Skip to content

Commit

Permalink
Fix navLayout
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrozadotdev committed Nov 18, 2023
1 parent ee29a62 commit 0d5fca8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
24 changes: 8 additions & 16 deletions client/packages/openblocks/src/comps/comps/layout/navLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import { registerLayoutMap } from "comps/comps/uiComp";
import { MultiCompBuilder, withDefault, withViewFn } from "comps/generators";
import { withDispatchHook } from "comps/generators/withDispatchHook";
import { NameAndExposingInfo } from "comps/utils/exposingTypes";
import { ALL_APPLICATIONS_URL } from "constants/routesURL";
import { TopHeaderHeight } from "constants/style";
import { AppPagePathParam } from "constants/applicationConstants";
import { Section } from "openblocks-design";
import { trans } from "i18n";
import { EditorContainer, EmptyContent } from "pages/common/styledComponent";
Expand Down Expand Up @@ -66,7 +64,7 @@ let NavTmpLayout = (function () {

NavTmpLayout = withViewFn(NavTmpLayout, (comp) => {
const pathParam = useAppPathParam();
const appPageId = useAppPageId();
const [appPageId, updateHash] = useAppPageId();
const isViewMode = isUserViewMode(pathParam);
const [selectedKey, setSelectedKey] = useState("");
const items = useMemo(() => comp.children.items.getView(), [comp.children.items]);
Expand Down Expand Up @@ -198,19 +196,13 @@ NavTmpLayout = withViewFn(NavTmpLayout, (comp) => {
selectedKeys={[selectedKey]}
onClick={(e) => {
const itemComp = itemKeyRecord[e.key];
const url = [
ALL_APPLICATIONS_URL,
pathParam.applicationId,
].join("/") +
(
pathParam.viewMode
? "/" + pathParam.viewMode
: ""
) +
(itemComp.getItemKey()
? `?${AppPagePathParam}=${itemComp.getItemKey()}`
: ""
);
const url = window.location.pathname +
window.location.search +
(
itemComp.getItemKey() ?
updateHash(itemComp.getItemKey()) :
""
)
itemComp.children.action.act(url);
}}
/>
Expand Down
27 changes: 25 additions & 2 deletions client/packages/openblocks/src/util/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,33 @@ export function useRedirectUrl() {
return queryParams.get(AuthSearchParams.redirectUrl);
}

function getHashObject(hash: string) {
return hash.substring(1).split('&').reduce(function (res, item) {
if(!item) return res
var parts = item.split('=');
//@ts-ignore
res[parts[0]] = parts[1];
return res;
}, {});
}

function updateAppPageId(hash:string, id: string) {
const hashObject = getHashObject(hash)
//@ts-ignore
hashObject[AppPagePathParam] = id
const result = Object.keys(hashObject).reduce(function (res, key, index) {
//@ts-ignore
return res + (index ? "&" : "") + key + "=" + hashObject[key]
}, "")
return result ? "#" + result : ""
}

export function useAppPageId() {
const location = useLocation();
const queryParams = new URLSearchParams(location.search);
return queryParams.get(AppPagePathParam) || "";
const hashObject = getHashObject(location.hash)
const appPageId = hashObject[AppPagePathParam as keyof typeof hashObject] as string || ""
const updateHash = (id: string) => updateAppPageId(location.hash, id)
return [appPageId, updateHash] as const
}

export function useFixedDelay(callback: () => Promise<unknown>, delay: number | null) {
Expand Down

0 comments on commit 0d5fca8

Please sign in to comment.