Skip to content

Commit b12ff88

Browse files
authored
Create statement page, Part 2 (#20)
* Create New Language Select page * Change Variable Data * Edit Statement Page * Created Navbar, erase unnecessary codes * Create main statement page * Fix query detecting logic * Fix errors * Fix quotation * Apply mobile-responsive * Fix sx mobile responsive to direction, and change xs to sm * Fix lint warnings
1 parent 3c5e7a2 commit b12ff88

File tree

4 files changed

+223
-0
lines changed

4 files changed

+223
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import {
2+
Button,
3+
Paper,
4+
Stack,
5+
TextField,
6+
Typography,
7+
ButtonGroup,
8+
} from '@mui/material';
9+
10+
// As same as Polygon, the page link is same for creating new language and editing existed language
11+
// It can be divided into two pages if needed
12+
13+
export default function EditStatement({
14+
language,
15+
languageName,
16+
}: {
17+
language: string;
18+
languageName: string;
19+
}) {
20+
// have to fetch the statement and tutorial from the server by the language
21+
return (
22+
<Paper>
23+
<Stack direction='column' px={4} py={2} gap={2}>
24+
<Stack direction='column'>
25+
<Stack
26+
direction={{ sm: 'column', md: 'row' }}
27+
gap={2}
28+
px={2}
29+
justifyContent='space-between'
30+
>
31+
<Typography variant='h6'>
32+
Edit {languageName}({language}) Statement
33+
</Typography>
34+
<ButtonGroup variant='text' sx={{ justifyContent: 'flex-end' }}>
35+
<Button>In LaTex</Button>
36+
<Button>In HTML</Button>
37+
<Button>In PDF</Button>
38+
</ButtonGroup>
39+
</Stack>
40+
<Typography variant='caption' px={2}>
41+
It is recommended to use simple TeX, &ldquo;Preview in HTML&rdquo; feature
42+
supports only subset of TeX markup
43+
</Typography>
44+
</Stack>
45+
<TextField id='prob_name' label='Name' fullWidth />
46+
<TextField id='legend' label='Legend' rows={10} multiline fullWidth />
47+
<TextField
48+
id='input_format'
49+
label='Input Format'
50+
rows={5}
51+
multiline
52+
fullWidth
53+
/>
54+
<TextField
55+
id='output_format'
56+
label='Output Format'
57+
rows={5}
58+
multiline
59+
fullWidth
60+
/>
61+
<TextField id='scoring' label='Scoring' rows={10} multiline fullWidth />
62+
<TextField id='notes' label='Notes' rows={5} multiline fullWidth />
63+
<TextField id='tutorial' label='Tutorial' rows={10} multiline fullWidth />
64+
<Button variant='contained'>Save</Button>
65+
</Stack>
66+
</Paper>
67+
);
68+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
'use client';
2+
3+
import { Button, Paper, Stack, TextField, Autocomplete, Link } from '@mui/material';
4+
import { useState } from 'react';
5+
6+
// As same as Polygon, the page link is same for creating new language and editing existed language
7+
// It can be divided into two pages if needed
8+
9+
export default function NewLanguage({
10+
languageList,
11+
existedLanguageList,
12+
}: {
13+
languageList: { label: string; value: string }[];
14+
existedLanguageList: { label: string; value: string }[];
15+
}) {
16+
// cloneClicked variable is used to show the existedLanguageList when the user wants to clone
17+
const [cloneClicked, setCloneClicked] = useState(false);
18+
return (
19+
<Paper>
20+
<Stack direction='column' px={4} py={2} gap={2}>
21+
<Autocomplete
22+
id='language_setting'
23+
options={languageList.filter(
24+
(lang) =>
25+
!existedLanguageList.find(
26+
(existedLang) => existedLang.value === lang.value,
27+
),
28+
)}
29+
getOptionLabel={(option) => option.label}
30+
renderInput={(params) => (
31+
<TextField
32+
{...params}
33+
label='Language'
34+
helperText={
35+
!cloneClicked && (
36+
<>
37+
If you want to clone statement and tutorial from existing,{' '}
38+
<Link href='#' onClick={() => setCloneClicked(true)}>
39+
click here
40+
</Link>
41+
</>
42+
)
43+
}
44+
/>
45+
)}
46+
/>
47+
{cloneClicked && (
48+
<Autocomplete
49+
id='existed_language_setting'
50+
options={existedLanguageList}
51+
getOptionLabel={(option) => option.label}
52+
renderInput={(params) => (
53+
<TextField {...params} label='Clone from language' />
54+
)}
55+
/>
56+
)}
57+
<Button variant='contained'>Create</Button>
58+
</Stack>
59+
</Paper>
60+
);
61+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Tabs, Tab, Box, Button, Stack, ButtonGroup } from '@mui/material';
2+
3+
export default function StatementNavbar({
4+
existedLanguageList,
5+
language,
6+
}: {
7+
existedLanguageList: { label: string; value: string }[];
8+
language: string;
9+
}) {
10+
return (
11+
<Box sx={{ width: '100%' }}>
12+
<Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
13+
<Stack
14+
direction={{ sm: 'column', md: 'row' }}
15+
gap={2}
16+
p={2}
17+
justifyContent='space-between'
18+
>
19+
<Tabs value={language}>
20+
{existedLanguageList.map((lang) => (
21+
<Tab
22+
label={lang.label}
23+
value={lang.value}
24+
href={'?language=' + lang.value}
25+
key={lang.value}
26+
/>
27+
))}
28+
</Tabs>
29+
<ButtonGroup
30+
variant='text'
31+
sx={{ flexWrap: 'wrap', justifyContent: 'flex-end' }}
32+
>
33+
<Button>Edit With Preview</Button>
34+
<Button>Review</Button>
35+
<Button>Delete Current</Button>
36+
<Button href='?language='>Create New</Button>
37+
</ButtonGroup>
38+
</Stack>
39+
</Box>
40+
</Box>
41+
);
42+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
'use client';
2+
3+
import { Stack } from '@mui/material';
4+
import { useSearchParams } from 'next/navigation';
5+
import { useState } from 'react';
6+
7+
import NewLanguage from './NewLanguage';
8+
import EditStatement from './EditStatement';
9+
import StatementNavbar from './StatementNavbar';
10+
11+
// languageList variable is all-supported languages
12+
// if it needs to be fetched from the server, it should be done in the useEffect hook
13+
const languageList = [
14+
{ label: 'Korean', value: 'ko' },
15+
{ label: 'English', value: 'en' },
16+
{ label: 'Japanese', value: 'ja' },
17+
{ label: 'Chinese', value: 'zh' },
18+
{ label: 'Vietnamese', value: 'vi' },
19+
{ label: 'Russian', value: 'ru' },
20+
{ label: 'French', value: 'fr' },
21+
];
22+
23+
export default function Problem() {
24+
// existedLanguageList variable is the list of languages that already have statements and tutorials
25+
// it should be fetched from the server in the useEffect hook
26+
const [existedLanguageList] = useState([
27+
{ label: 'English', value: 'en' },
28+
{ label: 'French', value: 'fr' },
29+
]);
30+
// get query parameters
31+
const searchParams = useSearchParams();
32+
const [language] = useState(searchParams.get('language') || '');
33+
return (
34+
<Stack mt={2} gap={4}>
35+
<StatementNavbar existedLanguageList={existedLanguageList} language={language} />
36+
{!existedLanguageList.find((lang) => lang.value === language) && (
37+
<NewLanguage
38+
languageList={languageList}
39+
existedLanguageList={existedLanguageList}
40+
/>
41+
)}
42+
{existedLanguageList.find((lang) => lang.value === language) && (
43+
<EditStatement
44+
language={language}
45+
languageName={
46+
existedLanguageList.find((lang) => lang.value === language)?.label || ''
47+
}
48+
/>
49+
)}
50+
</Stack>
51+
);
52+
}

0 commit comments

Comments
 (0)