Skip to content

Commit

Permalink
fix: allow undefined memberId in publicprofile hook (#613)
Browse files Browse the repository at this point in the history
  • Loading branch information
spaenleh authored Feb 6, 2024
1 parent ad16307 commit f52d163
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/config/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ export const CURRENT_MEMBER_STORAGE_KEY = [
];

export const OWN_PUBLIC_PROFILE_KEY = ['own-profile'];
export const buildPublicProfileKey = (memberId: UUID) => ['profile', memberId];
export const buildPublicProfileKey = (memberId?: UUID) => ['profile', memberId];

export const itemsWithGeolocationKeys = {
allBounds: [ITEMS_CONTEXT, 'map'],
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/publicProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default (queryConfig: QueryClientConfig) => {
...defaultQueryOptions,
}),

usePublicProfile: (memberId: UUID) =>
usePublicProfile: (memberId?: UUID) =>
useQuery({
queryKey: buildPublicProfileKey(memberId),
queryFn: () => {
Expand Down
39 changes: 29 additions & 10 deletions src/ws/hooks/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ import { useQueryClient } from 'react-query';

import {
OWN_ITEMS_KEY,
RECYCLED_ITEMS_DATA_KEY,
RECYCLED_ITEMS_KEY,
SHARED_ITEMS_KEY,
accessibleItemsKeys,
buildItemChildrenKey,
buildItemKey,
buildLastItemValidationGroupKey,
} from '../../config/keys';
import {
copyItemsRoutine,
Expand Down Expand Up @@ -95,6 +97,8 @@ export const configureWsItemHooks = (
break;
}
case OPS.DELETE: {
// should looks for keys that should be updated or invalidated further.
// leads to seeing an error message if this item was viewed in the builder for example.
queryClient.setQueryData(itemKey, null);
break;
}
Expand All @@ -115,8 +119,8 @@ export const configureWsItemHooks = (
},

/**
* React hook to subscribe to the updates of the given item ID
* @param itemId The ID of the item of which to observe updates
* React hook to subscribe to the updates of the given item IDs
* @param itemIds The IDs of the items for which to observe updates
*/
useItemsUpdates: (itemIds?: UUID[] | null) => {
const queryClient = useQueryClient();
Expand Down Expand Up @@ -438,7 +442,7 @@ export const configureWsItemHooks = (
break;
}
default:
console.error('unhandled event for useRecyledItemsUpdates');
console.error('unhandled event for useRecycledItemsUpdates');
break;
}
}
Expand All @@ -458,6 +462,7 @@ export const configureWsItemHooks = (
* @param userId The ID of the user on which to observe item feedback updates
*/
useItemFeedbackUpdates: (userId?: UUID | null) => {
const queryClient = useQueryClient();
useEffect(() => {
if (!userId) {
return () => {
Expand All @@ -471,38 +476,52 @@ export const configureWsItemHooks = (
if (event.kind === KINDS.FEEDBACK) {
let routine: ReturnType<typeof createRoutine> | undefined;
let message: string | undefined;
const itemIds = event.resource;
switch (event.op) {
case 'update':
case OPS.UPDATE:
routine = editItemRoutine;
message = SUCCESS_MESSAGES.EDIT_ITEM;
// todo: add invalidations for queries related to an update of the itemIds specified
break;
case 'delete':
case OPS.DELETE:
routine = deleteItemsRoutine;
message = SUCCESS_MESSAGES.DELETE_ITEMS;
// invalidate data displayed in the Trash screen
queryClient.invalidateQueries(RECYCLED_ITEMS_DATA_KEY);
break;
case 'move':
case OPS.MOVE:
routine = moveItemsRoutine;
message = SUCCESS_MESSAGES.MOVE_ITEMS;
// todo: invalidate queries for the source and destination
break;
case 'copy':
case OPS.COPY:
routine = copyItemsRoutine;
message = SUCCESS_MESSAGES.COPY_ITEMS;
// todo: invalidate queries for the destination
break;
case 'export':
case OPS.EXPORT:
routine = exportItemRoutine;
message = SUCCESS_MESSAGES.DEFAULT_SUCCESS;
break;
case 'recycle':
routine = recycleItemsRoutine;
message = SUCCESS_MESSAGES.RECYCLE_ITEMS;
// todo: invalidate the queries related to the trash and to the original source

break;
case 'restore':
case OPS.RESTORE:
routine = restoreItemsRoutine;
message = SUCCESS_MESSAGES.RESTORE_ITEMS;
break;
case 'validate':
case OPS.VALIDATE:
routine = postItemValidationRoutine;
message = SUCCESS_MESSAGES.DEFAULT_SUCCESS;
// todo: invalidate the validation query to refetch the validation status
itemIds.map((itemId) =>
queryClient.invalidateQueries(
buildLastItemValidationGroupKey(itemId),
),
);
break;
default: {
console.error('unhandled event for useItemFeedbackUpdates');
Expand Down

0 comments on commit f52d163

Please sign in to comment.