Skip to content

Commit 478b8c9

Browse files
authored
Merge pull request #112 from OpenSIST/dev
Commit: add bio rankings
2 parents 2d73d3d + a0c6f6b commit 478b8c9

4 files changed

Lines changed: 3176 additions & 597 deletions

File tree

src/Components/Modify/Applicant/AddModifyApplicant.jsx

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import SoftBackground from "./FormComponent/SoftBackground";
1313
import {getDisplayName} from "../../../Data/UserData";
1414
import {getPrograms} from "../../../Data/ProgramData";
1515
import {blobToBase64} from "../../../Data/Common";
16-
import {addModifyPost, getPostObject, removePost} from "../../../Data/PostData";
1716
import {addModifyFile, getFileObject, removeFile} from "../../../Data/FileData";
1817

1918
export async function loader({params}) {
@@ -67,14 +66,16 @@ export async function action({request}) {
6766
const L = formValues.L;
6867
const S = formValues.S;
6968
const EnglishProficiency = {
70-
[EnglishOption === 'TOEFL' ? 'TOEFL' : 'IELTS']: {
71-
'Total': Number(EnglishTotal),
72-
'R': Number(R),
73-
'W': Number(W),
74-
'L': Number(L),
75-
'S': Number(S),
69+
[EnglishOption === 'IELTS' ? 'IELTS' : 'TOEFL']: {
70+
'Total': EnglishTotal ? Number(EnglishTotal) : null,
71+
'R': R ? Number(R) : null,
72+
'W': W ? Number(W) : null,
73+
'L': L ? Number(L) : null,
74+
'S': S ? Number(S) : null,
7675
}
7776
}
77+
console.log(EnglishProficiency);
78+
console.log(((EnglishTotal && R && W && L && S) && {'EnglishProficiency': EnglishProficiency}))
7879
const Exchange = formValues.Exchange ? removeEmptyDictInList(formValues.Exchange) : [];
7980
const Publication = formValues.Publication ? removeEmptyDictInList(formValues.Publication) : [];
8081
const Recommendation = formValues.Recommendation ? removeEmptyDictInList(formValues.Recommendation) : [];
@@ -124,14 +125,15 @@ export async function action({request}) {
124125
'Major': Major,
125126
'GPA': GPA,
126127
'Ranking': Ranking,
127-
...((GRE.Total !== 260 || GRE.V !== 130 || GRE.Q !== 130 || GRE.AW !== 0) && { 'GRE': GRE }),
128-
'EnglishProficiency': EnglishProficiency,
129-
...(Exchange.length !== 0 && { 'Exchange': Exchange }),
130-
...(Publication.length !== 0 && { 'Publication': Publication }),
128+
...((GRE.Total !== 260 || GRE.V !== 130 || GRE.Q !== 130 || GRE.AW !== 0) && {'GRE': GRE}),
129+
// 'EnglishProficiency': EnglishProficiency,
130+
...{'EnglishProficiency': ((EnglishTotal && R && W && L && S) ? EnglishProficiency : {})},
131+
...(Exchange.length !== 0 && {'Exchange': Exchange}),
132+
...(Publication.length !== 0 && {'Publication': Publication}),
131133
'Research': Research,
132134
'Internship': Internship,
133-
...(Recommendation.length !== 0 && { 'Recommendation': Recommendation }),
134-
...(Competition !== undefined && { 'Competition': Competition }),
135+
...(Recommendation.length !== 0 && {'Recommendation': Recommendation}),
136+
...(Competition !== undefined && {'Competition': Competition}),
135137
'Programs': ActionType === 'new' ? {} : Programs,
136138
'Final': Final === undefined ? "" : Final,
137139
'Posts': Posts
@@ -201,9 +203,11 @@ export async function action({request}) {
201203
const FormContent = (activeStep, formValues, handleBack, handleNext, handleChange, type, loaderData) => {
202204
switch (activeStep) {
203205
case 0:
204-
return <BasicInfo formValues={formValues} handleNext={handleNext} handleChange={handleChange} actionType={type} loaderData={loaderData}/>;
206+
return <BasicInfo formValues={formValues} handleNext={handleNext} handleChange={handleChange}
207+
actionType={type} loaderData={loaderData}/>;
205208
case 1:
206-
return <SoftBackground formValues={formValues} handleBack={handleBack} handleChange={handleChange} loaderData={loaderData}/>;
209+
return <SoftBackground formValues={formValues} handleBack={handleBack} handleChange={handleChange}
210+
loaderData={loaderData}/>;
207211
default:
208212
return null;
209213
}
@@ -280,8 +284,27 @@ export default function AddModifyApplicant({type}) {
280284
}
281285
const [formValues, setFormValues] = useState(applicantContent ?? {});
282286
const handleChange = (event, value, name) => {
283-
setFormValues({...formValues, [event?.target.name ? event?.target.name : name]: value ? value : event?.target.value});
287+
console.log(event?.target?.name, event?.target?.value, value, name)
288+
console.log({[event?.target.name ? event?.target.name : name]: value ? value : event?.target.value})
289+
setFormValues({
290+
...formValues,
291+
[event?.target.name ? event?.target.name : name]: value ? value : event?.target.value
292+
});
293+
console.log(formValues);
284294
if (event?.target.value === "" || (event?.target.name === undefined && (value === "" || value === undefined || value === null || value === '[]'))) {
295+
if (name === "EnglishOption" || name === "R" || name === "W" || name === "L" || name === "S" || name === "EnglishTotal") {
296+
if (name === "EnglishOption") {
297+
setFormValues({
298+
...formValues,
299+
'EnglishTotal': undefined,
300+
'R': undefined,
301+
'W': undefined,
302+
'L': undefined,
303+
'S': undefined
304+
});
305+
}
306+
return
307+
}
285308
const {[event?.target.name ? event?.target.name : name]: _, ...rest} = formValues;
286309
setFormValues(rest);
287310
}
@@ -293,14 +316,16 @@ export default function AddModifyApplicant({type}) {
293316
nonLinear
294317
alternativeLabel
295318
activeStep={activeStep}
296-
sx={{ mt: 10 }}
319+
sx={{mt: 10}}
297320
>
298321
{steps.map((label) => (
299322
<Step key={label}>
300-
<StepButton color="inherit" sx={{"&.MuiButtonBase-root:hover": {
323+
<StepButton color="inherit" sx={{
324+
"&.MuiButtonBase-root:hover": {
301325
bgcolor: "transparent",
302326
cursor: "default"
303-
}}}>
327+
}
328+
}}>
304329
{label}
305330
</StepButton>
306331
</Step>

src/Components/Modify/Applicant/FormComponent/BasicInfo.jsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function BasicInfo({formValues, handleNext, handleChange, actionType, loaderData
5858

5959
const navigate = useNavigate();
6060
const isError = () => {
61-
return !formValues.Gender || !formValues.CurrentDegree || !formValues.ApplicationYear || !formValues.Major || !formValues.GPA || !formValues.Ranking || !formValues.EnglishOption || !formValues.EnglishTotal || !formValues.R || !formValues.L || !formValues.S || !formValues.W || (isGRETotalRequired && !formValues.GRETotal) || (isGREVRequired && !formValues.V) || (isGREQRequired && !formValues.Q) || (isGREAWRequired && !formValues.AW) || isGPAError || isEnglishTotalError || isReadingError || isListeningError || isSpeakingError || isWritingError || isGRETotalError || isGREVError || isGREQError || isGREAWError;
61+
return !formValues.Gender || !formValues.CurrentDegree || !formValues.ApplicationYear || !formValues.Major || !formValues.GPA || !formValues.Ranking || (isGRETotalRequired && !formValues.GRETotal) || (isGREVRequired && !formValues.V) || (isGREQRequired && !formValues.Q) || (isGREAWRequired && !formValues.AW) || isGPAError || isEnglishTotalError || isReadingError || isListeningError || isSpeakingError || isWritingError || isGRETotalError || isGREVError || isGREQError || isGREAWError;
6262
}
6363

6464
const smallPage = useSmallPage();
@@ -298,7 +298,6 @@ function BasicInfo({formValues, handleNext, handleChange, actionType, loaderData
298298
name="EnglishOption"
299299
label="选择考试"
300300
variant="outlined"
301-
required
302301
/>
303302
}
304303
value={formValues.EnglishOption ? englishOptions.find((option) => {
@@ -323,7 +322,7 @@ function BasicInfo({formValues, handleNext, handleChange, actionType, loaderData
323322
value={formValues.EnglishTotal || ""}
324323
onChange={(event) => {handleChange(event)}}
325324
type="number"
326-
required
325+
// required
327326
error={isEnglishTotalError}
328327
helperText={isEnglishTotalError ? (formValues.EnglishOption === 'TOEFL' ? "TOEFL总分应在0-120之间" : "IELTS总分应在0-9之间") : null}
329328
sx={disableNumberUpDown}
@@ -339,7 +338,7 @@ function BasicInfo({formValues, handleNext, handleChange, actionType, loaderData
339338
value={formValues.R || ""}
340339
onChange={(event) => {handleChange(event)}}
341340
type="number"
342-
required
341+
// required
343342
error={isReadingError}
344343
helperText={isReadingError ? (formValues.EnglishOption === 'TOEFL' ? "TOEFL阅读分应在0-30之间" : "IELTS阅读分应在0-9之间") : null}
345344
sx={disableNumberUpDown}
@@ -355,7 +354,7 @@ function BasicInfo({formValues, handleNext, handleChange, actionType, loaderData
355354
value={formValues.L || ""}
356355
onChange={(event) => {handleChange(event)}}
357356
type="number"
358-
required
357+
// required
359358
error={isListeningError}
360359
helperText={isListeningError ? (formValues.EnglishOption === 'TOEFL' ? "TOEFL听力分应在0-30之间" : "IELTS听力分应在0-9之间") : null}
361360
sx={disableNumberUpDown}
@@ -371,7 +370,7 @@ function BasicInfo({formValues, handleNext, handleChange, actionType, loaderData
371370
value={formValues.S || ""}
372371
onChange={(event) => {handleChange(event)}}
373372
type="number"
374-
required
373+
// required
375374
error={isSpeakingError}
376375
helperText={isSpeakingError ? (formValues.EnglishOption === 'TOEFL' ? "TOEFL口语分应在0-30之间" : "IELTS口语分应在0-9之间") : null}
377376
sx={disableNumberUpDown}
@@ -387,7 +386,7 @@ function BasicInfo({formValues, handleNext, handleChange, actionType, loaderData
387386
value={formValues.W || ""}
388387
onChange={(event) => {handleChange(event)}}
389388
type="number"
390-
required
389+
// required
391390
error={isWritingError}
392391
helperText={isWritingError ? (formValues.EnglishOption === 'TOEFL' ? "TOEFL写作分应在0-30之间" : "IELTS写作分应在0-9之间") : null}
393392
sx={disableNumberUpDown}

src/Data/ProgramData.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const CACHE_EXPIRATION = 10 * 60 * 1000; // 10 min
1313
* All functions starred with other words -> Online operation to corresponding backend APIs
1414
*/
1515

16-
export async function getPrograms(isRefresh = false, query = {}) {
16+
export async function getPrograms(isRefresh = false, query = {}, ranking = "cs_rank") {
1717
/*
1818
* Get the list of programs (without description) from the server or local storage
1919
* @param isRefresh [Boolean]: whether to refresh the data
@@ -43,9 +43,19 @@ export async function getPrograms(isRefresh = false, query = {}) {
4343
}
4444

4545
programs = programs['data'];
46-
const univAbbrOrder = univListOrder.map((univ) => univ.abbr);
46+
// const univAbbrOrder = univListOrder.map((univ) => univ.abbr);
47+
// programs = Object.entries(programs).sort(([univ1, _], [univ2, __]) => {
48+
// return univAbbrOrder.indexOf(univ1) - univAbbrOrder.indexOf(univ2);
49+
// }).reduce((acc, [univ, programs]) => {
50+
// acc[univ] = programs;
51+
// return acc;
52+
// }, {});
53+
const univAbbrOrder = univListOrder.reduce((acc, univ) => {
54+
acc[univ.abbr] = univ[ranking || 'cs_rank'];
55+
return acc;
56+
}, {});
4757
programs = Object.entries(programs).sort(([univ1, _], [univ2, __]) => {
48-
return univAbbrOrder.indexOf(univ1) - univAbbrOrder.indexOf(univ2);
58+
return univAbbrOrder[univ1] - univAbbrOrder[univ2];
4959
}).reduce((acc, [univ, programs]) => {
5060
acc[univ] = programs;
5161
return acc;

0 commit comments

Comments
 (0)