2023-04-29 23:15:07 +02:00
|
|
|
import {defineStore} from 'pinia';
|
2023-09-07 16:06:17 +02:00
|
|
|
import {router} from '@inertiajs/vue3';
|
2023-04-29 23:15:07 +02:00
|
|
|
|
|
|
|
export const menuStore = defineStore('menu', {
|
|
|
|
state: () => ({
|
|
|
|
visible: false,
|
|
|
|
overflowVisible: false,
|
|
|
|
tooltipsVisible: false,
|
|
|
|
}),
|
|
|
|
getters: {
|
|
|
|
isShifted: (state) => state.visible || state.overflowVisible,
|
|
|
|
hideable: (state) => state.overflowVisible && !state.visible,
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
menuListener() {
|
|
|
|
var x = window.matchMedia('(min-width: 1024px)');
|
|
|
|
|
|
|
|
if (x.matches && !this.visible) {
|
|
|
|
this.visible = true;
|
|
|
|
this.overflowVisible = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!x.matches && this.visible) {
|
|
|
|
this.visible = false;
|
|
|
|
this.overflowVisible = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.tooltipsVisible = !window.matchMedia('(min-width: 1280px)').matches;
|
|
|
|
},
|
|
|
|
startInertiaListener() {
|
|
|
|
window.addEventListener('resize', this.menuListener);
|
|
|
|
this.menuListener();
|
|
|
|
|
2023-09-07 16:06:17 +02:00
|
|
|
router.on('before', () => {
|
2023-04-29 23:15:07 +02:00
|
|
|
if (!window.matchMedia('(min-width: 1024px)').matches) {
|
2023-09-07 16:06:17 +02:00
|
|
|
this.visible = false;
|
|
|
|
this.overflowVisible = false;
|
2023-04-29 23:15:07 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
toggle() {
|
|
|
|
this.overflowVisible = !this.overflowVisible;
|
|
|
|
},
|
|
|
|
hide() {
|
|
|
|
this.overflowVisible = false;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|