auto connect session, create session after button

This commit is contained in:
Annie Huang authored and wancat committed 2024-06-27 10:30:00 +08:00
1 parent ea2ba2c7a0
commit 15465feda9
2 files changed
+40 -25

No files matched your search

+20 -19
View File
@@ -80,14 +80,15 @@ export async function createSession() {
}
}
async function getActiveSession(questId: string) {
export async function getActiveSession(questId: string) {
try {
const res = await api.post('/sessions/active', { questId })
await setSession(res.data)
} catch (err) {
console.error(err)
toast.warning('Failed to connect previous session. Creating a new one...')
await createSession()
throw new LoadSessionError('Failed to load session', questId)
// toast.warning('Failed to connect previous session. Creating a new one...')
// await createSession()
}
}
@@ -119,22 +120,22 @@ export function reset() {
store.quest = null
}
export async function init(questId: string) {
if (!questId) throw new Error('No quest ID provided')
// reset()
// try {
// await setQuest(questId)
// } catch (err) {
// console.error(err)
// throw new LoadQuestError('Failed to load quest', questId)
// }
try {
await getActiveSession(questId)
} catch (err) {
console.error(err)
throw new LoadSessionError('Failed to load session', questId)
}
}
// export async function init(questId: string) {
// if (!questId) throw new Error('No quest ID provided')
// reset()
// try {
// await setQuest(questId)
// } catch (err) {
// console.error(err)
// throw new LoadQuestError('Failed to load quest', questId)
// }
// try {
// await getActiveSession(questId)
// } catch (err) {
// console.error(err)
// throw new LoadSessionError('Failed to load session', questId)
// }
// }
function setup() {
socket.on('terminal', (data: string) => {