diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 1cb1be756..64e749756 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -4,7 +4,7 @@ on: push: branches: - main - - refactor/academics + - feat/search jobs: build: diff --git a/apis/search.ts b/apis/search.ts index 6be38787d..d1d2ab7e1 100644 --- a/apis/search.ts +++ b/apis/search.ts @@ -10,7 +10,7 @@ import { import { getRequest } from './network/server'; -type SearchParam = { keyword: string; number: number }; +type SearchParam = { keyword: string; number: number; amount?: number }; export const searchAbout = (params: SearchParam) => getRequest('/about/search/top', params) as Promise; diff --git a/app/[locale]/search/AboutRow.tsx b/app/[locale]/search/AboutRow.tsx new file mode 100644 index 000000000..7a13c2f22 --- /dev/null +++ b/app/[locale]/search/AboutRow.tsx @@ -0,0 +1,55 @@ +import { Link } from '@/navigation'; + +import RangeBolded from '@/components/common/RangeBolded'; + +import { AboutPreview } from '@/types/search'; + +import { getPath } from '@/utils/page'; +import { + contact, + directions, + facilities, + futureCareers, + greetings, + history, + overview, + studentClubs, +} from '@/utils/segmentNode'; + +import OrangeCircle from './OrangeCircle'; + +export default function AboutRow({ preview }: { preview: AboutPreview }) { + const node = postTypeToNode(preview.aboutPostType); + + return ( + +
+ +

{node.name}

+
+ +

{`소개 > ${node.name}`}

+ + ); +} + +const postTypeToNode = (postType: AboutPreview['aboutPostType']) => { + switch (postType) { + case 'OVERVIEW': + return overview; + case 'GREETINGS': + return greetings; + case 'HISTORY': + return history; + case 'FUTURE_CAREERS': + return futureCareers; + case 'STUDENT_CLUBS': + return studentClubs; + case 'FACILITIES': + return facilities; + case 'CONTACT': + return contact; + case 'DIRECTIONS': + return directions; + } +}; diff --git a/app/[locale]/search/NoticeRow.tsx b/app/[locale]/search/NoticeRow.tsx index c105a8250..af43aa0ac 100644 --- a/app/[locale]/search/NoticeRow.tsx +++ b/app/[locale]/search/NoticeRow.tsx @@ -1,33 +1,27 @@ import { Link } from '@/navigation'; +import RangeBolded from '@/components/common/RangeBolded'; + import { getPath } from '@/utils/page'; import { notice } from '@/utils/segmentNode'; interface NoticeRowProps { id: number; title: string; - description: { - content: string; - boldStartIndex: number; - boldEndIndex: number; - }; + partialDescription: string; + boldStartIndex: number; + boldEndIndex: number; dateStr: string; } const noticePath = getPath(notice); -export default function NoticeRow({ id, title, description, dateStr }: NoticeRowProps) { +export default function NoticeRow({ id, title, dateStr, ...description }: NoticeRowProps) { const date = new Date(dateStr); return (

{title}

-

- {description.content.slice(0, description.boldStartIndex)} - - {description.content.slice(description.boldStartIndex, description.boldEndIndex)} - - {description.content.slice(description.boldEndIndex)} -

+ diff --git a/app/[locale]/search/OrangeCircle.tsx b/app/[locale]/search/OrangeCircle.tsx new file mode 100644 index 000000000..d038ea567 --- /dev/null +++ b/app/[locale]/search/OrangeCircle.tsx @@ -0,0 +1,3 @@ +export default function OrangeCircle() { + return
; +} diff --git a/app/[locale]/search/page.tsx b/app/[locale]/search/page.tsx index eaafcdcc7..d7b7aade5 100644 --- a/app/[locale]/search/page.tsx +++ b/app/[locale]/search/page.tsx @@ -24,12 +24,16 @@ import PageTitle from '@/components/layout/pageLayout/PageTitle'; import { getPath } from '@/utils/page'; import { main, news, notice, seminar } from '@/utils/segmentNode'; +import AboutRow from './AboutRow'; +import OrangeCircle from './OrangeCircle'; import SearchBoxWrapper from './SearchBoxWrapper'; const newsPath = getPath(news); const noticePath = getPath(notice); const seminarPath = getPath(seminar); +const DESCRIPTION_CHAR_CNT = 200; + export default async function SearchPage({ searchParams: { keyword }, }: { @@ -53,39 +57,38 @@ export default async function SearchPage({ } const SearchResult = async ({ keyword }: { keyword: string }) => { + // TODO: 단위별 에러 처리(allSettled) const [about, notice, news, seminar, member, research, academics, admissions] = await Promise.all( [ - searchAbout({ keyword, number: 5 }), - searchNotice({ keyword, number: 5 }), - searchNews({ keyword, number: 5 }), + searchAbout({ keyword, number: 5, amount: DESCRIPTION_CHAR_CNT }), + searchNotice({ keyword, number: 5, amount: DESCRIPTION_CHAR_CNT }), + searchNews({ keyword, number: 5, amount: DESCRIPTION_CHAR_CNT }), getSeminarPosts({ keyword, pageNum: 1 }), - searchMember({ keyword, number: 5 }), - searchResearch({ keyword, number: 5 }), - searchAcademics({ keyword, number: 5 }), - searchAdmissions({ keyword, number: 5 }), + searchMember({ keyword, number: 5, amount: DESCRIPTION_CHAR_CNT }), + searchResearch({ keyword, number: 5, amount: DESCRIPTION_CHAR_CNT }), + searchAcademics({ keyword, number: 5, amount: DESCRIPTION_CHAR_CNT }), + searchAdmissions({ keyword, number: 5, amount: DESCRIPTION_CHAR_CNT }), ], ); - const total = notice.total + news.total + seminar.total; - return ( <>
- {about.results} +
+ {about.results.map((result) => ( + + ))} +
-
+
{notice.results.slice(0, 2).map((notice) => ( ))} @@ -174,7 +177,7 @@ const SubSection = ({ return ( <>
-
+

{t(title)}({size})

diff --git a/components/common/RangeBolded.tsx b/components/common/RangeBolded.tsx new file mode 100644 index 000000000..6153c95e0 --- /dev/null +++ b/components/common/RangeBolded.tsx @@ -0,0 +1,17 @@ +export default function RangeBolded({ + partialDescription, + boldStartIndex, + boldEndIndex, +}: { + partialDescription: string; + boldStartIndex: number; + boldEndIndex: number; +}) { + return ( +

+ {partialDescription.slice(0, boldStartIndex)} + {partialDescription.slice(boldStartIndex, boldEndIndex)} + {partialDescription.slice(boldEndIndex)} +

+ ); +} diff --git a/types/search.ts b/types/search.ts index ebb322f10..eb8b7d5ff 100644 --- a/types/search.ts +++ b/types/search.ts @@ -2,22 +2,24 @@ export type AboutSearchResult = { total: number; - results: { - id: 0; - name: string; - aboutPostType: - | 'OVERVIEW' - | 'GREETINGS' - | 'HISTORY' - | 'FUTURE_CAREERS' - | 'CONTACT' - | 'STUDENT_CLUBS' - | 'FACILITIES' - | 'DIRECTIONS'; - partialDescription: string; - boldStartIndex: number; - boldEndIndex: number; - }[]; + results: AboutPreview[]; +}; + +export type AboutPreview = { + id: 0; + name: string; + aboutPostType: + | 'OVERVIEW' + | 'GREETINGS' + | 'HISTORY' + | 'FUTURE_CAREERS' + | 'CONTACT' + | 'STUDENT_CLUBS' + | 'FACILITIES' + | 'DIRECTIONS'; + partialDescription: string; + boldStartIndex: number; + boldEndIndex: number; }; // 소식 탭