feat: add vue-router

This commit is contained in:
pa
2025-10-16 00:00:48 +09:00
committed by Natsumi
parent 9cba3dbce8
commit df04f1d449
24 changed files with 175 additions and 136 deletions

View File

@@ -1,11 +1,13 @@
import { ref, watch } from 'vue';
import { defineStore } from 'pinia';
import { useRouter } from 'vue-router';
import { useNotificationStore } from './notification';
import { watchState } from '../service/watchState';
export const useUiStore = defineStore('Ui', () => {
const notificationStore = useNotificationStore();
const router = useRouter();
document.addEventListener('keydown', function (e) {
if (e.shiftKey) {
@@ -19,7 +21,6 @@ export const useUiStore = defineStore('Ui', () => {
}
});
const menuActiveIndex = ref('feed');
const notifiedMenus = ref([]);
const shiftHeld = ref(false);
@@ -27,40 +28,43 @@ export const useUiStore = defineStore('Ui', () => {
() => watchState.isLoggedIn,
(isLoggedIn) => {
if (isLoggedIn) {
menuActiveIndex.value = 'feed';
router.push({ name: 'feed' });
}
},
{ flush: 'sync' }
);
function notifyMenu(index) {
const currentRouteName = router.currentRoute.value?.name;
if (
index !== menuActiveIndex.value &&
index !== currentRouteName &&
!notifiedMenus.value.includes(index)
) {
notifiedMenus.value.push(index);
}
}
function selectMenu(index) {
menuActiveIndex.value = index;
removeNotify(index);
if (index === 'notification') {
notificationStore.unseenNotifications = [];
watch(
() => router.currentRoute.value.name,
(routeName) => {
if (routeName) {
removeNotify(routeName);
if (routeName === 'notification') {
notificationStore.unseenNotifications = [];
}
}
}
}
);
function removeNotify(index) {
notifiedMenus.value = notifiedMenus.value.filter((i) => i !== index);
}
return {
menuActiveIndex,
notifiedMenus,
shiftHeld,
notifyMenu,
selectMenu,
removeNotify
};
});