feat: store graph in session manager

This commit is contained in:
wancat committed 2023-08-29 14:28:09 +08:00
1 parent 1c017c98c7
commit 3dae9e8552
4 files changed
+32 -26

No files matched your search

+18 -1
View File
@@ -1,10 +1,18 @@
import { ref } from 'vue'
import { FileGraph } from '@linux-odyssey/file-graph'
import api from './api'
class SessionManager {
constructor(questId) {
this.questId = questId
this.session = ref(null)
this.graph = ref(
new FileGraph({
path: '/',
type: 'folder',
discovered: false,
})
)
}
getSession() {
@@ -14,6 +22,13 @@ class SessionManager {
setSession(session) {
console.log('Update session:', session)
this.session.value = session
this.graph.value = new FileGraph(session.graph)
}
handleGraphUpdate(event) {
if (event.discover) {
this.graph.value.discover(event.discover)
}
}
async createSession() {
@@ -37,7 +52,8 @@ class SessionManager {
if (sessions.length === 0) {
return
}
const session = sessions[sessions.length - 1]
const { _id: sessionId } = sessions[sessions.length - 1]
const { data: session } = await api.get(`/sessions/${sessionId}`)
console.log(
`Last Session ID: ${session._id}, Quest: ${session.quest}, Created At: ${session.createdAt}`
)
@@ -49,6 +65,7 @@ class SessionManager {
if (!this.session.value) {
await this.createSession()
}
console.log(this.session.value)
}
}