fix last open project not being remembered when clicking Projects in the menu.
This commit is contained in:
@@ -1,7 +1,3 @@
|
|||||||
<script lang="ts" context="module">
|
|
||||||
let lastQuest = "";
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { ProjectResult } from "../models/project";
|
import type { ProjectResult } from "../models/project";
|
||||||
import ProjectEntry from "./ProjectEntry.svelte";
|
import ProjectEntry from "./ProjectEntry.svelte";
|
||||||
@@ -41,10 +37,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ensure a selection.
|
// Ensure a selection.
|
||||||
$: {
|
$: if (groupId == "" && groups.length > 0) {
|
||||||
if (groupId == "" && groups.length > 0) {
|
groupId = groups[0].id;
|
||||||
groupId = groups[0].id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$: selectedGroup = groups.find(g => g.id === groupId)
|
$: selectedGroup = groups.find(g => g.id === groupId)
|
||||||
|
|||||||
@@ -25,21 +25,43 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
if ($projectGroupStore.groups.length > 0 && groupId === "") {
|
const lastGroupId = localStorage.getItem("stufflog3.questlog.last_group_id") || "";
|
||||||
const group = $projectGroupStore.groups[0];
|
const lastProjectId = localStorage.getItem("stufflog3.questlog.last_project_id") || "";
|
||||||
|
|
||||||
if (group.projects.length > 0) {
|
if ($projectGroupStore.groups.length > 0) {
|
||||||
const projects = [...group.projects].sort(sortProjects);
|
// 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);
|
||||||
|
|
||||||
navigate(`/questlog/${group.id}/${projects[0].id}`, {replace: true});
|
if (lastGroup != null) {
|
||||||
|
const lastProject = lastGroup.projects.find(p => p.id === lastProjectId);
|
||||||
|
if (lastProject != null) {
|
||||||
|
group = lastGroup;
|
||||||
|
preferredProjectId = lastProject.id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// There's some weirdness with navigate. This hack will just do a
|
if (group.projects.length > 0) {
|
||||||
// groups = [...groups] in the sttore to get the page to update.
|
const projects = [...group.projects].sort(sortProjects);
|
||||||
tick().then(() => {
|
const project = projects.find(p => p.id === preferredProjectId) || projects[0];
|
||||||
projectGroupStore.fakeRefresh();
|
|
||||||
})
|
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.
|
||||||
|
tick().then(() => {
|
||||||
|
projectGroupStore.fakeRefresh();
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
navigate(`/questlog/${group.id}`);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
navigate(`/questlog/${group.id}`);
|
localStorage.setItem("stufflog3.questlog.last_group_id", groupId);
|
||||||
|
localStorage.setItem("stufflog3.questlog.last_project_id", projectId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user