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
39 changes: 31 additions & 8 deletions src/pages/search/ListEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import SortButtons, { type Sort } from '@/components/molecules/SortButtons';
import type { Category, SearchResultItemRes } from '@/api/search';
import { ChipTabs, SegmentedControlTabs } from '@/components/atoms/Tabs';
import { filterByCategoryTab, type FilterCategory } from '@/utils/filterList';
import AcademicScheduleInSearch from './AcademicScheduleInSearch';
import Pagination from '@/components/molecules/common/Pagination';

export type SearchTabKey =
Expand Down Expand Up @@ -68,6 +67,15 @@ const CommunityLabel: Record<string, string> = {
FREE: '자유 게시판',
};

/** 학사일정-캘린더 제목에서 맨 앞 [학부,대학원], [학 부], [대학원] 등 추출 */
function parseCalendarTitle(title: string): { category: string; cleanTitle: string } {
const match = title.match(/^\[([^\]]+)\]\s*(.*)$/);
if (match) {
return { category: match[1].trim(), cleanTitle: (match[2] ?? '').trim() || title };
}
return { category: '', cleanTitle: title };
}

const EMPTY_MESSAGE_CLASS = ({ isLong }: { isLong: boolean }) => {
if (!isLong) {
return 'flex h-26 items-center justify-center mx-5 border-1 border-grey-10 rounded-[4px] p-5';
Expand All @@ -76,7 +84,11 @@ const EMPTY_MESSAGE_CLASS = ({ isLong }: { isLong: boolean }) => {
};

// 검색 결과 아이템 렌더링
function renderItem(item: SearchResultItemRes, tab: SearchTabKey): ReactNode {
function renderItem(
item: SearchResultItemRes,
tab: SearchTabKey,
categoryTab?: Category | string,
): ReactNode {
if (tab === '명대뉴스') {
return (
<BroadcastCard
Expand Down Expand Up @@ -118,6 +130,20 @@ function renderItem(item: SearchResultItemRes, tab: SearchTabKey): ReactNode {
/>
);
}
// 학사일정-캘린더: 제목에서 [학부,대학원] 등 추출 → category로 전달
if (tab === '학사일정' && categoryTab === 'MJU_CALENDAR') {
const { category: extractedCategory, cleanTitle } = parseCalendarTitle(item.highlightedTitle);
return (
<NoticeItem
key={item.id}
id={item.id}
category={extractedCategory || item.category}
title={cleanTitle}
date={item.date}
link={item.link}
/>
);
}
return (
<NoticeItem
key={item.id}
Expand Down Expand Up @@ -283,7 +309,7 @@ export default function ListEntry({
<div className='mt-3 flex flex-col'>
<SectionHeader
title='명대뉴스'
showMore={broadcastItems.length === 5}
showMore={broadcastItems.length === 2}
moreTo={getMorePath('명대뉴스')}
moreSearch={getMoreSearch('명대뉴스', initialContent)}
/>
Expand Down Expand Up @@ -340,12 +366,9 @@ export default function ListEntry({
)}
</div>

{/* 학사일정 카테고리일 경우 학사일정 캘린더 출력, 나머지는 필터링 한 결과 출력 */}
{/* 필터링 한 결과 출력 */}
<div className='mb-5 flex flex-col'>
{categoryTab === 'MJU_CALENDAR' && currentTab === '학사일정' && (
<AcademicScheduleInSearch />
)}
{filteredItems.map((item) => renderItem(item, currentTab))}
{filteredItems.map((item) => renderItem(item, currentTab, categoryTab))}
{filteredItems.length === 0 &&
!(categoryTab === 'MJU_CALENDAR' && currentTab === '학사일정') && (
<div className='flex flex-col items-center justify-center py-50'>
Expand Down
17 changes: 10 additions & 7 deletions src/pages/search/SearchDetailOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ export default function SearchDetail() {
* 검색 요청 function
*/
const filterByType = (content: SearchResultItemRes[], type: string) =>
content.filter((item) => item.type?.toLowerCase() === type.toLowerCase()).slice(0, 5);
content
.filter((item) => item.type?.toLowerCase() === type.toLowerCase())
.slice(0, type === 'broadcast' ? 2 : 5);

async function handleSearch(text: string) {
if (currentTab === 'ALL' || tapLabel[currentTab] === 'ALL') {
Expand All @@ -123,7 +125,8 @@ export default function SearchDetail() {
} else {
let type = tapLabel[currentTab];
if (currentTab === '학사일정' && categoryTab === 'academic') type = 'NOTICE';
const category = currentTab === '명대뉴스' ? 'all' : categoryTab;
const category =
currentTab === '명대뉴스' || categoryTab === 'MJU_CALENDAR' ? 'all' : categoryTab;
const res = await getSearchResult(text, type, category, sort, page, 10);
const items = res.content as unknown as SearchResultItemRes[];
setItems(items);
Expand Down Expand Up @@ -157,18 +160,18 @@ export default function SearchDetail() {
}
setInitialContent(keyword);
setIsAiSummaryLoading(true);
try {
await handleSearch(keyword);
} catch {
// 에러는 상위에서 처리
}
try {
await handleGetAiSummary(keyword);
} catch {
setAiSummary((prev) => ({ ...prev, summary: '', document_count: 0, sources: [] }));
} finally {
setIsAiSummaryLoading(false);
}
try {
await handleSearch(keyword);
} catch {
// 에러는 상위에서 처리
}
})();
}, [keyword, page]);

Expand Down