diff --git a/app/src/components/QuestPart.vue b/app/src/components/QuestPart.vue index 17020b3..f4cae70 100644 --- a/app/src/components/QuestPart.vue +++ b/app/src/components/QuestPart.vue @@ -3,8 +3,14 @@ import { computed } from 'vue' import MarkdownText from './MarkdownText.vue' import sessionStore from '../store/session' +interface Task { + id: number + name: string + completed: boolean +} + const tasks = computed(() => { - return sessionStore.session.tasks.map((task: any) => { + return sessionStore.session.tasks.map((task: Task) => { const prefix = task.completed ? '✓' : '➤' const color = task.completed ? 'text-text-primary' : 'text-text' return { diff --git a/app/src/components/VisualizationPart.vue b/app/src/components/VisualizationPart.vue index bbbafe4..aa5fea6 100644 --- a/app/src/components/VisualizationPart.vue +++ b/app/src/components/VisualizationPart.vue @@ -5,7 +5,7 @@ import TreeChart from './TreeChart.vue' const treeRef = ref(null) let pos = { top: 0, left: 0, x: 0, y: 0 } -function mouseMoveHandler(e: any) { +function mouseMoveHandler(e: MouseEvent) { const dx = e.clientX - pos.x const dy = e.clientY - pos.y @@ -23,7 +23,7 @@ function mouseUpHandler() { document.removeEventListener('mouseup', mouseUpHandler) } -function mouseDownHandler(e: any) { +function mouseDownHandler(e: MouseEvent) { if (treeRef.value === null) return treeRef.value.style.cursor = 'grabbing' treeRef.value.style.userSelect = 'none' diff --git a/app/src/store/session.ts b/app/src/store/session.ts index a0a01b7..395a5d3 100644 --- a/app/src/store/session.ts +++ b/app/src/store/session.ts @@ -24,7 +24,21 @@ function newSession() { } } -const store: any = reactive({ +interface Session { + status: string + graph: FileGraph + pwd: string + hints: string[] + tasks: string[] +} + +interface Store { + session: Session + questId: string + quest: any // 这里需要根据实际情况定义 quest 属性的类型 +} + +const store: Store = reactive({ session: newSession(), questId: '', quest: null, @@ -40,7 +54,7 @@ function setQuest(questId: string) { }) } -async function setSession(session: any) { +async function setSession(session: Session) { try { console.log('Setting session...', session) store.session = session @@ -50,7 +64,11 @@ async function setSession(session: any) { term.focus() } catch (err: any) { console.error(err) - toast.error(err.message) + if (err instanceof Error) { + toast.error(err.message) + } else { + toast.error('Failed to connect to the session. Please try again later.') + } throw err } } @@ -67,7 +85,7 @@ export async function createSession() { } } -async function getActiveSession(questId: any) { +async function getActiveSession(questId: string) { try { const res = await api.post('/sessions/active', { questId }) await setSession(res.data) @@ -128,10 +146,10 @@ export async function init(questId: string) { } function setup() { - socket.on('terminal', (data: any) => { + socket.on('terminal', (data: string) => { term.write(data) }) - term.onData((data: any) => { + term.onData((data: string) => { socket.emit('terminal', data) }) socket.on('graph', (event: { discover: FileObject[]; pwd: string }) => { diff --git a/app/src/utils/errors.ts b/app/src/utils/errors.ts index 0f94185..2c78434 100644 --- a/app/src/utils/errors.ts +++ b/app/src/utils/errors.ts @@ -1,28 +1,28 @@ /* eslint-disable max-classes-per-file */ export class TooManyRequestsError extends Error { - constructor(message: string | undefined) { + constructor(message: string) { super(message) this.name = 'TooManyRequestsError' } } export class ValidationError extends Error { - constructor(message: string | undefined) { + constructor(message: string) { super(message) this.name = 'ValidationError' } } export class UnauthorizedError extends Error { - constructor(message: string | undefined) { + constructor(message: string) { super(message) this.name = 'UnauthorizedError' } } export class LoadQuestError extends Error { - questId: any - constructor(message: string | undefined, questId: any) { + questId: string + constructor(message: string, questId: string) { super(message) this.name = 'LoadQuestError' this.questId = questId @@ -30,8 +30,8 @@ export class LoadQuestError extends Error { } export class LoadSessionError extends Error { - questId: any - constructor(message: string | undefined, questId: any) { + questId: string + constructor(message: string, questId: string) { super(message) this.name = 'LoadSessionError' this.questId = questId diff --git a/app/src/views/ChooseUsernamePage.vue b/app/src/views/ChooseUsernamePage.vue index ff54dea..d344183 100644 --- a/app/src/views/ChooseUsernamePage.vue +++ b/app/src/views/ChooseUsernamePage.vue @@ -5,7 +5,14 @@ import Background from '../components/DynamicBackground.vue' import { TooManyRequestsError, ValidationError } from '../utils/errors' import { checkUsername, chooseUsername } from '../utils/auth' -async function check({ username, error }: { username: string; error: any }) { +async function check({ + username, + error, +}: { + username: string + // eslint-disable-next-line no-unused-vars + error: (msg: string) => void +}) { if (username) { if (!isValidUsername(username)) { error('無效的帳號名稱')