GUILHERME 81727c16f8
Some checks failed
Dev Build & Deploy Divida Ativa Web / build-deploy (push) Failing after 33s
feat: SPA autonomo de Divida Ativa com bootstrap multi-tenant e CRUDs Livro/Folha/CDA
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-06 17:50:31 -03:00

44 lines
1.4 KiB
JavaScript

import { defineStore } from 'pinia';
export const useMenuStore = defineStore('menu', {
state: () => ({
activeMenuItems: [],
favorites: [],
recent: [],
}),
persist: {
pick: ['favorites', 'recent'],
},
actions: {
toggleMenuItem(key) {
const idx = this.activeMenuItems.indexOf(key);
if (idx > -1) {
this.activeMenuItems.splice(idx, 1);
} else {
this.activeMenuItems.push(key);
}
},
addActiveMenuItem(key) {
if (!this.activeMenuItems.includes(key)) {
this.activeMenuItems.push(key);
}
},
toggleFavorite(item) {
const path = typeof item.to === 'string' ? item.to : item.to?.path;
const idx = this.favorites.findIndex((f) => f.to === path);
if (idx > -1) {
this.favorites.splice(idx, 1);
} else {
this.favorites.push({ label: item.label, to: path, icon: item.icon });
}
},
addToRecent(item) {
const path = typeof item.to === 'string' ? item.to : item.to?.path;
this.recent = [{ label: item.label, to: path, icon: item.icon }, ...this.recent.filter((r) => r.to !== path)].slice(
0,
5
);
},
},
});