Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/lib/filterData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
});
}
Expand Down
49 changes: 8 additions & 41 deletions src/option/components/AssignContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Assign[]>([]);
Expand All @@ -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);
Expand Down
30 changes: 5 additions & 25 deletions src/option/components/QuizContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Quiz[]>([]);
Expand All @@ -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);
Expand Down
Loading