Skip to content

Commit 6b34707

Browse files
authored
Improve/app/workspace switcher (#263)
* optimistically set current workspace w/ switcher - standardized infinite item context - when workspace is switched, immediately switch to existing query data for that workspace (if it exists, even if stale) or set to empty (if that query hasn't been run yet). then invalidate route. this is currently done for all {item}.byWorkspace routers - use GridSkeleton for empty placeholder if query is actively fetching * close workspace switcher before async invalidate * remove console.logs from useSetWorkspace * return early when pushing to currentPath w/ new handle - if currentWorkspace.handle === workspace.handle, return before any currentPath nonsense - accidentally lost the 'return' when deleting the console.log
1 parent 0c97b0f commit 6b34707

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

packages/lib/hooks/use-workspace.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export function useSetWorkspace({ onBeginSet }: { onBeginSet?: () => void }) {
2828

2929
onBeginSet?.();
3030

31+
if (currentWorkspace.handle === workspace.handle) return;
32+
3133
if (currentPath?.endsWith('carts')) {
3234
apiUtils.cartFunnel.byWorkspace.setInfiniteData(
3335
{ handle: workspace.handle },
@@ -311,13 +313,12 @@ export function useSetWorkspace({ onBeginSet }: { onBeginSet?: () => void }) {
311313
await apiUtils.track.byWorkspace.invalidate();
312314
}
313315

314-
if (currentWorkspace.handle === workspace.handle) return;
315316
if (currentPath) {
316-
router.push(currentPath.replace(currentWorkspace.handle, workspace.handle));
317-
// return console.log('pushed @', Date.now());
317+
return router.push(
318+
currentPath.replace(currentWorkspace.handle, workspace.handle),
319+
);
318320
}
319321
router.push(`/${workspace.handle}`);
320-
// console.log('pushed @', Date.now());
321322
},
322323
[apiUtils, currentPath, currentWorkspace, router, onBeginSet],
323324
);

0 commit comments

Comments
 (0)