11import { useNavigate } from "react-router-dom" ;
2+ import { FaThumbtack } from "react-icons/fa" ;
23
34interface Column {
45 label : string ;
56 value : string ;
7+ size : string ;
68}
79
8- interface AboutTableProps < T > {
10+ interface AboutTableProps < T extends object > {
911 columns : Column [ ] ;
1012 data : T [ ] ;
13+ moveToDetail : ( row : T ) => void ;
1114}
1215
13- export const AboutTable = < T extends { id : number } > ( {
16+ export const AboutTable = < T extends object > ( {
1417 columns,
1518 data,
19+ moveToDetail,
1620} : AboutTableProps < T > ) => {
17- const nav = useNavigate ( ) ;
18- const moveToDetail = ( row : T ) => {
19- nav ( `/board/notice/${ row . id } ` ) ;
20- } ;
21+
22+ // 고정된 항목과 일반 항목을 분리
23+ const pinnedItems = data . filter ( ( item : any ) => item . is_pinned ) ;
24+ const normalItems = data . filter ( ( item : any ) => ! item . is_pinned ) ;
25+
2126
2227 return (
2328 < div className = "w-full overflow-x-auto" >
2429 < table className = "w-full border-collapse border-black/50" >
30+ < colgroup >
31+ { columns . map ( ( column , index ) => (
32+ < col style = { { width : column . size } } key = { column . value + "_col_" + index } />
33+ ) ) }
34+ </ colgroup >
35+
2536 < thead className = "bg-white text-lg font-medium text-[#343434]" >
2637 < tr className = "border-b border-black/50" >
2738 { columns . map ( ( column , index ) => (
@@ -35,9 +46,27 @@ export const AboutTable = <T extends { id: number }>({
3546 </ tr >
3647 </ thead >
3748 < tbody className = "bg-white" >
38- { data . map ( ( row , rowIndex ) => (
49+ { /* 고정된 항목 먼저 표시 */ }
50+ { pinnedItems . map ( ( row , rowIndex ) => (
51+ < tr
52+ key = { `pinned-${ rowIndex } ` }
53+ className = "border-b border-black/20 hover:cursor-pointer bg-gray-50"
54+ onClick = { ( ) => moveToDetail ( row ) }
55+ >
56+ { columns . map ( ( column , index ) => (
57+ < td
58+ key = { index }
59+ className = "p-[9px] text-left text-lg font-normal text-[#343434]"
60+ >
61+ { column . value === "pin" ? < FaThumbtack className = "text-hellopy-purple-200" /> : String ( row [ column . value as keyof T ] ?? "-" ) }
62+ </ td >
63+ ) ) }
64+ </ tr >
65+ ) ) }
66+ { /* 일반 항목 표시 */ }
67+ { normalItems . map ( ( row , rowIndex ) => (
3968 < tr
40- key = { rowIndex }
69+ key = { `normal- ${ rowIndex } ` }
4170 className = "border-b border-black/20 hover:cursor-pointer"
4271 onClick = { ( ) => moveToDetail ( row ) }
4372 >
0 commit comments