-
Notifications
You must be signed in to change notification settings - Fork 262
fix: squad post moderation list not updating #4458
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
base: main
Are you sure you want to change the base?
Changes from all commits
9eca54d
9632b9b
dcf2b7c
9fd663d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,12 +44,7 @@ export const useSquadPendingPosts = ({ | |
}, [squads]); | ||
|
||
const query = useInfiniteQuery<Connection<SourcePostModeration[]>>({ | ||
queryKey: generateQueryKey( | ||
RequestKey.SquadPostRequests, | ||
user, | ||
squadId ?? 'all', | ||
status, | ||
), | ||
queryKey: generateQueryKey(RequestKey.SquadPostRequests, user, squadId), | ||
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. It is ideal to include the params we send as part of the query key. Let's keep the status. 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 including status requires us to pass it through a lot of places where we don't currently. It works well without it, so I think its better to leave it out for now and rather implement it when needed. 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. We need to have it on all places. Otherwise, we will just have issues when we try to toggle between statuses. It is always best to have them. If we want them to ensure consistency, we can introduce a generic function - but every param should be part of the query key. |
||
queryFn: async ({ pageParam }) => { | ||
return gqlClient | ||
.request<{ | ||
|
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.
We could use only one using the
squad.id
as discriminant field. Basically we have the squad list that has a specific id and the "all" list where this id isundefined
.Have we tried to pass something like:
squad?.id ?? "all"
instead?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.
Yeah, I think the keys used are not matching with one another. It would be great if we continue the pattern Luca suggested above.
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.
We can't, because when the user is doing moderation for a single squad in for example /moderation/my-favorite-squad, when they approve/reject a post, the sidebar will not be updated because it uses a different key than the list that is being updated.
Remember, we are manually updating these in this component for optimistic updates. We need to access the keys specifically.
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.
In that case, we will need to update two keys here. One for the specific squad and one for
all
.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.
We can also just invalidate
[RequestKey.SquadPostRequests, user?.id]
that will invalidate bothThere 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 we do prefer to invalidate and refetch over manually updating then that is a possibility, yes
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.
Was thinking Lee is talking about invalidation here, my bad, if you want you can try new hooks for updating that I created after our gathering talks (they are merged already), WIP docs are https://dailydotdev.atlassian.net/wiki/spaces/HAN/pages/1556185091/Data+fetching+mutations+and+optimistic+updates+with+typed+queries
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.
Yes, invalidation works, but the point about the query keys is my main concern. The issue is that there is a mismatch with the keys used across places, which makes the invalidation of one or the other not reflect the 100% correct data. So even if we invalidate or setData, the root cause is still there as you might not hit the right cache for the related areas.
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.
From my testing, with this setup, it does indeed reflect the correct key across all places both when moderation all squads and a single one: