Skip to content

Commit 896a90b

Browse files
创建高级编辑开关(#4
1 parent f403217 commit 896a90b

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

src/contestEditor/configPanel.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@
4141
max-width: 200px;
4242
}
4343
}
44+
.contest-editor-config-problem-card-title {
45+
display: flex;
46+
align-items: center;
47+
gap: 2em;
48+
> :nth-child(2){
49+
display: flex;
50+
align-items: center;
51+
gap: 4px;
52+
}
53+
}
4454
.contest-editor-config-problem > :nth-child(2) {
4555
display: flex;
4656
flex-direction: column;

src/contestEditor/configPanel.tsx

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ const ConfigPanel: FC<{
112112
setPanel,
113113
updateContestData,
114114
);
115+
function syncAdvancedFields(problem: ImmerContestData["problems"][number]) {
116+
if (problem.advancedEditing) return;
117+
problem.dir = problem.exec = problem.name;
118+
problem.input = problem.name + ".in";
119+
problem.output = problem.name + ".out";
120+
}
115121
return (
116122
<form className="contest-editor-config" ref={formRef}>
117123
<label>
@@ -317,7 +323,23 @@ const ConfigPanel: FC<{
317323
{contestData.problems.map((problem, index) => (
318324
<Card
319325
key={problem.key}
320-
title={`第 ${index + 1} 题`}
326+
title={
327+
<div className="contest-editor-config-problem-card-title">
328+
<div>{index + 1}</div>
329+
<div>
330+
<Switch
331+
checked={problem.advancedEditing ?? false}
332+
onChange={(x) =>
333+
updateProblemData(index, (v) => {
334+
v.advancedEditing = x;
335+
syncAdvancedFields(v);
336+
})
337+
}
338+
/>
339+
高级编辑
340+
</div>
341+
</div>
342+
}
321343
extra={[
322344
<Button
323345
key="move-up"
@@ -369,7 +391,10 @@ const ConfigPanel: FC<{
369391
name={`problem ${index} name`}
370392
value={problem.name}
371393
onChange={(e) =>
372-
updateProblemData(index, (x) => (x.name = e.target.value))
394+
updateProblemData(index, (x) => {
395+
x.name = e.target.value;
396+
syncAdvancedFields(x);
397+
})
373398
}
374399
/>
375400
</label>
@@ -397,7 +422,7 @@ const ConfigPanel: FC<{
397422
/>
398423
</label>
399424
</div>
400-
{contestData.noi_style && (
425+
{problem.advancedEditing && contestData.noi_style && (
401426
<div>
402427
<label>
403428
<div>目录</div>
@@ -429,7 +454,7 @@ const ConfigPanel: FC<{
429454
</label>
430455
</div>
431456
)}
432-
{contestData.file_io && (
457+
{problem.advancedEditing && contestData.file_io && (
433458
<div>
434459
<label>
435460
<div>输入文件名</div>

src/types/contestData.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export type ContestData<
6868
export type UILanguageConfig = LanguageConfig & { key: import("crypto").UUID };
6969

7070
export type UIProblemData<Conf extends ContentFlags = { withMarkdown: true }> =
71-
ProblemData<Conf> & { key: import("crypto").UUID };
71+
ProblemData<Conf> & { key: import("crypto").UUID; advancedEditing?: boolean };
7272

7373
export interface UIImageItem {
7474
uuid: string;
@@ -87,11 +87,16 @@ export interface ImmerContestData extends ContestData<{ withMarkdown: true }> {
8787
images: UIImageItem[];
8888
}
8989

90+
export interface StoredProblemData extends ProblemData<{ withMarkdown: true }> {
91+
advancedEditing?: boolean;
92+
}
93+
9094
export interface StoredContestData extends ContestData<{ withMarkdown: true }> {
9195
images: {
9296
uuid: string;
9397
name: string;
9498
}[];
99+
problems: StoredProblemData[];
95100
}
96101

97102
export type ContestDataWithImages = ContestData<{ withMarkdown: true }> & {

0 commit comments

Comments
 (0)