refactor: move task components to components/task/

This commit is contained in:
2026-04-01 03:55:01 -06:00
parent e4359e8093
commit 6fb3bc0198
8 changed files with 38 additions and 37 deletions

View File

@@ -28,10 +28,10 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted } from "vue" import { ref, onMounted } from "vue"
import { useRouter } from "vue-router" import { useRouter } from "vue-router"
import { Challenge } from "../api" import { Challenge } from "../../api"
import { taskTab } from "../store/task" import { taskTab } from "../../store/task"
import { TASK_TYPE } from "../utils/const" import { TASK_TYPE } from "../../utils/const"
import type { ChallengeSlim } from "../utils/type" import type { ChallengeSlim } from "../../utils/type"
const router = useRouter() const router = useRouter()
const challenges = ref<ChallengeSlim[]>([]) const challenges = ref<ChallengeSlim[]>([])

View File

@@ -49,37 +49,39 @@
</n-button> </n-button>
</n-flex> </n-flex>
</n-flex> </n-flex>
<Tutorial v-if="taskTab === TASK_TYPE.Tutorial" /> <TutorialContent v-if="taskTab === TASK_TYPE.Tutorial" />
<Challenge v-else /> <ChallengeList v-else />
</div> </div>
<TaskStatsModal v-model:show="statsModal" :task-id="taskId" /> <TaskStatsModal v-model:show="statsModal" :task-id="taskId" />
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { Icon } from "@iconify/vue" import { Icon } from "@iconify/vue"
import { computed, ref } from "vue" import { computed, ref, watch } from "vue"
import { step, tutorialIds, prev, next, prevDisabled, nextDisabled } from "../store/tutorial" import { step, tutorialIds, prev, next, prevDisabled, nextDisabled } from "../../store/tutorial"
import { authed, roleSuper } from "../store/user" import { authed, roleSuper } from "../../store/user"
import { taskTab, taskId, challengeDisplay } from "../store/task" import { taskTab, taskId, challengeDisplay } from "../../store/task"
import { useRoute, useRouter } from "vue-router" import { useRoute, useRouter } from "vue-router"
import { TASK_TYPE } from "../utils/const" import { TASK_TYPE } from "../../utils/const"
import Challenge from "./Challenge.vue" import ChallengeList from "./ChallengeList.vue"
import Tutorial from "./Tutorial.vue" import TutorialContent from "./TutorialContent.vue"
import TaskStatsModal from "./TaskStatsModal.vue" import TaskStatsModal from "./TaskStatsModal.vue"
const route = useRoute() const route = useRoute()
const router = useRouter() const router = useRouter()
const statsModal = ref(false) const statsModal = ref(false)
// setup onMounted // + watch SPA
const routeName = route.name as string function syncRoute(routeName: string) {
if (routeName.startsWith("home-tutorial")) { if (routeName.startsWith("home-tutorial")) {
taskTab.value = TASK_TYPE.Tutorial taskTab.value = TASK_TYPE.Tutorial
if (route.params.display) step.value = Number(route.params.display) if (route.params.display) step.value = Number(route.params.display)
} else if (routeName.startsWith("home-challenge")) { } else if (routeName.startsWith("home-challenge")) {
taskTab.value = TASK_TYPE.Challenge taskTab.value = TASK_TYPE.Challenge
if (route.params.display) if (route.params.display) challengeDisplay.value = Number(route.params.display)
challengeDisplay.value = Number(route.params.display) }
} }
syncRoute(route.name as string)
watch(() => route.name as string, syncRoute)
defineEmits(["hide"]) defineEmits(["hide"])
@@ -105,7 +107,6 @@ function changeTab(v: TASK_TYPE) {
: { name: "home-tutorial-list" }, : { name: "home-tutorial-list" },
) )
} else if (v === TASK_TYPE.Challenge) { } else if (v === TASK_TYPE.Challenge) {
challengeDisplay.value = 0
router.push({ name: "home-challenge-list" }) router.push({ name: "home-challenge-list" })
} }
} }

View File

