Skip to content

Commit 683c683

Browse files
authored
fix: sort responses by updatedAt descending (#657)
1 parent e851730 commit 683c683

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

src/hooks/useResponses.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useCallback, useMemo } from 'react';
33
import { useLocalContext } from '@graasp/apps-query-client';
44
import { AppDataVisibility, Member } from '@graasp/sdk';
55

6+
import { compareDesc } from 'date-fns/compareDesc';
67
import cloneDeep from 'lodash.clonedeep';
78
import shuffle from 'lodash.shuffle';
89

@@ -85,11 +86,14 @@ const useResponses = ({
8586
({ creator, type }) =>
8687
creator?.id === accountId && type === AppDataTypes.Response,
8788
) as ResponseAppData[];
88-
return responses;
89+
return responses.sort((a, b) => compareDesc(a.updatedAt, b.updatedAt));
8990
}, [appData, accountId]);
9091

9192
const allResponses = useMemo(
92-
(): ResponseAppData[] => getResponses(appData),
93+
(): ResponseAppData[] =>
94+
getResponses(appData).sort((a, b) =>
95+
compareDesc(a.updatedAt, b.updatedAt),
96+
),
9397
[appData],
9498
);
9599

src/modules/responseEvaluation/ResponseEvaluation.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ import VoteToolbar from './VoteToolbar';
2323

2424
const ResponseEvaluation: FC = () => {
2525
const { t } = useTranslation();
26-
const { availableResponses } = useActivityContext();
26+
const { allResponses } = useActivityContext();
2727
const { currentStep } = useSteps();
2828
const evaluationType = currentStep?.evaluationType;
2929
const evaluationParameters = currentStep?.evaluationParameters ?? {};
30-
const responses = availableResponses;
30+
const responses = allResponses;
3131

3232
const { invalidateAppData, isLoading } = useAppDataContext();
3333

src/modules/results/RatingsResults.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ type RatingsResultsProps = unknown;
1212

1313
const RatingsResults: FC<RatingsResultsProps> = () => {
1414
const { allResponses } = useActivityContext();
15-
// const sortedResponses = useMemo(
16-
// () => sortResponsesByNumberOfVote(allResponses, allVotes),
17-
// [allResponses, allVotes],
18-
// );
15+
1916
return (
2017
<Stack
2118
direction="column"

0 commit comments

Comments
 (0)