Skip to content

Commit fddfda1

Browse files
committed
Formatting
1 parent 4e0e64c commit fddfda1

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

site/pages/workspaces/[user]/[workspace].tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,18 @@ const WorkspacesPage: React.FC = () => {
2121

2222
const { user: userQueryParam, workspace: workspaceQueryParam } = router.query
2323

24-
const userParam = firstOrItem(userQueryParam, null)
25-
const workspaceParam = firstOrItem(workspaceQueryParam, null)
24+
const { data: workspace, error: workspaceError } = useSWR<API.Workspace, Error>(() => {
25+
const userParam = firstOrItem(userQueryParam, null)
26+
const workspaceParam = firstOrItem(workspaceQueryParam, null)
2627

27-
const { data: workspace, error: workspaceError } = useSWR<API.Workspace, Error>(() => `/api/v2/workspaces/${(userParam as any).toString()}/${(workspaceParam as any).toString()}`)
28+
// TODO: Getting non-personal users isn't supported yet in the backend.
29+
// So if the user is the same as 'me', use 'me' as the parameter
30+
const normalizedUserParam = me && userParam === me.id ? "me" : userParam
31+
32+
// The SWR API expects us to 'throw' if the query isn't ready yet, so these casts to `any` are OK
33+
// because the API expects exceptions.
34+
return `/api/v2/workspaces/${(normalizedUserParam as any).toString()}/${(workspaceParam as any).toString()}`
35+
})
2836

2937
if (workspaceError) {
3038
return <ErrorSummary error={workspaceError} />
@@ -60,4 +68,3 @@ const useStyles = makeStyles(() => ({
6068
}))
6169

6270
export default WorkspacesPage
63-

0 commit comments

Comments
 (0)