improve remembering of last project to be per-group.

This commit is contained in:
2021-08-09 17:01:24 +02:00
parent d1a8d55b9e
commit c074d270e8
2 changed files with 12 additions and 8 deletions
@@ -11,8 +11,6 @@
export let groups: ProjectGroupResult[] = []; export let groups: ProjectGroupResult[] = [];
export let selected: string; export let selected: string;
let failedCount = 0;
function onClickAdd() { function onClickAdd() {
modalStore.set({name: "projectgroup.add"}); modalStore.set({name: "projectgroup.add"});
} }
@@ -21,12 +19,17 @@
if (group.projects.length === 0) { if (group.projects.length === 0) {
navigate(`/questlog/${group.id}`); navigate(`/questlog/${group.id}`);
} else { } else {
const projetcs = [...group.projects].sort(sortProjects); const preferredId = localStorage.getItem(`sl2.projectgroup.${group.id}.last_project_id`);
navigate(`/questlog/${group.id}/${projetcs[0].id}`); const projects = [...group.projects].sort(sortProjects);
const project = projects.find(p => p.id === preferredId) || projects[0];
navigate(`/questlog/${group.id}/${project.id}`);
// There's some weirdness with navigate. This hack will just do a // There's some weirdness with navigate. This hack will just do a
// groups = [...groups] in the sttore to get the page to update. // groups = [...groups] in the sttore to get the page to update.
//
// Edit: It doesn't seem to be needed anymore? Idk why, but I'll keep this in just in case.
tick().then(() => { tick().then(() => {
projectGroupStore.fakeRefresh(); projectGroupStore.fakeRefresh();
}) })
+5 -4
View File
@@ -25,8 +25,8 @@
} }
$: { $: {
const lastGroupId = localStorage.getItem("stufflog3.questlog.last_group_id") || ""; const lastGroupId = localStorage.getItem("sl2.questlogpage.last_group_id") || "";
const lastProjectId = localStorage.getItem("stufflog3.questlog.last_project_id") || ""; const lastProjectId = localStorage.getItem("sl2.questlogpage.last_project_id") || "";
if ($projectGroupStore.groups.length > 0) { if ($projectGroupStore.groups.length > 0) {
// Try to restore last selection // Try to restore last selection
@@ -60,8 +60,9 @@
navigate(`/questlog/${group.id}`); navigate(`/questlog/${group.id}`);
} }
} else { } else {
localStorage.setItem("stufflog3.questlog.last_group_id", groupId); localStorage.setItem("sl2.questlogpage.last_group_id", groupId);
localStorage.setItem("stufflog3.questlog.last_project_id", projectId); localStorage.setItem("sl2.questlogpage.last_project_id", projectId);
localStorage.setItem(`sl2.projectgroup.${groupId}.last_project_id`, projectId);
} }
} }
} }