Skip to content

Commit

Permalink
implement route hash for quick tab navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
Raajheer1 committed Mar 9, 2024
1 parent 44cbca9 commit 24f77c1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
21 changes: 20 additions & 1 deletion src/views/Profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
</template>

<script setup lang="ts">
import { ref } from "vue";
import { computed, onMounted, ref, watch } from "vue";
import { useRoute } from "vue-router";
// Components
import Card from "@/components/Card.vue";
Expand All @@ -46,7 +47,25 @@ const tabs = ref<string[]>(["Profile", "Notifications", "Discord"]);
const selectedTab = ref<number>(0);
const changeTab = (tab: number): void => {
selectedTab.value = tab;
window.location.hash = tabs.value[tab].toLowerCase();
};
const route = useRoute();
const currentHashTab = computed(() => {
const hash = route.hash.slice(1); // Remove leading "#"
return tabs.value.findIndex((tab) => tab.toLowerCase() === hash) || 0;
});
watch(currentHashTab, (newTab) => {
selectedTab.value = newTab;
});
// Initial check on component mount
onMounted(() => {
selectedTab.value = currentHashTab.value;
});
</script>

<style scoped>
Expand Down
7 changes: 5 additions & 2 deletions src/views/partials/MobileSidebar.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<div class="fixed top-[60px] left-0 w-screen h-screen z-50 transition-all">
<div class="bg-usa-blue w-[275px] p-4 text-sm">
<div class="fixed top-[60px] left-0 w-screen h-screen z-50 transition-all lg:invisible lg:opacity-0">
<div class="top-0 left-0 w-full h-full absolute bg-black bg-opacity-80 content-['']" @click="$emit('toggle')"></div>
<div class="relative bg-usa-blue w-[275px] max-w-[80%] p-4 text-sm rounded-br">
<div v-for="(link, idx) in SidebarLinks" :key="idx">
<div v-if="link.separator" class="mt-2 flex py-1 my-auto">
<h2 v-if="link.separatorTitle !== undefined" class="mr-4 text-usa-white text-md font-bold">
Expand All @@ -13,6 +14,7 @@
class="flex rounded p-3 hover:bg-white text-usa-white hover:bg-opacity-20 hover:text-usa-red items-center justify-between my-0.5"
active-class="bg-white bg-opacity-10 font-bold text-usa-red"
:to="link.to"
@click="$emit('toggle')"
>
<div class="flex items-center gap-x-4">
<span class="w-4 mx-auto text-center">
Expand All @@ -28,6 +30,7 @@
v-else
class="flex rounded p-3 hover:bg-white text-usa-white hover:bg-opacity-20 hover:text-usa-red items-center justify-between my-0.5"
active-class="bg-white bg-opacity-10 font-bold text-usa-red"
@click="$emit('toggle')"
>
<div class="flex items-center gap-x-4">
<span class="w-4 mx-auto text-center">
Expand Down

0 comments on commit 24f77c1

Please sign in to comment.