rename frontend subfolder
This commit is contained in:
parent
0a894237bb
commit
16f084bfcd
21 changed files with 12 additions and 2 deletions
31
frontend/src/lib/router.svelte.js
Normal file
31
frontend/src/lib/router.svelte.js
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { chatStore } from "./chatStore.svelte.js";
|
||||
|
||||
// keyed by chat_id → chatStore instance
|
||||
const cache = $state({});
|
||||
|
||||
// which chat is on screen right now
|
||||
export const activeChatId = $state(null);
|
||||
|
||||
export function getStore(chatId) {
|
||||
if (!cache[chatId]) {
|
||||
cache[chatId] = chatStore(chatId);
|
||||
}
|
||||
return cache[chatId];
|
||||
}
|
||||
|
||||
export function switchChat(chatId) {
|
||||
activeChatId = chatId;
|
||||
}
|
||||
|
||||
export function newChat() {
|
||||
const id = "chat_" + crypto.randomUUID();
|
||||
switchChat(id);
|
||||
return id;
|
||||
}
|
||||
|
||||
// restore last opened chat (or create first one)
|
||||
(() => {
|
||||
const ids = JSON.parse(localStorage.getItem("chat_ids") || "[]");
|
||||
if (ids.length) switchChat(ids[0]);
|
||||
else newChat();
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue