All checks were successful
Auto Tag Develop / tag (push) Successful in 6s
| Numéro du ticket | Titre du ticket | |------------------|-----------------| | | | ## Description de la PR ## Modification du .env ## Check list - [x] Pas de régression - [x] TU/TI/TF rédigée - [x] TU/TI/TF OK - [ ] CHANGELOG modifié Co-authored-by: Matthieu <mtholot19@gmail.com> Reviewed-on: #8 Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import { ref } from 'vue'
|
|
import type { SidebarSection } from '~/shared/types'
|
|
|
|
const sections = ref<SidebarSection[]>([])
|
|
const disabledRoutes = ref<string[]>([])
|
|
const loaded = ref(false)
|
|
|
|
export function useSidebar() {
|
|
async function loadSidebar() {
|
|
try {
|
|
const api = useApi()
|
|
const data = await api.get<{ sections: SidebarSection[]; disabledRoutes: string[] }>(
|
|
'/sidebar',
|
|
{},
|
|
{ toast: false }
|
|
)
|
|
sections.value = data.sections ?? []
|
|
disabledRoutes.value = data.disabledRoutes ?? []
|
|
loaded.value = true
|
|
} catch {
|
|
sections.value = []
|
|
disabledRoutes.value = []
|
|
loaded.value = true
|
|
}
|
|
}
|
|
|
|
function isRouteDisabled(path: string): boolean {
|
|
return disabledRoutes.value.some(
|
|
disabled => path === disabled || path.startsWith(disabled + '/')
|
|
)
|
|
}
|
|
|
|
function resetSidebar() {
|
|
sections.value = []
|
|
disabledRoutes.value = []
|
|
loaded.value = false
|
|
}
|
|
|
|
return {
|
|
sections,
|
|
disabledRoutes,
|
|
loaded,
|
|
loadSidebar,
|
|
resetSidebar,
|
|
isRouteDisabled,
|
|
}
|
|
}
|