-
Notifications
You must be signed in to change notification settings - Fork 943
fix: create and read workspace page #1294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
386a2d7
Change name of existing workspace call
presleyp c4c4b3c
Add new api call (has handler already)
presleyp 7e3db42
WorkspacesPage -> WorkspacePage
presleyp f46c970
starting to replace swr
presleyp 74a5d1d
Add other api calls
presleyp b0e4b5a
Fix api call
presleyp 495aba6
Replace swr with xstate
presleyp 14be28e
Format
presleyp fc98515
Test - wip
presleyp c0ad87b
Fix route in template page
presleyp 60532a8
Fix endpoint in create workspace
presleyp cfac4c2
Fix tests
presleyp 78f1708
Lint
presleyp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Replace swr with xstate
- Loading branch information
commit 495aba680e81f3daec3cebff47e1d5be6f84207e
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,42 @@ | ||
import React from "react" | ||
import { useActor } from "@xstate/react" | ||
import React, { useContext, useEffect } from "react" | ||
import { useParams } from "react-router-dom" | ||
import * as Types from "../../api/types" | ||
import { ErrorSummary } from "../../components/ErrorSummary/ErrorSummary" | ||
import { FullScreenLoader } from "../../components/Loader/FullScreenLoader" | ||
import { Margins } from "../../components/Margins/Margins" | ||
import { Stack } from "../../components/Stack/Stack" | ||
import { Workspace } from "../../components/Workspace/Workspace" | ||
import { firstOrItem } from "../../util/array" | ||
import { XServiceContext } from "../../xServices/StateContext" | ||
|
||
|
||
export const WorkspacePage: React.FC = () => { | ||
const { workspace: workspaceQueryParam } = useParams() | ||
const workspaceParam = firstOrItem(workspaceQueryParam, null) | ||
const workspaceId = firstOrItem(workspaceQueryParam, null) | ||
|
||
const [workspaceState, workspaceSend] = useActor(workspaceXService) | ||
const xServices = useContext(XServiceContext) | ||
const [workspaceState, workspaceSend] = useActor(xServices.workspaceXService) | ||
const { workspace, template, organization, getWorkspaceError, getTemplateError, getOrganizationError } = workspaceState.context | ||
|
||
if (state.matches('error')) { | ||
return <ErrorSummary error={getWorkspaceError || getTemplateError || getOrganizationError } /> | ||
} | ||
/** | ||
* Get workspace, template, and organization on mount and whenever workspaceId changes. | ||
* workspaceSend should not change. | ||
*/ | ||
useEffect(() => { | ||
workspaceId && workspaceSend({ type: "GET_WORKSPACE", workspaceId }) | ||
}, [workspaceId, workspaceSend]) | ||
|
||
if (!workspace || !template || !organization) { | ||
if (workspaceState.matches('error')) { | ||
return <ErrorSummary error={getWorkspaceError || getTemplateError || getOrganizationError } /> | ||
} else if (!workspace || !template || !organization) { | ||
return <FullScreenLoader /> | ||
} else { | ||
return ( | ||
<Margins> | ||
<Stack spacing={4}> | ||
<Workspace organization={organization} template={template} workspace={workspace} /> | ||
</Stack> | ||
</Margins> | ||
) | ||
} | ||
|
||
return ( | ||
<Margins> | ||
<Stack spacing={4}> | ||
<Workspace organization={organization} template={template} workspace={workspace} /> | ||
</Stack> | ||
</Margins> | ||
) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, this uses a global XState service. Would
useMachine
be more appropriate here since the machine should only be active for the lifecycle of this page?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking it would be active for longer but maybe that's not actually desired since it's for a specific workspace. I can make it local for now and
useMachine
and we can hoist it later if needed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neato neato
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kylecarbs Actually I think we'll want it to outlive the component because we're using separate pages for things like the create/edit form and the parts of the timeline. Does that sound right?