refactor: workspace provider (#2218)

This commit is contained in:
Himself65
2023-05-03 18:16:22 -05:00
committed by GitHub
parent ec39c23fb7
commit 9096ac2960
18 changed files with 377 additions and 255 deletions
@@ -22,6 +22,7 @@ export function useRouterWithWorkspaceIdDefense(router: NextRouter) {
}
const exist = metadata.find(m => m.id === currentWorkspaceId);
if (!exist) {
console.warn('workspace not exist, redirect to first one');
// clean up
setCurrentWorkspaceId(null);
setCurrentPageId(null);
@@ -45,8 +45,9 @@ export function useSyncRouterWithCurrentWorkspaceId(router: NextRouter) {
window.apis?.onWorkspaceChange(targetWorkspace.id);
}
void router.push({
pathname: '/workspace/[workspaceId]/all',
pathname: router.pathname,
query: {
...router.query,
workspaceId: targetWorkspace.id,
},
});
@@ -56,8 +57,9 @@ export function useSyncRouterWithCurrentWorkspaceId(router: NextRouter) {
console.log('set workspace id', workspaceId);
setCurrentWorkspaceId(targetWorkspace.id);
void router.push({
pathname: '/workspace/[workspaceId]/all',
pathname: router.pathname,
query: {
...router.query,
workspaceId: targetWorkspace.id,
},
});