Skip to content

Commit

Permalink
feat: pick up the URL variables at the start of the app
Browse files Browse the repository at this point in the history
* chore: fix review comments
  • Loading branch information
FabienArcellier committed Sep 14, 2024
1 parent 98ae885 commit 7d3bdb9
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/ui/src/components/core/root/CoreRoot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default {
},
events: {
"wf-app-open": {
desc: "Captures the first application load, capture the page key and route vars.",
desc: "Captures the first application load, including page key and route vars.",
stub: wfAppOpenStub,
},
"wf-hashchange": {
Expand Down Expand Up @@ -135,12 +135,12 @@ watch(activePageId, (newPageId) => {
changePageInHash(pageKey);
});
type UrlParams = {
type UrlHashParams = {
pageKey?: string;
routeVars: Record<string, string>;
};
function getUrlParams(): UrlParams {
function getUrlHashParams(): UrlHashParams {
const docHash = document.location.hash.substring(1);
const hashMatchGroups = docHash.match(hashRegex)?.groups;
let pageKey: string;
Expand All @@ -165,7 +165,7 @@ function getUrlParams(): UrlParams {
return { pageKey, routeVars };
}
function setHash(urlParams: UrlParams) {
function setHash(urlParams: UrlHashParams) {
const { pageKey, routeVars } = urlParams;
let hash = "";
Expand All @@ -190,35 +190,35 @@ function setHash(urlParams: UrlParams) {
}
function changePageInHash(targetPageKey: string) {
const urlParams = getUrlParams();
urlParams.pageKey = targetPageKey;
setHash(urlParams);
const urlHashParams = getUrlHashParams();
urlHashParams.pageKey = targetPageKey;
setHash(urlHashParams);
}
function changeRouteVarsInHash(targetRouteVars: Record<string, string>) {
const parsedHash = getUrlParams();
const routeVars = parsedHash?.routeVars ?? {};
parsedHash.routeVars = { ...routeVars, ...targetRouteVars };
setHash(parsedHash);
const urlHashParams = getUrlHashParams();
const routeVars = urlHashParams?.routeVars ?? {};
urlHashParams.routeVars = { ...routeVars, ...targetRouteVars };
setHash(urlHashParams);
}
function handleHashChange() {
const urlParams = getUrlParams();
const urlHashParams = getUrlHashParams();
const event = new CustomEvent("wf-hashchange", {
detail: {
payload: urlParams,
payload: urlHashParams,
},
});
rootEl.value?.dispatchEvent(event);
if (!urlParams.pageKey) return;
wf.setActivePageFromKey(urlParams.pageKey);
if (!urlHashParams.pageKey) return;
wf.setActivePageFromKey(urlHashParams.pageKey);
}
function handleAppOpenChange() {
const urlParams = getUrlParams();
const urlHashParams = getUrlHashParams();
const event = new CustomEvent("wf-app-open", {
detail: {
payload: urlParams,
payload: urlHashParams,
},
});
rootEl.value?.dispatchEvent(event);
Expand Down

0 comments on commit 7d3bdb9

Please sign in to comment.