Skip to content

Commit

Permalink
Improve/app/workspace switcher (#263)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
adambarito authored Dec 17, 2024
1 parent 0c97b0f commit 6b34707
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/lib/hooks/use-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export function useSetWorkspace({ onBeginSet }: { onBeginSet?: () => void }) {

onBeginSet?.();

if (currentWorkspace.handle === workspace.handle) return;

if (currentPath?.endsWith('carts')) {
apiUtils.cartFunnel.byWorkspace.setInfiniteData(
{ handle: workspace.handle },
Expand Down Expand Up @@ -311,13 +313,12 @@ export function useSetWorkspace({ onBeginSet }: { onBeginSet?: () => void }) {
await apiUtils.track.byWorkspace.invalidate();
}

if (currentWorkspace.handle === workspace.handle) return;
if (currentPath) {
router.push(currentPath.replace(currentWorkspace.handle, workspace.handle));
// return console.log('pushed @', Date.now());
return router.push(
currentPath.replace(currentWorkspace.handle, workspace.handle),
);
}
router.push(`/${workspace.handle}`);
// console.log('pushed @', Date.now());
},
[apiUtils, currentPath, currentWorkspace, router, onBeginSet],
);
Expand Down

0 comments on commit 6b34707

Please sign in to comment.