Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented: Page Selection Persistence for Import App with Side Navigation(#122) #224

Merged
merged 2 commits into from
Aug 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 14 additions & 21 deletions src/components/Menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<ion-menu-toggle auto-hide="false" v-for="(p, i) in appPages" :key="i">
<ion-item
button
@click="selectedIndex = i"
router-direction="root"
:router-link="p.url"
class="hydrated"
Expand Down Expand Up @@ -51,11 +50,12 @@ import {
IonTitle,
IonToolbar,
} from "@ionic/vue";
import { defineComponent, ref } from "vue";
import { computed, defineComponent } from "vue";
import { mapGetters } from "vuex";

import { albumsOutline, bookmarkOutline, settings, calendar } from "ionicons/icons";
import { useStore } from "@/store";
import { useRouter } from "vue-router";

export default defineComponent({
name: "Menu",
Expand All @@ -73,48 +73,35 @@ export default defineComponent({
IonTitle,
IonToolbar
},
created() {
// When open any specific page it should show that page selected
// TODO Find a better way
this.selectedIndex = this.appPages.findIndex((page) => {
return page.url === this.$router.currentRoute.value.path;
})
},
computed: {
...mapGetters({
isUserAuthenticated: 'user/isUserAuthenticated',
instanceUrl: 'user/getInstanceUrl',
userProfile: 'user/getUserProfile'
})
},
watch:{
$route (to) {
// When logout and login it should point to Oth index
// TODO Find a better way
if (to.path === '/login') {
this.selectedIndex = 0;
}
},
},
setup() {
const store = useStore();
const selectedIndex = ref(0);
const router = useRouter();
const appPages = [
{
title: "Inventory",
url: "/inventory",
childRoutes: ["/inventory-review"],
iosIcon: albumsOutline,
mdIcon: albumsOutline
},
{
title: "Purchase order",
url: "/purchase-order",
childRoutes: ["/purchase-order-review"],
iosIcon: calendar,
mdIcon: calendar
},
{
title: "Saved Mappings",
url: "/saved-mappings",
childRoutes: ["/mapping/"],
iosIcon: bookmarkOutline,
mdIcon: bookmarkOutline
},
Expand All @@ -123,8 +110,14 @@ export default defineComponent({
url: "/settings",
iosIcon: settings,
mdIcon: settings,
},
}
];

const selectedIndex = computed(() => {
const path = router.currentRoute.value.path
return appPages.findIndex((screen) => screen.url === path || screen.childRoutes?.includes(path) || screen.childRoutes?.some((route) => path.includes(route)))
})

return {
selectedIndex,
appPages,
Expand All @@ -133,7 +126,7 @@ export default defineComponent({
settings,
store
};
},
}
});
</script>
<style scoped>
Expand Down