From 444887b64f17eed61eced161da01082ef90e0c04 Mon Sep 17 00:00:00 2001 From: Matchu Date: Sat, 24 Oct 2020 01:35:37 -0700 Subject: [PATCH] update trade list matching after changing own/want That is, if you're browsing a trade list and you go "oh actually, I _do_ want that!", and click the item page to mark it, then click Back, we'll now update the matching stuff on the trade list page to reflect that it's now a match. This was just a matter of simplifying the GraphQL query, I think the `currentUserOwnsThis` and `currentUserWantsThis` fields just didn't exist at the time? We _don't_ yet update your _own_ trade list, if you click through to an item to remove it or something like that. The cache update function isn't too tricky, but it's a bit verbose to implement in Apollo, so I'm not bothering right now! --- src/app/UserItemsPage.js | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/src/app/UserItemsPage.js b/src/app/UserItemsPage.js index c36c24e9..4e89285a 100644 --- a/src/app/UserItemsPage.js +++ b/src/app/UserItemsPage.js @@ -37,6 +37,7 @@ function UserItemsPage() { isNc name thumbnailUrl + currentUserWantsThis allOccupiedZones { id label @client @@ -48,22 +49,13 @@ function UserItemsPage() { isNc name thumbnailUrl + currentUserOwnsThis allOccupiedZones { id label @client } } } - - currentUser { - itemsTheyOwn { - id - } - - itemsTheyWant { - id - } - } } `, { variables: { userId } } @@ -81,20 +73,13 @@ function UserItemsPage() { return {error.message}; } - const itemIdsYouOwn = new Set( - data.currentUser?.itemsTheyOwn.map((i) => i.id) || [] - ); - const itemIdsYouWant = new Set( - data.currentUser?.itemsTheyWant.map((i) => i.id) || [] - ); - // This helps you compare your owns/wants to other users! If they own // something, and you want it, we say "You want this!". And if they want // something, and you own it, we say "You own this!". const showYouOwnThisBadge = (item) => - !isCurrentUser && itemIdsYouOwn.has(item.id); + !isCurrentUser && item.currentUserOwnsThis; const showYouWantThisBadge = (item) => - !isCurrentUser && itemIdsYouWant.has(item.id); + !isCurrentUser && item.currentUserWantsThis; const numYouOwnThisBadges = data.user.itemsTheyWant.filter( showYouOwnThisBadge