Browse Source

fix last open project not being remembered when clicking Projects in the menu.

main
Gisle Aune 3 years ago
parent
commit
d1a8d55b9e
  1. 8
      svelte-ui/src/components/QuestLog.svelte
  2. 28
      svelte-ui/src/pages/QLPage.svelte

8
svelte-ui/src/components/QuestLog.svelte

@ -1,7 +1,3 @@
<script lang="ts" context="module">
let lastQuest = "";
</script>
<script lang="ts">
import type { ProjectResult } from "../models/project";
import ProjectEntry from "./ProjectEntry.svelte";
@ -41,11 +37,9 @@
}
// Ensure a selection.
$: {
if (groupId == "" && groups.length > 0) {
$: if (groupId == "" && groups.length > 0) {
groupId = groups[0].id;
}
}
$: selectedGroup = groups.find(g => g.id === groupId)
$: visibleProjects = selectedGroup?.projects || [];

28
svelte-ui/src/pages/QLPage.svelte

@ -25,13 +25,31 @@
}
$: {
if ($projectGroupStore.groups.length > 0 && groupId === "") {
const group = $projectGroupStore.groups[0];
const lastGroupId = localStorage.getItem("stufflog3.questlog.last_group_id") || "";
const lastProjectId = localStorage.getItem("stufflog3.questlog.last_project_id") || "";
if ($projectGroupStore.groups.length > 0) {
// Try to restore last selection
let group = $projectGroupStore.groups[0];
let preferredProjectId = "";
if (groupId === "") {
if (lastGroupId !== "" && lastProjectId !== "") {
const lastGroup = $projectGroupStore.groups.find(g => g.id === lastGroupId);
if (lastGroup != null) {
const lastProject = lastGroup.projects.find(p => p.id === lastProjectId);
if (lastProject != null) {
group = lastGroup;
preferredProjectId = lastProject.id;
}
}
}
if (group.projects.length > 0) {
const projects = [...group.projects].sort(sortProjects);
const project = projects.find(p => p.id === preferredProjectId) || projects[0];
navigate(`/questlog/${group.id}/${projects[0].id}`, {replace: true});
navigate(`/questlog/${group.id}/${project.id}`, {replace: true});
// There's some weirdness with navigate. This hack will just do a
// groups = [...groups] in the sttore to get the page to update.
@ -41,6 +59,10 @@
} else {
navigate(`/questlog/${group.id}`);
}
} else {
localStorage.setItem("stufflog3.questlog.last_group_id", groupId);
localStorage.setItem("stufflog3.questlog.last_project_id", projectId);
}
}
}
</script>

Loading…
Cancel
Save