Skip to content

Commit

Permalink
generalise cache update
Browse files Browse the repository at this point in the history
  • Loading branch information
lukavdplas committed Sep 19, 2024
1 parent 677fbda commit 31c1f28
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import { splat, differenceBy } from "@shared/utils";
import { ToastService } from "@services/toast.service";

type EntityPropertyName = 'agents' | 'gifts' | 'letters' | 'spaces';

const REFETCH_QUERIES = ['DataEntryEpisodeEntities'];
type EntityTypeName = 'AgentDescriptionType' | 'GiftDescriptionType' | 'LetterDescriptionType' | 'SpaceDescriptionType';

let nextID = 0;

Expand Down Expand Up @@ -97,6 +96,16 @@ export class EpisodeEntitiesFormComponent implements OnChanges, OnDestroy {
return keys[this.entityType]
}

get entityTypeName(): EntityTypeName {
const types: Record<Entity, EntityTypeName> = {
[Entity.Agent]: 'AgentDescriptionType',
[Entity.Gift]: 'GiftDescriptionType',
[Entity.Letter]: 'LetterDescriptionType',
[Entity.Space]: 'SpaceDescriptionType',
}
return types[this.entityType];
}

ngOnChanges(changes: SimpleChanges): void {
if (changes['entityType']) {

Expand Down Expand Up @@ -173,7 +182,7 @@ export class EpisodeEntitiesFormComponent implements OnChanges, OnDestroy {
id: episodeID,
}));
cache.evict(cache.identify({
__typename: "AgentDescriptionType",
__typename: this.entityTypeName,
id: entityID,
}));
cache.gc();
Expand Down

0 comments on commit 31c1f28

Please sign in to comment.