fix dashboard again

pull/106/head
dperolio 2 years ago
parent f0c90b5100
commit 49e456dc6a
No known key found for this signature in database
GPG Key ID: 4191689562D51409

@ -22,8 +22,8 @@ export default class Router extends Builtin {
await this.patchViews(); await this.patchViews();
await this.patchSidebar(); await this.patchSidebar();
await this.forceRouterUpdate(); await this.forceRouterUpdate();
vizality.api.routes.on(Events.VIZALITY_ROUTE_ADD, this.forceRouterUpdate); $vz.api.routes.on(Events.VIZALITY_ROUTE_ADD, this.forceRouterUpdate);
vizality.api.routes.on('routeRemove', this.forceRouterUpdate); $vz.api.routes.on('routeRemove', this.forceRouterUpdate);
} }
/** /**
@ -31,8 +31,8 @@ export default class Router extends Builtin {
* @returns {void} * @returns {void}
*/ */
stop () { stop () {
vizality.api.routes.off(Events.VIZALITY_ROUTE_ADD, this.forceRouterUpdate); $vz.api.routes.off(Events.VIZALITY_ROUTE_ADD, this.forceRouterUpdate);
vizality.api.routes.off('routeRemove', this.forceRouterUpdate); $vz.api.routes.off('routeRemove', this.forceRouterUpdate);
unpatch('vz-router-routes'); unpatch('vz-router-routes');
unpatch('vz-router-views'); unpatch('vz-router-views');
unpatch('vz-router-sidebar'); unpatch('vz-router-sidebar');
@ -50,7 +50,7 @@ export default class Router extends Builtin {
try { try {
const { children } = findInReactTree(res, m => isArray(m.children) && m.children.length > 5); const { children } = findInReactTree(res, m => isArray(m.children) && m.children.length > 5);
children.push( children.push(
...vizality.api.routes.getAllRoutes()?.map(route => ({ ...$vz.api.routes.getAllRoutes()?.map(route => ({
...children[0], ...children[0],
props: { props: {
/** /**
@ -84,10 +84,10 @@ export default class Router extends Builtin {
if (!isArray(routes)) { if (!isArray(routes)) {
return; return;
} }
routes[routes.length - 1].props.path = [ routes[routes.length - 2].props.path = [
...new Set( ...new Set(
routes[routes.length - 1]?.props?.path?.concat( routes[routes.length - 2]?.props?.path?.concat(
vizality.api.routes.getAllRoutes()?.map(route => `/vizality${route.path}`) $vz.api.routes.getAllRoutes()?.map(route => `/vizality${route.path}`)
) )
) )
]; ];
@ -126,14 +126,14 @@ export default class Router extends Builtin {
* Add listeners for route changes and addon settings toggle actions. * Add listeners for route changes and addon settings toggle actions.
*/ */
useEffect(() => { useEffect(() => {
vizality.api.settings $vz.api.settings
.on(Events.VIZALITY_SETTING_UPDATE, handleSidebarCollapse); .on(Events.VIZALITY_SETTING_UPDATE, handleSidebarCollapse);
Routes.listeners.add(forceUpdate); Routes.listeners.add(forceUpdate);
/** /**
* Remove the listeners on unmount. * Remove the listeners on unmount.
*/ */
return () => { return () => {
vizality.api.settings $vz.api.settings
.removeListener(Events.VIZALITY_SETTING_UPDATE, handleSidebarCollapse); .removeListener(Events.VIZALITY_SETTING_UPDATE, handleSidebarCollapse);
Routes.listeners.delete(forceUpdate); Routes.listeners.delete(forceUpdate);
}; };
@ -145,15 +145,15 @@ export default class Router extends Builtin {
child.type = props => { child.type = props => {
try { try {
let ret = Reflect.apply(oType, null, [ props ]); let ret = Reflect.apply(oType, null, [ props ]);
if (vizality.api.routes.getLocation()?.pathname?.startsWith('/vizality')) { if ($vz.api.routes.getLocation()?.pathname?.startsWith('/vizality')) {
/** /**
* Add and remove collapsed and expanded attributes based on the setting. * Add and remove collapsed and expanded attributes based on the setting.
*/ */
ret.props.className = joinClassNames('vz-dashboard-sidebar', ret.props.className); ret.props.className = joinClassNames('vz-dashboard-sidebar', ret.props.className);
ret.props['vz-collapsed'] = vizality.settings.get('dashboardSidebarCollapse', false) && ''; ret.props['vz-collapsed'] = $vz.settings.get('dashboardSidebarCollapse', false) && '';
ret.props['vz-expanded'] = !vizality.settings.get('dashboardSidebarCollapse', false) && ''; ret.props['vz-expanded'] = !$vz.settings.get('dashboardSidebarCollapse', false) && '';
const rawPath = vizality.api.routes.getLocation().pathname.substring('vizality/'.length); const rawPath = $vz.api.routes.getLocation().pathname.substring('vizality/'.length);
const route = vizality.api.routes.getAllRoutes()?.find(rte => rawPath.startsWith(rte.path)); const route = $vz.api.routes.getAllRoutes()?.find(rte => rawPath.startsWith(rte.path));
if (route && route.sidebar) { if (route && route.sidebar) {
const Sidebar = route.sidebar; const Sidebar = route.sidebar;
ret.props.children[0] = <Sidebar />; ret.props.children[0] = <Sidebar />;

Loading…
Cancel
Save