-
Notifications
You must be signed in to change notification settings - Fork 16
refactor: start getting rid of apiQueryClient
#2597
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 all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
622bc80
show what it looks like to get rid of apiQueryClient
david-crespo a134c36
try invalidateOptions on list options helper
david-crespo 1fba247
show what it looks like to get apiQueryClient out of more pages
david-crespo 985437b
put invalidate function on queryClient by extending class
david-crespo 8444dc1
convert a few more to see how they look
david-crespo 1540bfe
Merge main into convert-query-client-example
david-crespo ae28b8a
use the new path params types
david-crespo b3bd45f
remove invalidateOptions on paginated query thing
david-crespo 604ecf5
convert some more, actually cut some lines!
david-crespo 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
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
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
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 |
|---|---|---|
|
|
@@ -8,12 +8,7 @@ | |
| import { useForm } from 'react-hook-form' | ||
| import { useNavigate, type LoaderFunctionArgs } from 'react-router-dom' | ||
|
|
||
| import { | ||
| apiQueryClient, | ||
| useApiMutation, | ||
| useApiQueryClient, | ||
| usePrefetchedApiQuery, | ||
| } from '@oxide/api' | ||
| import { apiq, queryClient, useApiMutation, usePrefetchedQuery } from '@oxide/api' | ||
|
|
||
| import { DescriptionField } from '~/components/form/fields/DescriptionField' | ||
| import { NameField } from '~/components/form/fields/NameField' | ||
|
|
@@ -22,30 +17,32 @@ import { HL } from '~/components/HL' | |
| import { getProjectSelector, useProjectSelector } from '~/hooks/use-params' | ||
| import { addToast } from '~/stores/toast' | ||
| import { pb } from '~/util/path-builder' | ||
| import type * as PP from '~/util/path-params' | ||
|
|
||
| const projectView = ({ project }: PP.Project) => apiq('projectView', { path: { project } }) | ||
|
|
||
| EditProjectSideModalForm.loader = async ({ params }: LoaderFunctionArgs) => { | ||
| const { project } = getProjectSelector(params) | ||
| await apiQueryClient.prefetchQuery('projectView', { path: { project } }) | ||
| await queryClient.prefetchQuery(projectView({ project })) | ||
| return null | ||
| } | ||
|
|
||
| export function EditProjectSideModalForm() { | ||
| const queryClient = useApiQueryClient() | ||
| const navigate = useNavigate() | ||
|
|
||
| const projectSelector = useProjectSelector() | ||
|
|
||
| const onDismiss = () => navigate(pb.projects()) | ||
|
|
||
| const { data: project } = usePrefetchedApiQuery('projectView', { path: projectSelector }) | ||
| const { data: project } = usePrefetchedQuery(projectView(projectSelector)) | ||
|
|
||
| const editProject = useApiMutation('projectUpdate', { | ||
| onSuccess(project) { | ||
| // refetch list of projects in sidebar | ||
| // TODO: check this invalidation | ||
| queryClient.invalidateQueries('projectList') | ||
| queryClient.invalidateEndpoint('projectList') | ||
| // avoid the project fetch when the project page loads since we have the data | ||
| queryClient.setQueryData('projectView', { path: { project: project.name } }, project) | ||
| const { queryKey } = projectView({ project: project.name }) | ||
| queryClient.setQueryData(queryKey, project) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is kind of cool. Even though it's two lines, it's much more explicit about what's going on. |
||
| addToast(<>Project <HL>{project.name}</HL> updated</>) // prettier-ignore | ||
| onDismiss() | ||
| }, | ||
|
|
||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
This approach feels good, much better than a separate
invalidatefunction (which I tried in 622bc80) or a separateapiQueryClient, like we have now. I like that it adds a new method and does not touch existing methods.