diff --git a/frontend/src/repositories/WS.ts b/frontend/src/repositories/WS.ts index 44fad33..a57ff21 100644 --- a/frontend/src/repositories/WS.ts +++ b/frontend/src/repositories/WS.ts @@ -6,24 +6,26 @@ export const uploadUrl = '/api/upload' export const watchUrl = '/api/watch' let tree = [] as FileEntry[] -let reconnectDuration = 500 +let reconnDelay = 500 let wsWatch = null as WebSocket | null export const loadSession = () => { + const s = localStorage['cista-files'] + if (!s) return false const store = useDocumentStore() try { - tree = JSON.parse(sessionStorage['cista-files']) + tree = JSON.parse(s) store.updateRoot(tree) - console.log(`Loaded session ${tree.length} items`) + console.log(`Loaded session with ${tree.length} items cached`) return true } catch (error) { - if (sessionStorage['cista-files']) console.log("Loading session failed", error) + console.log("Loading session failed", error) return false } } const saveSession = () => { - sessionStorage["cista-files"] = JSON.stringify(tree) + localStorage["cista-files"] = JSON.stringify(tree) } export const connect = (path: string, handlers: Partial>) => { @@ -61,7 +63,7 @@ export const watchConnect = () => { console.log('Connected to backend', msg) store.server = msg.server store.connected = true - reconnectDuration = 500 + reconnDelay = 500 store.error = '' if (msg.user) store.login(msg.user.username, msg.user.privileged) else if (store.isUserLogged) store.logout() @@ -85,10 +87,10 @@ const watchReconnect = (event: MessageEvent) => { store.connected = false store.error = 'Reconnecting...' } - reconnectDuration = Math.min(5000, reconnectDuration + 500) + reconnDelay = Math.min(5000, reconnDelay + 500) // The server closes the websocket after errors, so we need to reopen it if (watchTimeout !== null) clearTimeout(watchTimeout) - watchTimeout = setTimeout(watchConnect, reconnectDuration) + watchTimeout = setTimeout(watchConnect, reconnDelay) } diff --git a/frontend/src/stores/documents.ts b/frontend/src/stores/documents.ts index 5fcb2d7..7ea40da 100644 --- a/frontend/src/stores/documents.ts +++ b/frontend/src/stores/documents.ts @@ -67,6 +67,7 @@ export const useDocumentStore = defineStore({ console.log("Logout") await logoutUser() this.$reset() + localStorage.clear() history.go() // Reload page } },