feat: add vue-toastification for alerting

This commit is contained in:
wancat authored and Lin, Hung-Shin committed 2023-11-14 10:45:24 +08:00
1 parent 2d0fffc8f4
commit d0e2a4125d
7 files changed
+58 -22

No files matched your search

+19 -9
View File
@@ -1,9 +1,12 @@
import { reactive } from 'vue'
import { useToast } from 'vue-toastification'
import { FileGraph } from '@linux-odyssey/file-graph'
import api from '../utils/api'
import Socket from '../utils/socket'
import SocketTerminal from '../utils/terminal'
const toast = useToast()
function newSession() {
const graph = new FileGraph({
path: '/',
@@ -50,15 +53,22 @@ export async function createSession() {
await setSession(data)
}
async function getActiveSession(questId) {
const res = await api.post('/sessions/active', { questId })
const session = res.data
try {
await setSession(session)
} catch (err) {
console.log(err)
await createSession().catch(console.error)
}
function getActiveSession(questId) {
return api
.post('/sessions/active', { questId })
.then((res) => {
const session = res.data
return setSession(session)
})
.catch((err) => {
console.log(err)
toast.warning('Failed to connect previous session. Creating a new one...')
return createSession()
})
.catch((err) => {
console.log(err)
toast.error('Failed to create a new session. Please try again later.')
})
}
function updateGraph(event) {