mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 03:20:12 +08:00
feat: store graph in session manager
This commit is contained in:
1 parent
1c017c98c7
commit
3dae9e8552
4 files changed
+32
-26
No files matched your search
@@ -20,6 +20,9 @@ onMounted(async () => {
|
|||||||
console.log('Disconnected from the server.')
|
console.log('Disconnected from the server.')
|
||||||
})
|
})
|
||||||
socket.on('message', console.log)
|
socket.on('message', console.log)
|
||||||
|
socket.on('graph', (event) => {
|
||||||
|
sessionManager.handleGraphUpdate(event)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,36 +1,16 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { onMounted, ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { FileGraph } from '@linux-odyssey/file-graph'
|
|
||||||
import FileNode from './FileNode.vue'
|
import FileNode from './FileNode.vue'
|
||||||
import socket from '../utils/socket.js'
|
import sessionManager from '../utils/session.js'
|
||||||
|
|
||||||
const pwd = ref('/home/rudeus')
|
const pwd = ref('/home/rudeus')
|
||||||
|
|
||||||
const graph = ref(
|
|
||||||
new FileGraph({
|
|
||||||
path: '/',
|
|
||||||
name: '/',
|
|
||||||
type: 'folder',
|
|
||||||
discovered: false,
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
socket.on('graph', (event) => {
|
|
||||||
// TODO: update graph
|
|
||||||
console.log(event)
|
|
||||||
if (event.discover) {
|
|
||||||
graph.value.discover(event.discover)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="tree w-max h-max">
|
<div class="tree w-max h-max">
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<FileNode :node="graph" :pwd="pwd" />
|
<FileNode :node="sessionManager.graph.value" :pwd="pwd" />
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,10 +1,18 @@
|
|||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
|
import { FileGraph } from '@linux-odyssey/file-graph'
|
||||||
import api from './api'
|
import api from './api'
|
||||||
|
|
||||||
class SessionManager {
|
class SessionManager {
|
||||||
constructor(questId) {
|
constructor(questId) {
|
||||||
this.questId = questId
|
this.questId = questId
|
||||||
this.session = ref(null)
|
this.session = ref(null)
|
||||||
|
this.graph = ref(
|
||||||
|
new FileGraph({
|
||||||
|
path: '/',
|
||||||
|
type: 'folder',
|
||||||
|
discovered: false,
|
||||||
|
})
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
getSession() {
|
getSession() {
|
||||||
@@ -14,6 +22,13 @@ class SessionManager {
|
|||||||
setSession(session) {
|
setSession(session) {
|
||||||
console.log('Update session:', session)
|
console.log('Update session:', session)
|
||||||
this.session.value = 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() {
|
async createSession() {
|
||||||
@@ -37,7 +52,8 @@ class SessionManager {
|
|||||||
if (sessions.length === 0) {
|
if (sessions.length === 0) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const session = sessions[sessions.length - 1]
|
const { _id: sessionId } = sessions[sessions.length - 1]
|
||||||
|
const { data: session } = await api.get(`/sessions/${sessionId}`)
|
||||||
console.log(
|
console.log(
|
||||||
`Last Session ID: ${session._id}, Quest: ${session.quest}, Created At: ${session.createdAt}`
|
`Last Session ID: ${session._id}, Quest: ${session.quest}, Created At: ${session.createdAt}`
|
||||||
)
|
)
|
||||||
@@ -49,6 +65,7 @@ class SessionManager {
|
|||||||
if (!this.session.value) {
|
if (!this.session.value) {
|
||||||
await this.createSession()
|
await this.createSession()
|
||||||
}
|
}
|
||||||
|
console.log(this.session.value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ import { FileNode } from '@linux-odyssey/file-graph'
|
|||||||
const nodeSchema = new Schema({
|
const nodeSchema = new Schema({
|
||||||
path: String,
|
path: String,
|
||||||
type: String,
|
type: String,
|
||||||
discovered: Boolean,
|
discovered: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
nodeSchema.add({
|
nodeSchema.add({
|
||||||
@@ -41,7 +44,10 @@ const Session = model(
|
|||||||
hints: [String],
|
hints: [String],
|
||||||
graph: {
|
graph: {
|
||||||
type: nodeSchema,
|
type: nodeSchema,
|
||||||
default: new FileNode({ path: '/', name: '/', type: 'folder' }),
|
default: new FileNode({
|
||||||
|
path: '/',
|
||||||
|
type: 'folder',
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ timestamps: true }
|
{ timestamps: true }
|
||||||
|
|||||||
Reference in new issue
Block a user