diff options
Diffstat (limited to 'packages/desktop/src/context')
| -rw-r--r-- | packages/desktop/src/context/local.tsx | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/packages/desktop/src/context/local.tsx b/packages/desktop/src/context/local.tsx index 4c2a3d3be..b04c70f0f 100644 --- a/packages/desktop/src/context/local.tsx +++ b/packages/desktop/src/context/local.tsx @@ -202,6 +202,13 @@ function init() { } } + const init = async (path: string) => { + const relativePath = relative(path) + if (!store.node[relativePath]) await fetch(path) + if (store.node[relativePath].loaded) return + return load(relativePath) + } + const open = async (path: string, options?: { pinned?: boolean; view?: LocalFile["view"] }) => { const relativePath = relative(path) if (!store.node[relativePath]) await fetch(path) @@ -271,6 +278,7 @@ function init() { update: (path: string, node: LocalFile) => setStore("node", path, reconcile(node)), open, load, + init, close(path: string) { setStore("opened", (opened) => opened.filter((x) => x !== path)) if (store.active === path) { @@ -473,11 +481,16 @@ function init() { const context = (() => { const [store, setStore] = createStore<{ activeTab: boolean + files: string[] + activeFile?: string items: (ContextItem & { key: string })[] }>({ activeTab: true, + files: [], items: [], }) + const files = createMemo(() => store.files.map((x) => file.node(x))) + const activeFile = createMemo(() => (store.activeFile ? file.node(store.activeFile) : undefined)) return { all() { @@ -505,6 +518,17 @@ function init() { remove(key: string) { setStore("items", (x) => x.filter((x) => x.key !== key)) }, + files, + openFile(path: string) { + file.init(path).then(() => { + setStore("files", (x) => [...x, path]) + setStore("activeFile", path) + }) + }, + activeFile, + setActiveFile(path: string | undefined) { + setStore("activeFile", path) + }, } })() |
