Stop adding extras to Your Outfits after save
This commit is contained in:
parent
e7ad4dc39e
commit
e63c4ea68f
1 changed files with 9 additions and 1 deletions
|
@ -99,7 +99,14 @@ function useOutfitSaving(outfitState, dispatchToOutfit) {
|
||||||
cache.modify({
|
cache.modify({
|
||||||
id: cache.identify(outfit.creator),
|
id: cache.identify(outfit.creator),
|
||||||
fields: {
|
fields: {
|
||||||
outfits: (existingOutfitRefs = []) => {
|
outfits: (existingOutfitRefs = [], { readField }) => {
|
||||||
|
const isAlreadyInList = existingOutfitRefs.some(
|
||||||
|
(ref) => readField("id", ref) === outfit.id
|
||||||
|
);
|
||||||
|
if (isAlreadyInList) {
|
||||||
|
return existingOutfitRefs;
|
||||||
|
}
|
||||||
|
|
||||||
const newOutfitRef = cache.writeFragment({
|
const newOutfitRef = cache.writeFragment({
|
||||||
data: outfit,
|
data: outfit,
|
||||||
fragment: gql`
|
fragment: gql`
|
||||||
|
@ -108,6 +115,7 @@ function useOutfitSaving(outfitState, dispatchToOutfit) {
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
});
|
});
|
||||||
|
|
||||||
return [...existingOutfitRefs, newOutfitRef];
|
return [...existingOutfitRefs, newOutfitRef];
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue