|
|
@@ -67,6 +67,16 @@ export type WorkspaceState = {
|
|
|
* Maps request IDs to their latest response.
|
|
|
*/
|
|
|
responses: Record<number, HttpResponse>;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Holds entry selection history.
|
|
|
+ */
|
|
|
+ entryHistory: number[];
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Holds the currently selected entry index.
|
|
|
+ */
|
|
|
+ entryIndex: number;
|
|
|
};
|
|
|
|
|
|
export const state: WorkspaceState = $state({
|
|
|
@@ -80,6 +90,8 @@ export const state: WorkspaceState = $state({
|
|
|
auth: [],
|
|
|
pendingRequests: [],
|
|
|
responses: {},
|
|
|
+ entryHistory: [],
|
|
|
+ entryIndex: 0,
|
|
|
});
|
|
|
|
|
|
const index = (entry: WorkspaceEntry) => {
|
|
|
@@ -97,6 +109,11 @@ const index = (entry: WorkspaceEntry) => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+const reIndex = (entry: WorkspaceEntry) => {
|
|
|
+ console.log("re-indexing", entry);
|
|
|
+ state.indexes[entry.id] = entry;
|
|
|
+};
|
|
|
+
|
|
|
function reset() {
|
|
|
state.children = {};
|
|
|
state.indexes = {};
|
|
|
@@ -107,6 +124,8 @@ function reset() {
|
|
|
state.auth = [];
|
|
|
state.pendingRequests = [];
|
|
|
state.responses = {};
|
|
|
+ state.entryHistory = [];
|
|
|
+ state.entryIndex = 0;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -168,7 +187,56 @@ export function selectWorkspace(ws: Workspace) {
|
|
|
state.workspace = ws;
|
|
|
}
|
|
|
|
|
|
+export async function selectPreviousEntry() {
|
|
|
+ if (state.entryHistory.length === 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (state.entryIndex === 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ state.entryIndex -= 1;
|
|
|
+ state.entry = state.indexes[state.entryHistory[state.entryIndex]];
|
|
|
+ console.log($state.snapshot(state.entryIndex));
|
|
|
+ console.log($state.snapshot(state.entryHistory));
|
|
|
+}
|
|
|
+
|
|
|
+export async function selectNextEntry() {
|
|
|
+ if (state.entryHistory.length === 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (state.entryIndex === state.entryHistory.length - 1) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ state.entryIndex += 1;
|
|
|
+ state.entry = state.indexes[state.entryHistory[state.entryIndex]];
|
|
|
+ console.log($state.snapshot(state.entryIndex));
|
|
|
+ console.log($state.snapshot(state.entryHistory));
|
|
|
+}
|
|
|
+
|
|
|
+function pushEntry(id: number) {
|
|
|
+ if (state.entryIndex < state.entryHistory.length - 1) {
|
|
|
+ state.entryHistory.splice(state.entryIndex + 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (state.entryHistory[state.entryHistory.length - 1] !== id) {
|
|
|
+ state.entryHistory.push(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ state.entryIndex = state.entryHistory.length - 1;
|
|
|
+
|
|
|
+ console.log($state.snapshot(state.entryIndex));
|
|
|
+ console.log($state.snapshot(state.entryHistory));
|
|
|
+}
|
|
|
+
|
|
|
export async function selectEntry(id: number) {
|
|
|
+ if (state.entry?.id === id) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
const entry = await invoke<WorkspaceEntryResponse>("get_workspace_entry", {
|
|
|
entryId: id,
|
|
|
});
|
|
|
@@ -192,13 +260,16 @@ export async function selectEntry(id: number) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ reIndex(state.entry);
|
|
|
+ pushEntry(id);
|
|
|
+
|
|
|
console.log("selected entry:", $state.snapshot(state.entry));
|
|
|
|
|
|
if (state.entry.parent_id != null) {
|
|
|
let parent = state.indexes[state.entry.parent_id];
|
|
|
while (parent) {
|
|
|
parent.open = true;
|
|
|
- if (parent.parent_id === null) {
|
|
|
+ if (parent.parent_id == null) {
|
|
|
break;
|
|
|
}
|
|
|
parent = state.indexes[parent.parent_id];
|
|
|
@@ -406,7 +477,7 @@ export async function updateEntryName(name: string) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- console.debug(state.entry.id, "updating entry name to", name);
|
|
|
+ console.debug("entry name update", state.entry.id, name);
|
|
|
|
|
|
await invoke("update_workspace_entry", {
|
|
|
entryId: state.entry.id,
|