Skip to content

Commit

Permalink
handle double clicking skip and also drop extra fetchcards calls
Browse files Browse the repository at this point in the history
  • Loading branch information
AstridKery committed Jun 7, 2024
1 parent 9bfac45 commit 0b26939
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
3 changes: 3 additions & 0 deletions backend/django/core/utils/utils_annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 3 additions & 6 deletions frontend/src/actions/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
});
};
Expand All @@ -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));
}
});
};
Expand All @@ -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));
}
});
};
Expand Down
14 changes: 13 additions & 1 deletion frontend/src/reducers/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 0b26939

Please sign in to comment.