import dayjs from "dayjs"; import Image from "next/image"; import type { ColumnDef } from "@tanstack/react-table"; import { Badge, Checkbox, Skeleton, cn } from "@common/components"; import { AttachmentApi } from "@/entities/attachment"; import type { Post } from "@/entities/post"; import { useQuery } from "@tanstack/react-query"; import { ENDPOINT } from "@/shared/config"; import type { BbsType } from "@/shared/store/menu-store"; declare module "@tanstack/react-table" { // eslint-disable-next-line @typescript-eslint/no-unused-vars interface TableMeta { bbsTypeCd?: BbsType; } } export const createColumns = ( thumbRefs: React.MutableRefObject>, ): ColumnDef[] => [ { id: "select", header: ({ table }) => ( e.stopPropagation()} onCheckedChange={(checked) => table.toggleAllPageRowsSelected(!!checked) } className="h-4 w-4 rounded border-gray-300" /> ), cell: ({ row, table }) => { const { atflCd, pstNo, pstTtl, inqNocs, rgtrNm, regDt } = row.original; const bbsTypeCd = table.options.meta?.bbsTypeCd; if (bbsTypeCd === "BBSIMAGE") { return (
e.stopPropagation()} onCheckedChange={(checked) => row.toggleSelected(!!checked)} className="h-4 w-4 rounded border-gray-300" /> {inqNocs >= 100 && HOT} {dayjs().diff(dayjs(row.original.regDt), "hour") < 24 && ( NEW )} {pstTtl}
{rgtrNm} {dayjs(regDt).format("YYYY-MM-DD")}
); } if (bbsTypeCd === "BBSMOVIE") { return (
e.stopPropagation()} onCheckedChange={(checked) => row.toggleSelected(!!checked)} className="h-4 w-4 rounded border-gray-300" /> {inqNocs >= 100 && HOT} {dayjs().diff(dayjs(regDt), "hour") < 24 && ( NEW )} {pstTtl}
{rgtrNm} {dayjs(regDt).format("YYYY-MM-DD")}
); } }, }, ]; type ThumbImageProps = { atflCd: string; pstNo: number; thumbRefs: React.MutableRefObject>; bbsTypeCd?: string; classes?: { image?: string; }; }; const ThumbImage = ({ atflCd, pstNo, thumbRefs, bbsTypeCd, classes, }: ThumbImageProps) => { const prevImage = thumbRefs.current.get(pstNo); const { data: imageUrl, isLoading } = useQuery({ queryKey: [ENDPOINT.ATTACH_SERVICE.IMAGES, atflCd], queryFn: () => { if (bbsTypeCd === "BBSIMAGE") { return AttachmentApi.getImageUrlByAtflCd(atflCd); } else if (bbsTypeCd === "BBSMOVIE") { return AttachmentApi.getMovieThumbnailUrlByAtflCd(atflCd); } }, select: (url) => { if (url) thumbRefs.current.set(pstNo, url); return url; }, enabled: !prevImage && !!atflCd, }); if (isLoading) return (
); if (imageUrl) return (
썸네일 이미지
); return (
); };