@@ -392,8 +392,8 @@
import { ref, computed, watch } from "vue" import { ref, computed, watch } from "vue"
import { Icon } from "@iconify/vue" import { Icon } from "@iconify/vue"
import { useRouter } from "vue-router" import { useRouter } from "vue-router"
import { Submission } from "../api" import { Submission } from "../../api"
import type { TaskStatsOut } from "../utils/type" import type { TaskStatsOut } from "../../utils/type"
const props = defineProps<{ taskId: number; show: boolean }>() const props = defineProps<{ taskId: number; show: boolean }>()
const emit = defineEmits<{ (e: "update:show", v: boolean): void }>() const emit = defineEmits<{ (e: "update:show", v: boolean): void }>()

View File

@@ -5,10 +5,10 @@
import { onMounted, ref, useTemplateRef, watch } from "vue" import { onMounted, ref, useTemplateRef, watch } from "vue"
import { marked } from "marked" import { marked } from "marked"
import copyFn from "copy-text-to-clipboard" import copyFn from "copy-text-to-clipboard"
import { css, html, js, tab } from "../store/editors" import { css, html, js, tab } from "../../store/editors"
import { Tutorial } from "../api" import { Tutorial } from "../../api"
import { step, tutorialIds } from "../store/tutorial" import { step, tutorialIds } from "../../store/tutorial"
import { taskId } from "../store/task" import { taskId } from "../../store/task"
import { useRouter } from "vue-router" import { useRouter } from "vue-router"
marked.use({ marked.use({

View File

@@ -6,7 +6,7 @@
max="900px" max="900px"
> >
<template #1> <template #1>
<Task @hide="hide" /> <TaskPanel @hide="hide" />
</template> </template>
<template #2> <template #2>
<n-split direction="vertical" min="200px"> <n-split direction="vertical" min="200px">
@@ -24,7 +24,7 @@
import { useMagicKeys, whenever } from "@vueuse/core" import { useMagicKeys, whenever } from "@vueuse/core"
import Editors from "../components/editor/Editors.vue" import Editors from "../components/editor/Editors.vue"
import Preview from "../components/editor/Preview.vue" import Preview from "../components/editor/Preview.vue"
import Task from "../components/Task.vue" import TaskPanel from "../components/task/TaskPanel.vue"
import { show, panelSize } from "../store/panel" import { show, panelSize } from "../store/panel"
import { html, css, js } from "../store/editors" import { html, css, js } from "../store/editors"

View File

@@ -1,4 +1,5 @@
import { ref } from "vue" import { ref } from "vue"
import { useStorage } from "@vueuse/core"
import { TASK_TYPE } from "../utils/const" import { TASK_TYPE } from "../utils/const"
const currentTask = window.location.pathname.startsWith("/challenge") const currentTask = window.location.pathname.startsWith("/challenge")
@@ -7,4 +8,4 @@ const currentTask = window.location.pathname.startsWith("/challenge")
export const taskTab = ref(currentTask) export const taskTab = ref(currentTask)
export const taskId = ref(0) export const taskId = ref(0)
export const challengeDisplay = ref(0) export const challengeDisplay = useStorage("challenge-display", 0)

View File

@@ -1,9 +1,7 @@
import { useStorage } from "@vueuse/core"
import { ref } from "vue" import { ref } from "vue"
const urlParams = new URLSearchParams(window.location.search) export const step = useStorage("tutorial-step", 1)
const currentStep = urlParams.get("step") ?? "1"
export const step = ref(Number(currentStep))
export const tutorialIds = ref<number[]>([]) export const tutorialIds = ref<number[]>([])
export function prevDisabled(): boolean { export function prevDisabled(): boolean {

View File

@@ -10,7 +10,8 @@ export function goHome(router: any, type: TASK_TYPE, display: number) {
if (type === TASK_TYPE.Tutorial) { if (type === TASK_TYPE.Tutorial) {
router.push({ name: "home-tutorial", params: { display } }) router.push({ name: "home-tutorial", params: { display } })
} else if (type === TASK_TYPE.Challenge) { } else if (type === TASK_TYPE.Challenge) {
router.push({ name: "home-challenge", params: { display } }) if (display) router.push({ name: "home-challenge", params: { display } })
else router.push({ name: "home-challenge-list" })
} else { } else {
router.push({ name: "home" }) router.push({ name: "home" })
} }