From 0b26939acbae7a9b4425d19913b8c1400acb3fe3 Mon Sep 17 00:00:00 2001 From: Caroline Kery Date: Fri, 7 Jun 2024 11:10:43 -0400 Subject: [PATCH] handle double clicking skip and also drop extra fetchcards calls --- backend/django/core/utils/utils_annotate.py | 3 +++ frontend/src/actions/card.js | 9 +++------ frontend/src/reducers/card.js | 14 +++++++++++++- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/backend/django/core/utils/utils_annotate.py b/backend/django/core/utils/utils_annotate.py index 8cbe6ab3..f3982e48 100644 --- a/backend/django/core/utils/utils_annotate.py +++ b/backend/django/core/utils/utils_annotate.py @@ -169,6 +169,9 @@ def label_data(label, datum, profile, time): irr_data = datum.irr_ind with transaction.atomic(): + if DataLabel.objects.filter(data=datum,profile=profile).exists(): + return + DataLabel.objects.create( data=datum, label=label, diff --git a/frontend/src/actions/card.js b/frontend/src/actions/card.js index 9c94430d..33cfb1b9 100644 --- a/frontend/src/actions/card.js +++ b/frontend/src/actions/card.js @@ -70,13 +70,12 @@ export const annotateCard = (dataID, labelID, num_cards_left, start_time, projec dispatch(clearDeck()); return dispatch(setMessage(response.error)); } else { - dispatch(popCard()); + dispatch(popCard(dataID)); if (is_admin) { dispatch(getAdmin(projectID)); queryClient.invalidateQueries(["adminCounts", projectID]); dispatch(getLabelCounts(projectID)); } - if (num_cards_left <= 1) dispatch(fetchCards(projectID)); } }); }; @@ -101,8 +100,7 @@ export const unassignCard = (dataID, num_cards_left, is_admin, projectID) => { dispatch(clearDeck()); return dispatch(setMessage(response.error)); } else { - dispatch(popCard()); - if (num_cards_left <= 1) dispatch(fetchCards(projectID)); + dispatch(popCard(dataID)); } }); }; @@ -127,12 +125,11 @@ export const passCard = (dataID, num_cards_left, is_admin, projectID, message) = dispatch(clearDeck()); return dispatch(setMessage(response.error)); } else { - dispatch(popCard()); + dispatch(popCard(dataID)); if (is_admin) { dispatch(getAdmin(projectID)); queryClient.invalidateQueries(["adminCounts", projectID]); } - if (num_cards_left <= 1) dispatch(fetchCards(projectID)); } }); }; diff --git a/frontend/src/reducers/card.js b/frontend/src/reducers/card.js index e51e6d00..a0012ef6 100644 --- a/frontend/src/reducers/card.js +++ b/frontend/src/reducers/card.js @@ -10,7 +10,19 @@ const initialState = { }; const card = handleActions({ - [POP_CARD]: (state) => { + [POP_CARD]: (state, action) => { + // if the card isn't in the deck don't pop it off + // This handles double-clicking of Skip + let found_card = false; + for (let i = 0; i < state.cards.length; i++) { + if (state.cards[i].text.pk == action.payload) { + found_card = true; + } + } + if (! found_card) { + return state; + } + // Set the start time of the new top card to the current time if (state.cards.length > 1) { state.cards[1]['start_time'] = moment();