Update lists after click item page own/want button

This is a bit hacky, but I want to ship and I'm not in a mood for a refactor :P

Before this change, you could see a bug by doing the following:

1. Click "I own this" to own an item.
2. Click "Add a list" and add it to a list.
3. Click "I own this" to un-own the item. (This deletes it from all lists.)
4. Observe that the "Add a list" dropdown disappears.
5. Click "I own this" to own it again.
6. Observe that, before this change, the dropdown would reappear, but incorrectly say it was still in the old list. After this change, it appears with the blank "Add to list", as intended.
This commit is contained in:
Emi Matchu 2021-11-30 16:52:29 -08:00
parent 29d44c10bd
commit 6ce8a5aea2

View file

@ -144,9 +144,7 @@ function ItemPageDescription({ description, isEmbedded }) {
); );
} }
function ItemPageOwnWantButtons({ itemId }) { const ITEM_PAGE_OWN_WANT_BUTTONS_QUERY = gql`
const { loading, error, data } = useQuery(
gql`
query ItemPageOwnWantButtons($itemId: ID!) { query ItemPageOwnWantButtons($itemId: ID!) {
item(id: $itemId) { item(id: $itemId) {
id id
@ -164,9 +162,13 @@ function ItemPageOwnWantButtons({ itemId }) {
} }
} }
} }
`, `;
{ variables: { itemId }, context: { sendAuth: true } }
); function ItemPageOwnWantButtons({ itemId }) {
const { loading, error, data } = useQuery(ITEM_PAGE_OWN_WANT_BUTTONS_QUERY, {
variables: { itemId },
context: { sendAuth: true },
});
if (error) { if (error) {
return <Box color="red.400">{error.message}</Box>; return <Box color="red.400">{error.message}</Box>;
@ -423,6 +425,14 @@ function ItemPageOwnButton({ itemId, isChecked }) {
currentUserOwnsThis: true, currentUserOwnsThis: true,
}, },
}, },
// TODO: Refactor the mutation result to include closet lists
refetchQueries: [
{
query: ITEM_PAGE_OWN_WANT_BUTTONS_QUERY,
variables: { itemId },
context: { sendAuth: true },
},
],
} }
); );
@ -446,6 +456,14 @@ function ItemPageOwnButton({ itemId, isChecked }) {
currentUserOwnsThis: false, currentUserOwnsThis: false,
}, },
}, },
// TODO: Refactor the mutation result to include closet lists
refetchQueries: [
{
query: ITEM_PAGE_OWN_WANT_BUTTONS_QUERY,
variables: { itemId },
context: { sendAuth: true },
},
],
} }
); );
@ -533,6 +551,14 @@ function ItemPageWantButton({ itemId, isChecked }) {
currentUserWantsThis: true, currentUserWantsThis: true,
}, },
}, },
// TODO: Refactor the mutation result to include closet lists
refetchQueries: [
{
query: ITEM_PAGE_OWN_WANT_BUTTONS_QUERY,
variables: { itemId },
context: { sendAuth: true },
},
],
} }
); );
@ -556,6 +582,14 @@ function ItemPageWantButton({ itemId, isChecked }) {
currentUserWantsThis: false, currentUserWantsThis: false,
}, },
}, },
// TODO: Refactor the mutation result to include closet lists
refetchQueries: [
{
query: ITEM_PAGE_OWN_WANT_BUTTONS_QUERY,
variables: { itemId },
context: { sendAuth: true },
},
],
} }
); );