Skip to content

Commit

Permalink
fix: Save and restore tabs between projects
Browse files Browse the repository at this point in the history
  • Loading branch information
aklinker1 committed Apr 8, 2024
1 parent b63b94b commit 9da3d2b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion web/components/MainSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const links = computed<HorizontalNavigationLink[]>(() => [
},
]);
const tab = ref<'bom' | 'stock' | 'settings' | 'warnings'>('bom');
const tab = useProjectTab();
const project = useProject();
const editProject = useEditProject();
Expand Down
17 changes: 17 additions & 0 deletions web/composables/useProjectTab.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { Tab } from './useProjectTabMap';

export default function () {
const project = useProject();
const map = useProjectTabMap();

return computed<Tab>({
get() {
if (project.value == null) return 'bom';
return map.value[project.value.id] ?? 'bom';
},
set(value) {
if (project.value == null) return;
map.value[project.value.id] = value;
},
});
}
5 changes: 5 additions & 0 deletions web/composables/useProjectTabMap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default createGlobalState(() =>
useSessionStorage<Record<string, Tab | undefined>>('@cutlist/tab-map', {}),
);

export type Tab = 'bom' | 'stock' | 'settings' | 'warnings';

0 comments on commit 9da3d2b

Please sign in to comment.