mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-07 19:10:12 +08:00
feat: migrate quest api to trpc
This commit is contained in:
1 parent
55a41dd3b5
commit
ac92950177
14 files changed
+55
-71
No files matched your search
@@ -2,8 +2,8 @@
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useToast } from 'vue-toastification'
|
||||
import { ref, defineProps, onMounted } from 'vue'
|
||||
import { getQuest } from '../utils/api'
|
||||
import MarkdownText from './MarkdownText.vue'
|
||||
import { trpc } from '../utils/trpc'
|
||||
|
||||
const props = defineProps({
|
||||
questTitle: {
|
||||
@@ -49,7 +49,7 @@ const handleColour = () => {
|
||||
}
|
||||
}
|
||||
onMounted(async () => {
|
||||
const quest = await getQuest(questId)
|
||||
const quest = await trpc.quests.getQuestDetail.query(questId)
|
||||
questInstruction.value = quest.instruction
|
||||
handleColour()
|
||||
})
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { ref, onMounted, watch, computed } from 'vue'
|
||||
import { useToast } from 'vue-toastification'
|
||||
import { DAG } from '@linux-odyssey/utils'
|
||||
import { getQuests } from '../utils/api'
|
||||
import { trpc } from '../utils/trpc'
|
||||
import useUserProfile from '../store/userProfile'
|
||||
import QuestIntro from './QuestIntro.vue'
|
||||
|
||||
@@ -64,7 +64,7 @@ async function computeGraphData() {
|
||||
if (!store.progress) return
|
||||
|
||||
try {
|
||||
const quests = await getQuests()
|
||||
const quests = await trpc.quests.getQuests.query()
|
||||
const dag = new DAG(quests)
|
||||
const nodesValues = dag.getNodes()
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { FileGraph, FileObject } from '@linux-odyssey/file-graph'
|
||||
import { IQuest } from '@linux-odyssey/models'
|
||||
import { createSession, getActiveSession, getQuest } from '../utils/api'
|
||||
import { QuestDetailResponse } from '@linux-odyssey/constants'
|
||||
import { createSession, getActiveSession } from '../utils/api'
|
||||
import Socket from '../utils/socket'
|
||||
import SocketTerminal from '../utils/terminal'
|
||||
import { Session, StageResponse } from '../types'
|
||||
import { trpc } from '../utils/trpc'
|
||||
|
||||
const socket = new Socket()
|
||||
const term = new SocketTerminal(40, 80)
|
||||
@@ -13,7 +14,7 @@ let hasSetup = false
|
||||
interface Store {
|
||||
session: Session | null
|
||||
questId: string
|
||||
quest: IQuest | null
|
||||
quest: QuestDetailResponse | null
|
||||
}
|
||||
|
||||
const useSession = defineStore('session', {
|
||||
@@ -24,7 +25,7 @@ const useSession = defineStore('session', {
|
||||
}),
|
||||
actions: {
|
||||
async setQuest(questId: string) {
|
||||
this.quest = await getQuest(questId)
|
||||
this.quest = await trpc.quests.getQuestDetail.query(questId)
|
||||
this.questId = questId
|
||||
},
|
||||
async setSession(session: Session) {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import axios from 'axios'
|
||||
import { IQuest } from '@linux-odyssey/models'
|
||||
import { GetSessionsRequest } from '@linux-odyssey/constants'
|
||||
import { Session } from '../types'
|
||||
import { UserProfile } from '../store/userProfile'
|
||||
@@ -18,11 +17,6 @@ export async function getUserProfile(): Promise<UserProfile> {
|
||||
return res.data
|
||||
}
|
||||
|
||||
export async function getQuest(id: string): Promise<IQuest> {
|
||||
const res = await api.get<IQuest>(`/quests/${id}`)
|
||||
return res.data
|
||||
}
|
||||
|
||||
export async function createSession(questId: string): Promise<Session> {
|
||||
const res = await api.post<Session>('/sessions', { questId })
|
||||
return res.data
|
||||
@@ -43,8 +37,3 @@ export async function getActiveSession(
|
||||
})
|
||||
return res.data
|
||||
}
|
||||
|
||||
export async function getQuests(): Promise<IQuest[]> {
|
||||
const res = await api.get<IQuest[]>('/quests')
|
||||
return res.data
|
||||
}
|
||||
Reference in new issue
Block a user