Skip to content
This repository was archived by the owner on Jul 16, 2024. It is now read-only.

Commit 69bc5d3

Browse files
nichujienichujie
and
nichujie
authored
chore: moment -> dayjs (#114)
* chore: moment -> dayjs * refactor: menu children -> items * refactor: remove SideMenuBar --------- Co-authored-by: nichujie <[email protected]>
1 parent 75d4b60 commit 69bc5d3

File tree

18 files changed

+361
-346
lines changed

18 files changed

+361
-346
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040
"axios": "^1.2.5",
4141
"copy-to-clipboard": "^3.3.3",
4242
"crypto-js": "^4.1.1",
43+
"dayjs": "^1.11.7",
4344
"i18next": "^22.4.9",
4445
"i18next-http-backend": "^2.1.1",
4546
"jwt-decode": "^3.1.2",
4647
"lodash-es": "^4.17.21",
47-
"moment": "^2.29.4",
4848
"monaco-editor": "^0.34.1",
4949
"postcss-nesting": "^11.1.0",
5050
"rc-field-form": "^1.27.3",

pnpm-lock.yaml

+13-21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/AccessMenu/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ interface IProps extends MenuProps {
1010
}
1111

1212
const Index: React.FC<IProps> = ({ items, ...rest }) => {
13+
// @Chujie: note this component only support access control on first layer menu
14+
// i.e. access on submenu will be ignored
1315
const filteredItems = items
1416
.filter(item => item.access !== false)
1517
.map(item => omit(item, ['access']))
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import ProForm, {
2-
ProFormSelect,
3-
ProFormSwitch,
4-
ProFormText
2+
ProFormSelect,
3+
ProFormSwitch,
4+
ProFormText
55
} from '@ant-design/pro-form'
66
import { useRequest } from 'ahooks'
77
import { Form, message } from 'antd'
@@ -15,115 +15,115 @@ import type { Problem, ProblemCreate, ProblemEdit } from 'utils/service'
1515
import { ErrorCode, Horse } from 'utils/service'
1616

1717
export interface IProps {
18-
domainUrl: string
19-
initialValues?: Partial<Problem>
20-
onCreateSuccess?: (problem: Problem) => void
21-
onUpdateSuccess?: (problem: Problem) => void
18+
domainUrl: string
19+
initialValues?: Partial<Problem>
20+
onCreateSuccess?: (problem: Problem) => void
21+
onUpdateSuccess?: (problem: Problem) => void
2222
}
2323

2424
export const UpsertProblemForm: React.FC<IProps> = props => {
25-
const { domainUrl, initialValues, onCreateSuccess, onUpdateSuccess } = props
26-
const { t } = useTranslation()
27-
const navigate = useNavigate()
28-
const msg = useMessage()
25+
const { domainUrl, initialValues, onCreateSuccess, onUpdateSuccess } = props
26+
const { t } = useTranslation()
27+
const navigate = useNavigate()
28+
const msg = useMessage()
2929

30-
const languageOptions = SUPPORT_PROGRAMMING_LANGUAGE.map(lang => ({
31-
label: lang,
32-
value: lang
33-
}))
30+
const languageOptions = SUPPORT_PROGRAMMING_LANGUAGE.map(lang => ({
31+
label: lang,
32+
value: lang
33+
}))
3434

35-
const { run: createProblem } = useRequest(
36-
async (problem: ProblemCreate) =>
37-
Horse.problem.v1CreateProblem(domainUrl, problem),
38-
{
39-
manual: true,
40-
onSuccess: res => {
41-
if (res.data.errorCode === ErrorCode.IntegrityError) {
42-
message.error(t('msg.errorMsg.problemUrlNotUnique'))
43-
} else if (res.data.data?.id) {
44-
msg.success.create()
45-
if (onCreateSuccess) onCreateSuccess(res.data.data)
46-
navigate(
47-
`/domain/${domainUrl}/problem/${
48-
res.data.data.url ?? res.data.data.id
49-
}`
50-
)
51-
}
52-
},
53-
onError: () => {
54-
msg.error.create()
55-
}
56-
}
57-
)
35+
const { run: createProblem } = useRequest(
36+
async (problem: ProblemCreate) =>
37+
Horse.problem.v1CreateProblem(domainUrl, problem),
38+
{
39+
manual: true,
40+
onSuccess: res => {
41+
if (res.data.errorCode === ErrorCode.IntegrityError) {
42+
message.error(t('msg.errorMsg.problemUrlNotUnique'))
43+
} else if (res.data.data?.id) {
44+
msg.success.create()
45+
if (onCreateSuccess) onCreateSuccess(res.data.data)
46+
navigate(
47+
`/domain/${domainUrl}/problem/${
48+
res.data.data.url ?? res.data.data.id
49+
}`
50+
)
51+
}
52+
},
53+
onError: () => {
54+
msg.error.create()
55+
}
56+
}
57+
)
5858

59-
const { run: updateProblem } = useRequest(
60-
async (id: string, problem: ProblemEdit) =>
61-
Horse.problem.v1UpdateProblem(domainUrl, id, problem),
62-
{
63-
manual: true,
64-
onSuccess: res => {
65-
if (res.data.errorCode === ErrorCode.IntegrityError) {
66-
message.error(t('msg.errorMsg.problemUrlNotUnique'))
67-
} else if (res.data.data) {
68-
msg.success.update()
69-
if (onUpdateSuccess) onUpdateSuccess(res.data.data)
70-
}
71-
},
72-
onError: () => {
73-
msg.error.update()
74-
}
75-
}
76-
)
59+
const { run: updateProblem } = useRequest(
60+
async (id: string, problem: ProblemEdit) =>
61+
Horse.problem.v1UpdateProblem(domainUrl, id, problem),
62+
{
63+
manual: true,
64+
onSuccess: res => {
65+
if (res.data.errorCode === ErrorCode.IntegrityError) {
66+
message.error(t('msg.errorMsg.problemUrlNotUnique'))
67+
} else if (res.data.data) {
68+
msg.success.update()
69+
if (onUpdateSuccess) onUpdateSuccess(res.data.data)
70+
}
71+
},
72+
onError: () => {
73+
msg.error.update()
74+
}
75+
}
76+
)
7777

78-
const onFinish = async (values: Partial<Problem>): Promise<void> =>
79-
initialValues?.id
80-
? updateProblem(initialValues.id, values)
81-
: createProblem(values as ProblemCreate)
78+
const onFinish = async (values: Partial<Problem>): Promise<void> =>
79+
initialValues?.id
80+
? updateProblem(initialValues.id, values)
81+
: createProblem(values as ProblemCreate)
8282

83-
return (
84-
<ProForm<ProblemCreate | ProblemEdit>
85-
layout='vertical'
86-
onFinish={onFinish}
87-
initialValues={initialValues}
88-
dateFormatter='number'
89-
omitNil
90-
>
91-
<ProForm.Group>
92-
<ProFormText
93-
width='lg'
94-
name='title'
95-
label={t('UpsertProblemForm.title')}
96-
rules={[{ required: true }]}
97-
/>
98-
<ProFormSwitch
99-
name='hidden'
100-
label={t('UpsertProblemForm.hidden')}
101-
rules={[{ required: true }]}
102-
/>
103-
</ProForm.Group>
83+
return (
84+
<ProForm<ProblemCreate | ProblemEdit>
85+
layout='vertical'
86+
onFinish={onFinish}
87+
initialValues={initialValues}
88+
dateFormatter='number'
89+
omitNil
90+
>
91+
<ProForm.Group>
92+
<ProFormText
93+
width='lg'
94+
name='title'
95+
label={t('UpsertProblemForm.title')}
96+
rules={[{ required: true }]}
97+
/>
98+
<ProFormSwitch
99+
name='hidden'
100+
label={t('UpsertProblemForm.hidden')}
101+
rules={[{ required: true }]}
102+
/>
103+
</ProForm.Group>
104104

105-
<ProFormText
106-
width='lg'
107-
name='url'
108-
label={t('UpsertProblemForm.url')}
109-
tooltip='The url of a problem must be unique within a domain.'
110-
/>
105+
<ProFormText
106+
width='lg'
107+
name='url'
108+
label={t('UpsertProblemForm.url')}
109+
tooltip='The url of a problem must be unique within a domain.'
110+
/>
111111

112-
<ProFormSelect
113-
width='lg'
114-
name='languages'
115-
label={t('UpsertProblemForm.languages')}
116-
fieldProps={{
117-
showArrow: true,
118-
allowClear: true,
119-
mode: 'multiple',
120-
options: languageOptions
121-
}}
122-
/>
112+
<ProFormSelect
113+
width='lg'
114+
name='languages'
115+
label={t('UpsertProblemForm.languages')}
116+
fieldProps={{
117+
showArrow: true,
118+
allowClear: true,
119+
mode: 'multiple',
120+
options: languageOptions
121+
}}
122+
/>
123123

124-
<Form.Item name='content' label={t('UpsertProblemForm.content')}>
125-
<MarkdownEditor />
126-
</Form.Item>
127-
</ProForm>
128-
)
124+
<Form.Item name='content' label={t('UpsertProblemForm.content')}>
125+
<MarkdownEditor />
126+
</Form.Item>
127+
</ProForm>
128+
)
129129
}

0 commit comments

Comments
 (0)