mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 11:30:13 +08:00
refactor: rewrite session store using pinia and fix start button
This commit is contained in:
1 parent
78b9529699
commit
7cdc542c19
13 files changed
+171
-192
No files matched your search
@@ -1,8 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { useToast } from 'vue-toastification'
|
||||
import { ref } from 'vue'
|
||||
import { getActiveSession, setQuest, createSession } from '../../store/session'
|
||||
import { LoadQuestError, LoadSessionError } from '../../utils/errors'
|
||||
import { onMounted, ref } from 'vue'
|
||||
import useSession from '../../store/session'
|
||||
|
||||
const props = defineProps({
|
||||
questId: {
|
||||
@@ -12,34 +11,21 @@ const props = defineProps({
|
||||
})
|
||||
|
||||
const toast = useToast()
|
||||
const showCover = ref(false)
|
||||
const showCover = ref(true)
|
||||
const sessionStore = useSession()
|
||||
|
||||
function init(questId: string) {
|
||||
if (!questId) throw new Error('No quest ID provided')
|
||||
try {
|
||||
getActiveSession(props.questId)
|
||||
} catch (err: any) {
|
||||
if (err instanceof LoadQuestError) {
|
||||
toast.error(`無法讀取關卡: ${err.questId},請確認網頁連結。`)
|
||||
return
|
||||
}
|
||||
if (err instanceof LoadSessionError) {
|
||||
toast.error(`無法建立工作階段: ${err.questId},請重新登入再試一次。`)
|
||||
return
|
||||
}
|
||||
console.error(err)
|
||||
toast.warning('Failed to connect previous session. Creating a new one...')
|
||||
showCover.value = true
|
||||
onMounted(async () => {
|
||||
sessionStore.setQuest(props.questId)
|
||||
if (await sessionStore.getActiveSession()) {
|
||||
showCover.value = false
|
||||
}
|
||||
}
|
||||
|
||||
init(props.questId)
|
||||
setQuest(props.questId)
|
||||
sessionStore.setup()
|
||||
})
|
||||
|
||||
const startSession = async () => {
|
||||
showCover.value = false
|
||||
try {
|
||||
createSession()
|
||||
await sessionStore.createSession()
|
||||
showCover.value = false
|
||||
} catch (err: any) {
|
||||
console.error(err)
|
||||
toast.error(err.message)
|
||||
|
||||
Reference in new issue
Block a user