Skip to content

Commit 43f9d89

Browse files
committed
PEER-219: Add question details attempts view
Signed-off-by: SeeuSim <[email protected]>
1 parent e71340c commit 43f9d89

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

frontend/src/components/blocks/interview/question-attempts/main.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useInfiniteQuery } from '@tanstack/react-query';
22
import React, { useEffect, useMemo } from 'react';
33

44
import { CardContent } from '@/components/ui/card';
5+
import { cn } from '@/lib/utils';
56
import { getQuestionAttempts } from '@/services/question-service';
67
import { useAuthedRoute } from '@/stores/auth-store';
78
import { IPostGetQuestionAttemptsResponse } from '@/types/question-types';
@@ -11,9 +12,15 @@ import { QuestionAttemptsTable } from './table';
1112

1213
type QuestionAttemptsProps = {
1314
questionId: number;
15+
pageSize?: number;
16+
className?: string;
1417
};
1518

16-
export const QuestionAttemptsPane: React.FC<QuestionAttemptsProps> = ({ questionId }) => {
19+
export const QuestionAttemptsPane: React.FC<QuestionAttemptsProps> = ({
20+
questionId,
21+
pageSize,
22+
className,
23+
}) => {
1724
const { userId } = useAuthedRoute();
1825
const { data, hasNextPage, isFetchingNextPage, fetchNextPage, isError } = useInfiniteQuery({
1926
queryKey: ['question', 'attempts', questionId, userId],
@@ -33,8 +40,13 @@ export const QuestionAttemptsPane: React.FC<QuestionAttemptsProps> = ({ question
3340
return data?.pages.flatMap((v) => v as IPostGetQuestionAttemptsResponse) ?? [];
3441
}, [data]);
3542
return (
36-
<CardContent className='flex size-full p-0'>
37-
<QuestionAttemptsTable columns={columns} data={attempts} isError={isError} />
43+
<CardContent className={cn('flex h-full w-full p-0', className)}>
44+
<QuestionAttemptsTable
45+
columns={columns}
46+
data={attempts}
47+
isError={isError}
48+
pageSize={pageSize}
49+
/>
3850
</CardContent>
3951
);
4052
};

frontend/src/components/blocks/interview/question-attempts/table.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,18 @@ interface QuestionTableProps<TData, TValue> {
3636
columns: Array<ColumnDef<TData, TValue>>;
3737
data: Array<TData>;
3838
isError: boolean;
39+
pageSize?: number;
3940
}
4041

4142
export function QuestionAttemptsTable<TValue>({
4243
columns,
4344
data,
4445
isError,
46+
pageSize,
4547
}: QuestionTableProps<IQuestionAttempt, TValue>) {
4648
const [pagination, setPagination] = useState({
4749
pageIndex: 0,
48-
pageSize: 10,
50+
pageSize: pageSize ?? 10,
4951
});
5052

5153
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([]);

frontend/src/routes/questions/details/main.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useMemo } from 'react';
33
import { LoaderFunctionArgs, useLoaderData } from 'react-router-dom';
44

55
import { WithNavBanner } from '@/components/blocks/authed';
6+
import { QuestionAttemptsPane } from '@/components/blocks/interview/question-attempts';
67
import { QuestionDetails } from '@/components/blocks/questions/details';
78
import { Card } from '@/components/ui/card';
89
import { usePageTitle } from '@/lib/hooks';
@@ -35,7 +36,12 @@ export const QuestionDetailsPage = () => {
3536
<Card className='border-border m-4 w-1/3 max-w-[500px] overflow-hidden p-4 md:w-2/5'>
3637
<QuestionDetails questionDetails={questionDetails} />
3738
</Card>
38-
<div className='flex flex-1 flex-col' />
39+
<div className='flex flex-1 flex-col'>
40+
<Card className='border-border m-4 flex h-[calc(100%-32px)] flex-col gap-2 p-6'>
41+
<h1 className='text-xl font-semibold'>Attempts</h1>
42+
<QuestionAttemptsPane questionId={questionId} className='h-[calc(100%-40px)]' />
43+
</Card>
44+
</div>
3945
</div>
4046
</WithNavBanner>
4147
);

0 commit comments

Comments
 (0)