diff --git a/.changes/refactor-problem-create.md b/.changes/refactor-problem-create.md new file mode 100644 index 0000000..b51609b --- /dev/null +++ b/.changes/refactor-problem-create.md @@ -0,0 +1,5 @@ +--- +"algohub": patch:refactor +--- + +Refactored problem creation page. diff --git a/.cspell.json b/.cspell.json index ad0f617..1289150 100644 --- a/.cspell.json +++ b/.cspell.json @@ -11,6 +11,7 @@ "dtolnay", "emptydirs", "farmfe", + "Gridlines", "icns", "ICPC", "jbolda", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 451c8f0..8323914 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -28,7 +28,7 @@ dependencies = [ [[package]] name = "algohub" -version = "0.1.1-alpha.7" +version = "0.1.1-alpha.8" dependencies = [ "reqwest", "serde", diff --git a/src/components/MonacoEditor.vue b/src/components/MonacoEditor.vue index fc494a2..c7f72d2 100644 --- a/src/components/MonacoEditor.vue +++ b/src/components/MonacoEditor.vue @@ -77,11 +77,6 @@ onUnmounted(disposeEditor) onBeforeUnmount(disposeEditor) onBeforeRouteLeave(disposeEditor) -console.log(Language) -console.log(Object.values(Language)) -console.log(Object.keys(Language)) -console.log(Object.entries(Language)) - const languageOptions = Object.entries(Language).map(([name, value]) => ({ name, value })) const onChangeLanguage = (value: SelectChangeEvent) => { diff --git a/src/components/ProblemEditor.vue b/src/components/ProblemEditor.vue index 1cd7cbc..e26dd2b 100644 --- a/src/components/ProblemEditor.vue +++ b/src/components/ProblemEditor.vue @@ -28,6 +28,8 @@ onMounted(async () => { samples.splice(0, samples.length); data.samples.forEach(sample => samples.push({ input: sample.input, output: sample.output })); hint.value = data.hint || ''; + testCases.splice(0, testCases.length); + data.test_cases?.forEach(tc => testCases.push({ input: tc.input, output: tc.output })); loading.value = false; } }) @@ -38,7 +40,8 @@ const input = ref(''); const output = ref(''); const samples = reactive([{ input: '', output: '' }]); const hint = ref(''); -const isPrivate = ref(false); +const owner = ref(accountStore.account.id!); +const visibility = ref(ProblemVisibility.Public); const testCases = reactive([]); const timeLimit = ref(1000); @@ -57,7 +60,7 @@ interface ProblemForm { owner: RecordId, categories: string[]; tags: string[]; - private: boolean; + visibility: ProblemVisibility; } const validate = (form: ProblemForm): boolean => { @@ -92,11 +95,11 @@ const onCreateProblem = async () => { test_cases: testCases.map(tc => ({ input: tc.input, output: tc.output })), owner: { tb: "account", - id: accountStore.account.id! + id: owner.value }, categories: [], tags: [], - private: isPrivate.value + visibility: visibility.value, } const valid = validate(problem); if (!valid) return; @@ -106,7 +109,6 @@ const onCreateProblem = async () => { const res = await api.createProblem({ id: accountStore.account.id!, token: accountStore.account.token!, - visibility: ProblemVisibility.Public, ...problem, }); if (!res.success) { @@ -236,16 +238,32 @@ const formatSize = (bytes: number) => { return `${formattedSize} ${sizes[i]}`; }; + +const onRemoveTestCases = async (testCase: TestCase) => { + const removeInput = await api.removeAsset(testCase.input, accountStore.auth!); + const removeOutput = await api.removeAsset(testCase.output, accountStore.auth!); + if (!removeInput.success || !removeOutput.success) { + return toast.add({ severity: 'error', summary: 'Error', detail: removeInput.message || removeOutput.message, life: 3000 }); + } + const index = testCases.indexOf(testCase); + if (index !== -1) { + testCases.splice(index, 1); + } +} - - - + + + + + + -
- - Mark as private -
diff --git a/src/scripts/api.ts b/src/scripts/api.ts index ff07f29..d5d1da9 100644 --- a/src/scripts/api.ts +++ b/src/scripts/api.ts @@ -52,6 +52,17 @@ export const uploadContent = async (form: CreateAsset) => { } }; +export const removeAsset = async (id: string, auth: Credentials) => { + try { + const response = await axios.delete(`/asset/delete/${id}`, { + data: auth, + }); + return response.data as Response; + } catch (error) { + return handleAxiosError(AxiosError.from(error)); + } +}; + interface ProfileForm { id: string; token: string; @@ -160,9 +171,9 @@ interface Submission { lang: Language; problem: RecordId; code: string; - status: 'in_queue' | 'judging' | 'ready'; - judge_details: { status: any, timeUsed: number, memoryUsed: number }[], - judge_result: { status: any, timeUsed: number, memoryUsed: number }, + status: "in_queue" | "judging" | "ready"; + judge_details: { status: any; timeUsed: number; memoryUsed: number }[]; + judge_result: { status: any; timeUsed: number; memoryUsed: number }; // contest } diff --git a/src/scripts/types.ts b/src/scripts/types.ts index a643354..7480b90 100644 --- a/src/scripts/types.ts +++ b/src/scripts/types.ts @@ -43,6 +43,7 @@ export interface CreateAsset { export interface UserContent { id: string; + name: string; } export enum ProblemVisibility { diff --git a/src/views/problem/[id].vue b/src/views/problem/[id].vue index 98f5432..c043e97 100644 --- a/src/views/problem/[id].vue +++ b/src/views/problem/[id].vue @@ -1,6 +1,6 @@ + +