This commit is contained in:
Rizky 2024-06-22 02:56:39 -07:00
parent cce77e61db
commit 2bf2df8c62
2 changed files with 35 additions and 15 deletions

View File

@ -13,7 +13,6 @@ export const loadSession = (url_login?: string) => {
try { try {
const user = localStorage.getItem("user" + id_site); const user = localStorage.getItem("user" + id_site);
console.log(user);
if (user) { if (user) {
const raw = JSON.parse(user); const raw = JSON.parse(user);
w.user = raw.data; w.user = raw.data;

View File

@ -10,7 +10,6 @@ export const Menu: FC<MenuProp> = (props) => {
let role = props.role; let role = props.role;
role = props.on_init(); role = props.on_init();
let menu = get(imenu, role) || []; let menu = get(imenu, role) || [];
console.log(menu);
const pathname = getPathname(); const pathname = getPathname();
const local = useLocal({ const local = useLocal({
@ -59,12 +58,15 @@ export const SideBar: FC<{
depth: number; depth: number;
pm: MenuProp; pm: MenuProp;
mode: "full" | "mini"; mode: "full" | "mini";
}> = ({ data, local, depth, pm, mode }) => { }> = ({ data: _data, local, depth, pm, mode }) => {
const PassProp = pm.PassProp; const PassProp = pm.PassProp;
const data: IMenu[] = (typeof _data[0] === "string" ? [_data] : _data) as any;
return ( return (
<div <div
className={cx( className={cx(
"c-flex c-flex-col c-flex-grow c-mb-1", "c-flex c-flex-col c-flex-grow",
depth > 0 ? " c-overflow-hidden" : "" depth > 0 ? " c-overflow-hidden" : ""
)} )}
> >
@ -75,12 +77,21 @@ export const SideBar: FC<{
value: item[2], value: item[2],
}; };
const find_child = findChild(item, (e: any) => local.open.includes(e)); const find_child = findChild(item, (e: any) => local.open.includes(e));
let expand = find_child; if (find_child && !local.open.includes(item)) {
if (find_child && !local.open.includes(item)) local.open.push(item); local.open.push(item);
setTimeout(() => {
local.render();
}, 100);
}
if (typeof menu.value === "string" && getPathname() === menu.value) {
local.active = item;
}
return ( return (
<div className="w-full c-flex c-flex-col c-overflow-hidden"> <div className="w-full c-flex c-flex-col c-overflow-hidden">
<div <div
onClick={() => { onClick={async () => {
const childs = getChilds(item) || []; const childs = getChilds(item) || [];
if (local.open.includes(item)) { if (local.open.includes(item)) {
local.open = local.open.filter( local.open = local.open.filter(
@ -89,12 +100,18 @@ export const SideBar: FC<{
} else { } else {
local.open.push(item); local.open.push(item);
} }
local.active = item;
local.render(); local.render();
console.log(
"hello",
!Array.isArray(menu.value) && typeof menu.value === "string"
);
if ( if (
!Array.isArray(menu.value) && !Array.isArray(menu.value) &&
typeof menu.value === "string" typeof menu.value === "string"
) { ) {
await preload(menu.value);
console.log("preloaded", preload);
navigate(menu.value); navigate(menu.value);
} }
}} }}
@ -104,14 +121,16 @@ export const SideBar: FC<{
depth={depth || 0} depth={depth || 0}
hasChild={Array.isArray(menu.value) && mode === "full"} hasChild={Array.isArray(menu.value) && mode === "full"}
selected={local.active === item} selected={local.active === item}
expand={expand && Array.isArray(menu.value) && mode === "full"} expand={
find_child && Array.isArray(menu.value) && mode === "full"
}
mode={mode} mode={mode}
> >
{pm.child} {pm.child}
</PassProp> </PassProp>
</div> </div>
<div className="c-flex c-flex-col"> <div className="c-flex c-flex-col">
{Array.isArray(menu.value) && expand && mode === "full" ? ( {Array.isArray(menu.value) && mode === "full" ? (
<> <>
<SideBar <SideBar
data={menu.value} data={menu.value}
@ -138,10 +157,12 @@ const getChilds = (data: Array<any>) => {
const children = data[2]; // array index ke-2 bisa berupa array atau string const children = data[2]; // array index ke-2 bisa berupa array atau string
if (Array.isArray(children)) { if (Array.isArray(children)) {
for (let child of children) { for (let child of children) {
childs.push(child); if (child) {
if (Array.isArray(child[2])) { childs.push(child);
const result: any = getChilds(child); if (Array.isArray(child[2])) {
childs = childs.concat(result); const result: any = getChilds(child);
childs = childs.concat(result);
}
} }
} }
} }