From 2b969f64d07c625971acbd2842c7d69142ab1682 Mon Sep 17 00:00:00 2001 From: 6-keem <6ukeem@gmail.com> Date: Sun, 15 Mar 2026 23:16:18 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EA=B3=BC=EC=A0=9C/=ED=80=B4=EC=A6=88=20?= =?UTF-8?q?=EC=A0=95=EB=A0=AC=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?(=EB=AF=B8=EC=A0=9C=EC=B6=9C=20=EC=9A=B0=EC=84=A0,=20=EB=A7=88?= =?UTF-8?q?=EA=B0=90=20=EB=B9=A0=EB=A5=B8=20=EC=88=9C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 과제: 미제출 우선 배치 후 마감 빠른 순 정렬 - 퀴즈: 마감 빠른 순 정렬 (제출 여부 데이터 없음) - filterData의 filterAssigns에서 제출된 항목이 먼저 오던 버그 수정 --- src/lib/filterData.tsx | 17 +++++---- src/option/components/AssignContent.tsx | 49 ++++--------------------- src/option/components/QuizContent.tsx | 30 +++------------ 3 files changed, 22 insertions(+), 74 deletions(-) diff --git a/src/lib/filterData.tsx b/src/lib/filterData.tsx index 10f820e..0c789e3 100644 --- a/src/lib/filterData.tsx +++ b/src/lib/filterData.tsx @@ -70,18 +70,19 @@ export function filterAssigns(assigns: Assign[], filters: Filters, searchTerm: s } return data.sort((a, b) => { - if (a.isSubmit !== b.isSubmit) { - return a.isSubmit ? -1 : 1; - } + // 미제출 우선 배치 + if (!a.isSubmit && b.isSubmit) return -1; + if (a.isSubmit && !b.isSubmit) return 1; switch (sortBy) { case 'title': return a.title.localeCompare(b.title); - default: - if (a.dueDate === null && b.dueDate !== null) return a.isSubmit ? -1 : 1; - if (a.dueDate !== null && b.dueDate === null) return a.isSubmit ? 1 : -1; - if (a.dueDate === null && b.dueDate === null) return 0; - return (a.dueDate ?? '').localeCompare(b.dueDate ?? ''); + default: { + const dateA = a.dueDate === null ? Number.MAX_SAFE_INTEGER : new Date(a.dueDate).getTime(); + const dateB = b.dueDate === null ? Number.MAX_SAFE_INTEGER : new Date(b.dueDate).getTime(); + if (dateA !== dateB) return dateA - dateB; + return 0; + } } }); } diff --git a/src/option/components/AssignContent.tsx b/src/option/components/AssignContent.tsx index f899e9b..2c741c0 100644 --- a/src/option/components/AssignContent.tsx +++ b/src/option/components/AssignContent.tsx @@ -5,7 +5,6 @@ import { loadDataFromStorage } from '@/lib/storage'; import AssignCard from './AssignCard'; import { ScrollArea } from '@/components/ui/scroll-area'; import thung from '@/assets/thung.png'; -import { isCurrentDateByDate } from '@/lib/utils'; export function AssignContent() { const [assignArray, setAssignArray] = useState([]); @@ -27,48 +26,16 @@ export function AssignContent() { } const sortedAssignArray = parsedData.sort((a, b) => { - const isAX = a.isSubmit; - const isBX = b.isSubmit; + // 미제출 우선 배치 + if (!a.isSubmit && b.isSubmit) return -1; + if (a.isSubmit && !b.isSubmit) return 1; - // isSubmit이 false인 항목을 우선 배치 - if (!isAX && isBX) return -1; - if (isAX && !isBX) return 1; + // 마감 빠른 순 (null은 맨 뒤) + const dateA = a.dueDate === null ? Number.MAX_SAFE_INTEGER : new Date(a.dueDate).getTime(); + const dateB = b.dueDate === null ? Number.MAX_SAFE_INTEGER : new Date(b.dueDate).getTime(); + if (dateA !== dateB) return dateA - dateB; - const isCurrentDateByDateA = isCurrentDateByDate(a.dueDate); // isCurrentDateByDate 적용 - const isCurrentDateByDateB = isCurrentDateByDate(b.dueDate); - - // isSubmit이 false일 때는 isCurrentDateByDate가 true인 항목을 먼저 배치, 그 다음 dueDate가 null인 항목 - if (!isAX) { - if (isCurrentDateByDateA && !isCurrentDateByDateB) return -1; - if (!isCurrentDateByDateA && isCurrentDateByDateB) return 1; - const isANull = a.dueDate === null; - const isBNull = b.dueDate === null; - if (isANull && !isBNull) return 1; - if (!isANull && isBNull) return -1; - } - - // isSubmit이 true일 때는 isCurrentDateByDate가 true인 항목을 먼저 배치, 그 다음 dueDate가 null인 항목 - if (isAX) { - if (isCurrentDateByDateA && !isCurrentDateByDateB) return -1; - if (!isCurrentDateByDateA && isCurrentDateByDateB) return 1; - const isANull = a.dueDate === null; - const isBNull = b.dueDate === null; - if (isANull && !isBNull) return -1; - if (!isANull && isBNull) return 1; - } - - // dueDate 기준으로 날짜 순으로 정렬 - const dateA = a.dueDate === null ? Number.MAX_SAFE_INTEGER : new Date(a.dueDate!).getTime(); - const dateB = b.dueDate === null ? Number.MAX_SAFE_INTEGER : new Date(b.dueDate!).getTime(); - - if (dateA < dateB) return -1; - if (dateA > dateB) return 1; - - // courseTitle로 기본 정렬 - if (a.courseTitle < b.courseTitle) return -1; - if (a.courseTitle > b.courseTitle) return 1; - - return 0; + return a.courseTitle.localeCompare(b.courseTitle); }); setAssignArray(sortedAssignArray); diff --git a/src/option/components/QuizContent.tsx b/src/option/components/QuizContent.tsx index 644740f..7724c9d 100644 --- a/src/option/components/QuizContent.tsx +++ b/src/option/components/QuizContent.tsx @@ -5,7 +5,6 @@ import { loadDataFromStorage } from '@/lib/storage'; import QuizCard from './QuizCard'; import { ScrollArea } from '@radix-ui/react-scroll-area'; import thung from '@/assets/thung.png'; -import { isCurrentDateByDate } from '@/lib/utils'; export function QuizContent() { const [quizArray, setQuizArray] = useState([]); @@ -27,31 +26,12 @@ export function QuizContent() { } const sortedQuizArray = parsedData.sort((a, b) => { - const isCurrentDateByDateA = isCurrentDateByDate(a.dueDate); // isCurrentDateByDate 적용 - const isCurrentDateByDateB = isCurrentDateByDate(b.dueDate); + // 마감 빠른 순 (null은 맨 뒤) + const dateA = a.dueDate === null ? Number.MAX_SAFE_INTEGER : new Date(a.dueDate).getTime(); + const dateB = b.dueDate === null ? Number.MAX_SAFE_INTEGER : new Date(b.dueDate).getTime(); + if (dateA !== dateB) return dateA - dateB; - // isCurrentDateByDate가 true인 항목을 우선 배치, 그 다음 dueDate가 null인 항목 - if (isCurrentDateByDateA && !isCurrentDateByDateB) return -1; - if (!isCurrentDateByDateA && isCurrentDateByDateB) return 1; - - const isANull = a.dueDate === null; - const isBNull = b.dueDate === null; - - if (isANull && !isBNull) return 1; // A가 null이면 B가 우선 - if (!isANull && isBNull) return -1; // B가 null이면 A가 우선 - - // dueDate 기준으로 날짜 순으로 정렬 - const dateA = isANull ? Number.MAX_SAFE_INTEGER : new Date(a.dueDate!).getTime(); - const dateB = isBNull ? Number.MAX_SAFE_INTEGER : new Date(b.dueDate!).getTime(); - - if (dateA < dateB) return -1; - if (dateA > dateB) return 1; - - // courseTitle로 기본 정렬 - if (a.courseTitle < b.courseTitle) return -1; - if (a.courseTitle > b.courseTitle) return 1; - - return 0; + return a.courseTitle.localeCompare(b.courseTitle); }); setQuizArray(sortedQuizArray);