-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: pre-push 설정 추가 * @tanstack/react-table 설치 * feat: 테이블 관련 컴포넌트 설치 table, dropdwon, checkbox 추가 * feat: 테이블 관련 작업 기본 데이터 테이블 구성 난이도 필터 적용 드롭다운 적용 * feat: 검색 기능 구현 커스텀 필터 적용 * feat: 페이지네이션 기능 추가 * feat: 퀴즈 데이터 호출 타입 관련 수정 * feat: zod 적용 및 getQuizzes 호출 방식 변경 quiz 관련 스키마 정의 getQuizzes 쿼리 방식 useQuery로 변경 * refactor: 코드 정리 안쓰는 코드 제거 마크다운 관련 스타일 변경 * fix: 난이도 필터 스키마 변경 * chore: 콘솔 제거 * fix: 수정된 쿼리키 적용
- Loading branch information
Showing
17 changed files
with
1,269 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
npm run build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use client'; | ||
|
||
import { columns } from '@/components/quiz/table/columns'; | ||
import DataTable from '@/components/quiz/table/data-table'; | ||
import { useGetQuizzes } from '@/services/quiz/hooks'; | ||
|
||
export default function QuizTable() { | ||
const { data: quizzes } = useGetQuizzes(); | ||
|
||
return <div>{quizzes && <DataTable columns={columns} data={quizzes} />}</div>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
'use client'; | ||
|
||
import { Checkbox } from '@/components/ui/checkbox'; | ||
import { | ||
DropdownMenu, | ||
DropdownMenuContent, | ||
DropdownMenuTrigger, | ||
} from '@/components/ui/dropdown-menu'; | ||
import type { Quiz, QuizTable } from '@/libs/models'; | ||
import { Column, ColumnDef } from '@tanstack/react-table'; | ||
import Link from 'next/link'; | ||
|
||
export const columns: ColumnDef<QuizTable>[] = [ | ||
{ | ||
accessorKey: 'success', | ||
header: () => <div className="text-left">상태</div>, | ||
cell: ({ row }) => { | ||
const { success } = row.original; | ||
|
||
return <div>{JSON.stringify(success)}</div>; | ||
}, | ||
}, | ||
{ | ||
accessorKey: 'title', | ||
header: '제목', | ||
cell: ({ row }) => { | ||
const { title, summary, id } = row.original; | ||
|
||
return ( | ||
<div className="max-w-[13rem]"> | ||
<h3 className="truncate"> | ||
<Link className="text-base font-semibold" href={`/quizzes/${id}`}> | ||
{title} | ||
</Link> | ||
</h3> | ||
<p className="truncate text-blue-500">{summary}</p> | ||
</div> | ||
); | ||
}, | ||
/** | ||
* @description 참고 코드 | ||
* https://github.com/TanStack/table/blob/a334f66a82a9b3b0b4e99e7a0cc99ba077aaf167/packages/table-core/src/filterFns.ts#L3-L16 | ||
*/ | ||
filterFn: (row, columnId, filterValue) => { | ||
const search = filterValue.toLowerCase(); | ||
|
||
return Boolean( | ||
row.getValue<string | null>(columnId)?.toLowerCase().includes(search) | ||
); | ||
}, | ||
}, | ||
{ | ||
accessorKey: 'difficulty', | ||
header: ({ column }) => ( | ||
<DropdownMenu> | ||
<DropdownMenuTrigger className="w-full">난이도</DropdownMenuTrigger> | ||
<DropdownMenuContent> | ||
<Filter column={column} /> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
), | ||
cell: ({ row }) => { | ||
const difficulty = String(row.getValue('difficulty')); | ||
|
||
return <div className="text-center">{difficulty}</div>; | ||
}, | ||
filterFn: 'arrIncludesSome', | ||
}, | ||
]; | ||
|
||
function Filter({ column }: { column: Column<Quiz> }) { | ||
const onClickToggle = | ||
(difficulty: '하' | '중' | '상') => | ||
(e: React.MouseEvent<HTMLButtonElement>) => { | ||
if (e.currentTarget.dataset.state === 'checked') { | ||
column.setFilterValue((olds: string[]) => | ||
olds.filter((old) => old !== difficulty) | ||
); | ||
} else { | ||
column.setFilterValue((olds: string[]) => [ | ||
...(olds ?? []), | ||
difficulty, | ||
]); | ||
} | ||
}; | ||
|
||
const filterValue = (column.getFilterValue() as ['하' | '중' | '상']) ?? []; | ||
|
||
return ( | ||
<div className="flex flex-col"> | ||
<div className="flex items-center gap-2"> | ||
<Checkbox | ||
id="easy-check" | ||
checked={filterValue.includes('하')} | ||
onClick={onClickToggle('하')} | ||
/> | ||
<label htmlFor="easy-check">쉬움</label> | ||
</div> | ||
<div className="flex items-center gap-2"> | ||
<Checkbox | ||
id="medium-check" | ||
checked={filterValue.includes('중')} | ||
onClick={onClickToggle('중')} | ||
/> | ||
<label htmlFor="medium-check">보통</label> | ||
</div> | ||
<div className="flex items-center gap-2"> | ||
<Checkbox | ||
id="hard-check" | ||
checked={filterValue.includes('상')} | ||
onClick={onClickToggle('상')} | ||
/> | ||
<label htmlFor="hard-check">어려움</label> | ||
</div> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.