rerefactor du fetching de contenus une mielleure ux au load des modales (description dans le readme)
This commit is contained in:
@@ -1,23 +1,27 @@
|
||||
import { setActiveNavItem } from "./set-active-nav-item";
|
||||
import { useContentStore } from "../stores/content";
|
||||
import { useMapStore } from "../stores/map";
|
||||
import { useLayoutStore } from '../stores/layout';
|
||||
|
||||
export async function initFirstLoadRouting(store, router, baseUrl, siteName) {
|
||||
export async function initFirstLoadRouting(router, baseUrl, siteName) {
|
||||
const store = useContentStore();
|
||||
const decoupled_origin = JSON.parse(window.localStorage.getItem('decoupled_origin'));
|
||||
|
||||
if(decoupled_origin) {
|
||||
router.push(decoupled_origin.url);
|
||||
await store.fetchContentData(baseUrl + decoupled_origin.url);
|
||||
await store.fetchPartialContentData(baseUrl + decoupled_origin.url);
|
||||
window.localStorage.removeItem("decoupled_origin");
|
||||
document.title = store.pageTitle;
|
||||
setActiveNavItem(store.contentType, decoupled_origin.url);
|
||||
useLayoutStore().setHeaderPosition(false);
|
||||
await store.fetchFullContentData(baseUrl + decoupled_origin.url);
|
||||
} else {
|
||||
document.title = siteName;
|
||||
useLayoutStore().setHeaderPosition(true);
|
||||
}
|
||||
}
|
||||
|
||||
export function handleClickableElements(clickableElements, store, router, baseUrl, siteName, mapStore) {
|
||||
export function handleClickableElements(clickableElements, router, baseUrl, siteName) {
|
||||
for (const link of clickableElements) {
|
||||
let href = link.href || link.dataset.href;
|
||||
if (href.startsWith(baseUrl)) href = href.replace(baseUrl, '');
|
||||
@@ -25,26 +29,29 @@ export function handleClickableElements(clickableElements, store, router, baseUr
|
||||
link.onclick = async function (e) {
|
||||
if (href !== window.location.pathname) {
|
||||
router.push(href);
|
||||
pageChange(href, store, siteName, mapStore, baseUrl);
|
||||
pageChange(href, siteName, baseUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function handleBrowserNavigation(store, baseUrl, siteName, mapStore) {
|
||||
let href = window.location.pathname;
|
||||
if (href.startsWith(baseUrl)) href = href.replace(baseUrl, '');
|
||||
pageChange(href, store, siteName, mapStore, baseUrl)
|
||||
export async function handleBrowserNavigation(baseUrl, siteName) {
|
||||
let href = window.location.pathname;
|
||||
if (href.startsWith(baseUrl)) href = href.replace(baseUrl, '');
|
||||
pageChange(href, siteName, baseUrl)
|
||||
}
|
||||
|
||||
export async function pageChange(href, store, siteName, mapStore, baseUrl) {
|
||||
export async function pageChange(href, siteName, baseUrl) {
|
||||
const store = useContentStore();
|
||||
const mapStore = useMapStore();
|
||||
|
||||
if (href === '/') {
|
||||
store.resetStore(true);
|
||||
document.title = siteName;
|
||||
mapStore.resetMap();
|
||||
useLayoutStore().setHeaderPosition(true);
|
||||
} else {
|
||||
await store.fetchContentData(baseUrl + href);
|
||||
await store.fetchPartialContentData(baseUrl + href);
|
||||
document.title = store.pageTitle;
|
||||
useLayoutStore().setHeaderPosition(false);
|
||||
}
|
||||
@@ -53,4 +60,8 @@ export async function pageChange(href, store, siteName, mapStore, baseUrl) {
|
||||
const listeEtape = document.querySelector('#etapes-liste');
|
||||
const animationToggle = document.querySelector('#animation-toggle');
|
||||
if (!useLayoutStore().isDesktop) useLayoutStore().collapseEtapeListe(listeEtape, animationToggle);
|
||||
|
||||
if (href !== '/') {
|
||||
await store.fetchFullContentData(baseUrl + href);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user