Skip to content

Commit 60056b4

Browse files
Merge upstream develop
2 parents 1e87558 + 9ebc454 commit 60056b4

6 files changed

Lines changed: 134 additions & 133 deletions

File tree

apps/polycentric/src/features/follow/hooks/useFollows.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
decodeBundle,
88
type DecodedBundle,
99
} from '@/src/common/lib/polycentric-hooks/helpers';
10+
import { invalidateQuery } from '@/src/common/query/hooks/useQuery';
11+
import { feedQueryKeys } from '../../feed/hooks/feedCache';
1012
import { create } from 'zustand';
1113

1214
type FollowsState = {
@@ -45,6 +47,7 @@ const useFollows = create<FollowsState>((set, get) => ({
4547
try {
4648
await client.commitEvent(signedEvent, content);
4749
await client.sync();
50+
invalidateQuery(client, feedQueryKeys.following());
4851
} catch (err) {
4952
console.error(err);
5053
// revert the change
@@ -102,6 +105,7 @@ const useFollows = create<FollowsState>((set, get) => ({
102105

103106
if (targets.length > 0) {
104107
await client.sync();
108+
invalidateQuery(client, feedQueryKeys.following());
105109
}
106110
},
107111
/**

apps/polycentric/src/features/post/hooks/usePostActions.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { invalidateQuery } from '@/src/common/query/hooks/useQuery';
77
import { COLLECTION, v2, SyncStrategy } from '@polycentric/react-native';
88
import { router, useSegments } from 'expo-router';
99
import { feedQueryKeys } from '../../feed/hooks/feedCache';
10+
import { threadQueryKey } from './useThread';
1011

1112
type PostActions = {
1213
/**
@@ -53,6 +54,16 @@ export default function usePostActions(post: PostData): PostActions {
5354
invalidateQuery(client, feedQueryKeys.explore(identity));
5455
};
5556

57+
const invalidateThreads = (reply: PostData['reply']) => {
58+
if (!reply) return;
59+
const parents = [reply.parentId, reply.rootId].filter(
60+
(id): id is string => !!id,
61+
);
62+
for (const parentId of new Set(parents)) {
63+
invalidateQuery(client, threadQueryKey(parentId));
64+
}
65+
};
66+
5667
return {
5768
reportAsync: async () => {
5869
// TODO: discuss if we should record report events or
@@ -61,6 +72,7 @@ export default function usePostActions(post: PostData): PostActions {
6172
deleteAsync: async () => {
6273
await deleteEventAtKey(post.id);
6374
invalidateFeeds(post.identity);
75+
invalidateThreads(post.reply);
6476

6577
if (segments[0] === '[identityId]' && segments[1] === 'post') {
6678
// Redirect to profile

apps/polycentric/src/features/profile/hooks/useProfile.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,25 @@ const EMPTY_PROFILE: Omit<
3232
alias: null,
3333
};
3434

35+
/**
36+
* Shared cache key for a profile. The fetch mode is intentionally not part
37+
* of the key so every surface (feed avatars, post authors, the profile page)
38+
* reads and invalidates the same entry.
39+
*/
40+
export function profileQueryKey(
41+
identityKey: string | null | undefined,
42+
): string[] {
43+
return ['profile', identityKey ?? ''];
44+
}
45+
3546
export function useProfile(
3647
identityKey: string | null | undefined,
3748
options?: UseProfileOptions,
3849
): ProfileHookResult {
3950
const fetchMode = options?.fetchMode ?? FetchMode.OfflineOnly;
4051

4152
const query = useQuery(
42-
['profile', identityKey ?? '', fetchMode.toString()],
53+
profileQueryKey(identityKey),
4354
new Query.GetProfile({ identity: identityKey ?? '' }),
4455
{ fetchMode },
4556
!!identityKey,

apps/polycentric/src/features/profile/hooks/useProfileEdit.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
jest.mock('@polycentric/react-native', () => ({
22
resolveAlias: jest.fn(),
33
}));
4+
jest.mock('@/src/common/query/hooks/useQuery', () => ({
5+
invalidateQuery: jest.fn(),
6+
}));
47
jest.mock('../../../common/lib/polycentric-hooks/PolycentricProvider', () => ({
58
usePolycentric: () => ({}),
69
}));

apps/polycentric/src/features/profile/hooks/useProfileEdit.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { useCallback, useEffect, useState } from 'react';
22
import { resolveAlias } from '@polycentric/react-native';
33
import { usePolycentric } from '../../../common/lib/polycentric-hooks/PolycentricProvider';
4+
import { invalidateQuery } from '@/src/common/query/hooks/useQuery';
45
import { publishProfileUpdate } from '../lib/publishProfileUpdate';
6+
import { profileQueryKey } from './useProfile';
57

68
interface ProfileRef {
79
description: string | null;
810
alias: string | null;
9-
refresh: () => void;
1011
}
1112

1213
export type ProfileEditState = {
@@ -83,7 +84,7 @@ export function useProfileEdit(
8384
avatarUri,
8485
alias: aliasDraft,
8586
});
86-
profile.refresh();
87+
invalidateQuery(client, profileQueryKey(client.activeIdentityKey));
8788
setEditing(false);
8889
return true;
8990
} catch (err) {

0 commit comments

Comments
 (0)