Skip to content

Commit

Permalink
Merge pull request #224 from amansinghbais/import/#122
Browse files Browse the repository at this point in the history
Implemented: Page Selection Persistence for Import App with Side Navigation(#122)
  • Loading branch information
ravilodhi authored Aug 25, 2023
2 parents c466e37 + 387de76 commit f343fdf
Showing 1 changed file with 14 additions and 21 deletions.
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

0 comments on commit f343fdf

Please sign in to comment.