Skip to content

Commit

Permalink
link "History" to the last page visited
Browse files Browse the repository at this point in the history
  • Loading branch information
TaiSakuma committed Aug 22, 2023
1 parent a804a66 commit 626361d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/app/AppBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import { ref, computed } from "vue";
import { useConfig } from "@/utils/config";
import naviItems from "./navi-items";
import { useNaviItems } from "./navi-items";
import ScheduleCtrl from "@/components/ScheduleCtrl.vue";
import ToggleDarkModeButton from "@/components/utils/ToggleDarkModeButton.vue";
Expand All @@ -45,4 +45,5 @@ const apiName = computed(() => config.value.apiName || "");
const apiHttp = computed(() => config.value.apiHttp);
const tab = ref<string | null>(null);
const { naviItems } = useNaviItems();
</script>
3 changes: 2 additions & 1 deletion src/app/NavigationDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@
<script setup lang="ts">
import { ref, computed } from "vue";
import { useConfig } from "@/utils/config";
import naviItems from "./navi-items";
import { useNaviItems } from "./navi-items";
const { config } = useConfig();
const version = ref(import.meta.env.PACKAGE_VERSION);
const appName = computed(() => config.value.appName || "loading...");
const { naviItems } = useNaviItems();
</script>
49 changes: 33 additions & 16 deletions src/app/navi-items.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { RouteLocationRaw } from "vue-router";
import { computed, ref, watchEffect, toValue } from "vue";
import { useRoute } from "vue-router";
import type { RouteLocationRaw } from "vue-router";
import { useSessionStorage } from "@vueuse/core";

interface NaviItem {
icon: string;
Expand All @@ -7,19 +10,33 @@ interface NaviItem {
exact: boolean;
}

const naviItems: NaviItem[] = [
{
icon: "mdi-home",
title: "Main",
to: { name: "home" },
exact: true,
},
{
icon: "mdi-database",
title: "History",
to: { name: "runs" },
exact: false,
},
];
export function useNaviItems() {
const route = useRoute();
const routeNamesDb = ["runs", "run"];

export default naviItems;
const lastInDb = useSessionStorage<RouteLocationRaw>("lastInDb", {
name: "runs",
});

watchEffect(() => {
if (!routeNamesDb.includes(route.name as string)) return;
lastInDb.value = { path: route.path };
});

const naviItems = computed<NaviItem[]>(() => [
{
icon: "mdi-home",
title: "Main",
to: { name: "home" },
exact: true,
},
{
icon: "mdi-database",
title: "History",
to: toValue(lastInDb),
exact: false,
},
]);

return { naviItems };
}

0 comments on commit 626361d

Please sign in to comment.