diff --git a/.changes/refactor-problem.md b/.changes/refactor-problem.md new file mode 100644 index 0000000..cdf4206 --- /dev/null +++ b/.changes/refactor-problem.md @@ -0,0 +1,9 @@ +--- +"algohub": patch:refactor +--- + +Fully refactored the problem api to sync changes with the `algohub-server`, also: + +- Fixed icon sizes in markdown editor. +- Extract supported languages from ts enum. +- Refactored problem editor. diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index e68990d..451c8f0 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -28,7 +28,7 @@ dependencies = [ [[package]] name = "algohub" -version = "0.1.1-alpha.5" +version = "0.1.1-alpha.7" dependencies = [ "reqwest", "serde", diff --git a/src/components/MarkdownEditor.vue b/src/components/MarkdownEditor.vue index 4b628ed..b5a0d32 100644 --- a/src/components/MarkdownEditor.vue +++ b/src/components/MarkdownEditor.vue @@ -35,4 +35,11 @@ const themeStore = useThemeStore(); 'preview', 'previewOnly', ]"> - \ No newline at end of file + + + diff --git a/src/components/MonacoEditor.vue b/src/components/MonacoEditor.vue index 312cd20..7a633c0 100644 --- a/src/components/MonacoEditor.vue +++ b/src/components/MonacoEditor.vue @@ -57,7 +57,7 @@ onMounted(async () => { loader.config({ monaco }) editor.value = await loader.init().then((monaco) => monaco.editor.create(editorContainer.value, { value: '', - language: 'rust', + language: language.value, theme: themeStore.dark ? 'vs-dark' : 'vs', fontFamily: 'Cascadia Code, Consolas, Menlo, Monaco, "Courier New", monospace', inlineSuggest: { @@ -77,12 +77,12 @@ onUnmounted(disposeEditor) onBeforeUnmount(disposeEditor) onBeforeRouteLeave(disposeEditor) -const languageOptions = [ - { name: 'Rust', value: Language.Rust }, - { name: 'Python', value: Language.Python }, - { name: 'C', value: Language.C }, - { name: 'C++', value: Language.Cpp }, -] +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) => { const editor = rawEditor.value; diff --git a/src/components/ProblemEditor.vue b/src/components/ProblemEditor.vue new file mode 100644 index 0000000..1cd7cbc --- /dev/null +++ b/src/components/ProblemEditor.vue @@ -0,0 +1,378 @@ + + + \ No newline at end of file diff --git a/src/scripts/api.ts b/src/scripts/api.ts index e246a12..babf472 100644 --- a/src/scripts/api.ts +++ b/src/scripts/api.ts @@ -4,9 +4,10 @@ import { handleAxiosError } from "@/scripts/utils"; import type { CreateAsset, Credentials, - ProblemDetail, + UserProblem, Profile, UserContent, + CreateProblem, } from "./types"; export interface Response { @@ -87,24 +88,6 @@ export const fetchProfile = async (id: string) => { } }; -interface CreateProblem { - id: string; - token: string; - - title: string; - description: string; - input?: string; - output?: string; - samples: { input: string; output: string }[]; - hint?: string; - time_limit: number; - memory_limit: number; - test_cases: { input: string; output: string }[]; - categories: string[]; - tags: string[]; - private: boolean; -} - interface ProblemResponse { id: string; } @@ -121,7 +104,7 @@ export const createProblem = async (form: CreateProblem) => { export const fetchProblem = async (id: string, form?: Credentials) => { try { const response = await axios.post(`/problem/get/${id}`, form); - return response.data as Response; + return response.data as Response; } catch (error) { return handleAxiosError(AxiosError.from(error)); } @@ -136,7 +119,7 @@ interface ListProblem { export const listProblems = async (form: ListProblem) => { try { const response = await axios.post("/problem/list", form); - return response.data as Response; + return response.data as Response; } catch (error) { return handleAxiosError(AxiosError.from(error)); } diff --git a/src/scripts/types.ts b/src/scripts/types.ts index 94d8ec9..a643354 100644 --- a/src/scripts/types.ts +++ b/src/scripts/types.ts @@ -45,8 +45,39 @@ export interface UserContent { id: string; } -export interface ProblemDetail { - id: RecordId; +export enum ProblemVisibility { + ContestOnly = "contest_only", + Public = "public", + Private = "private", + Internal = "internal", +} + +export interface TestCase { + input: string; + output: string; +} + +export interface CreateProblem { + id: string; + token: string; + + title: string; + description: string; + input?: string; + output?: string; + samples: Sample[]; + hint?: string; + owner: RecordId; + time_limit: number; + memory_limit: number; + test_cases: { input: string; output: string }[]; + categories: string[]; + tags: string[]; + visibility: ProblemVisibility; +} + +export interface UserProblem { + id: string; title: string; description: string; input?: string; @@ -55,20 +86,22 @@ export interface ProblemDetail { hint?: string; time_limit: number; memory_limit: number; - test_cases: Sample[]; - creator: RecordId; + test_cases: TestCase[]; + creator: string; owner: RecordId; categories: string[]; tags: string[]; - mode: Mode; - private: boolean; - created_at: Date; - updated_at: Date; + visibility: ProblemVisibility; + created_at: string; + updated_at: string; } export enum Language { - Rust = "Rust", - Python = "Python", - C = "C", - Cpp = "Cpp", + Rust = "rust", + Python = "python", + C = "c", + Cpp = "cpp", + Golang = "golang", + Nodejs = "nodejs", + Java = "java", } diff --git a/src/views/account/[id].vue b/src/views/account/[id].vue index 3ca7089..028f10a 100644 --- a/src/views/account/[id].vue +++ b/src/views/account/[id].vue @@ -2,7 +2,7 @@ import * as api from "@/scripts/api"; import { useAccountStore, useThemeStore } from "@/scripts/store"; import { timeAgo } from "@/scripts/time"; -import { ProblemDetail, type Profile } from "@/scripts/types"; +import { UserProblem, type Profile } from "@/scripts/types"; import { expandAssetUrl } from "@/scripts/utils"; import { Avatar, useToast } from "primevue"; import { onMounted, ref, watch } from "vue"; @@ -38,7 +38,7 @@ const toggleTab = async (to: string) => { } } -const problemList = ref([]); +const problemList = ref([]); problemList.value.length = 1; const loadingProblems = ref(true); diff --git a/src/views/dashboard.vue b/src/views/dashboard.vue index dcfa74a..9cc2c67 100644 --- a/src/views/dashboard.vue +++ b/src/views/dashboard.vue @@ -4,7 +4,7 @@ import { onMounted, ref } from 'vue'; import * as api from '@/scripts/api'; import { useRouter } from 'vue-router'; import { useToast } from 'primevue'; -import { ProblemDetail } from '@/scripts/types'; +import { UserProblem } from '@/scripts/types'; const path = [{ label: 'Dashboard' }]; @@ -19,7 +19,7 @@ if (!accountStore.isLoggedIn) { const themeStore = useThemeStore(); -const problemList = ref([]); +const problemList = ref([]); const loadingProfile = ref(true); const loadingProblems = ref(true); diff --git a/src/views/problem/[id].vue b/src/views/problem/[id].vue index 54cd1f7..460cc33 100644 --- a/src/views/problem/[id].vue +++ b/src/views/problem/[id].vue @@ -4,7 +4,7 @@ import { useRoute } from 'vue-router'; import * as api from '@/scripts/api'; import { useAccountStore, useThemeStore } from '@/scripts/store'; import { useToast } from 'primevue'; -import { Language, ProblemDetail } from '@/scripts/types'; +import { Language, UserProblem } from '@/scripts/types'; import { MdPreview } from 'md-editor-v3'; import 'md-editor-v3/lib/style.css'; @@ -15,8 +15,8 @@ const toast = useToast(); const accountStore = useAccountStore(); const themeStore = useThemeStore(); -const problem = ref(); -const formatProblem = (problem: ProblemDetail) => { +const problem = ref(); +const formatProblem = (problem: UserProblem) => { let formattedText = ''; const { description, input, output, samples, hint } = problem; @@ -81,7 +81,7 @@ onMounted(async () => { - + diff --git a/src/views/problem/create.vue b/src/views/problem/create.vue index f7ab79b..7d0e398 100644 --- a/src/views/problem/create.vue +++ b/src/views/problem/create.vue @@ -1,375 +1,11 @@ - - \ No newline at end of file