Skip to content

Commit f8a686e

Browse files
committed
fix: properly refresh photo state after setting primary photo
1 parent e03beb4 commit f8a686e

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

client/src/components/person/PersonDetail.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,24 @@ export function PersonDetail() {
409409
setClaims(newClaims);
410410
}, [dbId, personId]);
411411

412+
// Refresh photo state after setting a new primary photo
413+
const refreshPhotoState = useCallback(async () => {
414+
if (!personId) return;
415+
const [photoCheck, wikiPhotoCheck, ancestryPhotoCheck, wikiTreePhotoCheck, linkedInPhotoCheck] = await Promise.all([
416+
api.hasPhoto(personId).catch(() => ({ exists: false })),
417+
api.hasWikiPhoto(personId).catch(() => ({ exists: false })),
418+
api.hasAncestryPhoto(personId).catch(() => ({ exists: false })),
419+
api.hasWikiTreePhoto(personId).catch(() => ({ exists: false })),
420+
api.hasLinkedInPhoto(personId).catch(() => ({ exists: false })),
421+
]);
422+
setHasPhoto(photoCheck?.exists ?? false);
423+
setHasFsPhoto((photoCheck as { exists: boolean; fsExists?: boolean })?.fsExists ?? false);
424+
setHasWikiPhoto(wikiPhotoCheck?.exists ?? false);
425+
setHasAncestryPhoto(ancestryPhotoCheck?.exists ?? false);
426+
setHasWikiTreePhoto(wikiTreePhotoCheck?.exists ?? false);
427+
setHasLinkedInPhoto(linkedInPhotoCheck?.exists ?? false);
428+
}, [personId]);
429+
412430
const handleSavePersonField = useCallback(async (fieldName: string, value: string, originalValue: string | null) => {
413431
if (!dbId || !personId) return;
414432
await api.setPersonOverride(dbId, personId, {
@@ -1032,6 +1050,7 @@ export function PersonDetail() {
10321050
onShowUploadDialog={() => setShowUploadDialog(true)}
10331051
onShowAncestryUploadDialog={() => setShowAncestryUploadDialog(true)}
10341052
onShowLinkInput={(platform) => setLinkingPlatform(platform)}
1053+
onPhotoChanged={refreshPhotoState}
10351054
syncLoading={syncLoading}
10361055
scrapeLoading={scrapeLoading}
10371056
fetchingPhotoFrom={fetchingPhotoFrom}

client/src/components/person/ProviderDataTable.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ interface ProviderDataTableProps {
3434
onShowUploadDialog: () => void;
3535
onShowAncestryUploadDialog: () => void;
3636
onShowLinkInput: (platform: 'wikipedia' | 'ancestry' | 'wikitree' | 'linkedin') => void;
37+
onPhotoChanged?: () => void; // Called when primary photo changes to refresh parent state
3738
syncLoading: boolean;
3839
scrapeLoading: boolean;
3940
fetchingPhotoFrom: string | null;
@@ -137,6 +138,7 @@ export function ProviderDataTable({
137138
onShowUploadDialog,
138139
onShowAncestryUploadDialog,
139140
onShowLinkInput,
141+
onPhotoChanged,
140142
syncLoading,
141143
scrapeLoading,
142144
fetchingPhotoFrom,
@@ -280,8 +282,8 @@ export function ProviderDataTable({
280282

281283
if (result) {
282284
toast.success(`Set ${PROVIDER_INFO[provider]?.name || provider} photo as primary`);
283-
// Trigger photo refresh in parent component by fetching updated photo
284-
await onFetchPhoto(provider).catch(() => null);
285+
// Notify parent to refresh photo state
286+
onPhotoChanged?.();
285287
}
286288

287289
setApplyingField(null);

0 commit comments

Comments
 (0)