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
21 changes: 14 additions & 7 deletions apps/web/app/_components/SearchPage/SearchPlaceListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Props } from './SearchPage'
import type { BasePlace } from './SearchPage'
import { Column, Flex } from '@repo/ui/components/Layout'
import { Icon } from '@repo/ui/components/Icon'
import { Text } from '@repo/ui/components/Text'
Expand All @@ -12,7 +12,7 @@ export const SearchPlaceListItem = ({
onClick,
}: {
inputValue: string
place: Props['places'][0]
place: BasePlace
onClick: VoidFunction
}) => {
return (
Expand All @@ -32,15 +32,22 @@ export const SearchPlaceListItem = ({
)
}

/**
* 정규식 특수 문자를 이스케이프 처리하는 함수
* 예: "[" -> "\[", "?" -> "\?"
*/
const escapeRegExp = (string: string) =>
string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')

/**
* 검색어 강조 처리
* @param inputValue 검색어
* @param placeName 장소 이름
* @param keyword 검색어
* @param text 검색 결과
* @returns JSX.Element[]
*/
const highlightWord = (inputValue: string, placeName: string) => {
const regex = new RegExp(`(${inputValue})`, 'gi')
const parts = placeName.split(regex)
const highlightWord = (keyword: string, text: string) => {
const regex = new RegExp(`(${escapeRegExp(keyword)})`, 'gi')
const parts = text.split(regex)

return parts.map((part, index) =>
regex.test(part) ? (
Expand Down
1 change: 1 addition & 0 deletions apps/web/app/places/search/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const Page = () => {

return (
<SearchPage
placeholder={'식당을 검색해주세요'}
useBackHandler={true}
searchFunc={handleSearch}
onSelectPlace={(id) => {
Expand Down