Skip to content

Commit

Permalink
πŸ”§ fix: μ˜μ–΄μž…λ ₯μ‹œ λ¬΄ν•œ λ‘œλ”©μ΄ λ‚˜λŠ” 문제 ν•΄κ²°
Browse files Browse the repository at this point in the history
  • Loading branch information
dannysir committed Dec 5, 2024
1 parent 76cb795 commit c2b2be1
Showing 1 changed file with 16 additions and 29 deletions.
45 changes: 16 additions & 29 deletions FE/src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,43 +27,30 @@ export default function SearchModal() {
shouldSearch ? searchInput : '',
500,
);

const {
data: originalData,
isLoading: isOriginalLoading,
isFetching: isOriginalFetching,
} = useQuery({
queryKey: ['search', debounceValue],
queryFn: () => getSearchResults(formatNoSpecialChar(debounceValue)),
enabled: !!debounceValue && !isDebouncing,
staleTime: 10000,
cacheTime: 1000 * 60,
});
const convertedSearch = debounceValue
? Hangul.assemble(converter.convert(debounceValue))
: '';

const {
data: convertedData,
isLoading: isConvertedLoading,
isFetching: isConvertedFetching,
} = useQuery({
queryKey: ['search', convertedSearch],
queryFn: () => getSearchResults(formatNoSpecialChar(convertedSearch)),
enabled:
!isOriginalLoading &&
!isOriginalFetching &&
!!convertedSearch &&
originalData !== undefined &&
originalData.length === 0,
const { data, isLoading, isFetching } = useQuery({
queryKey: ['search', debounceValue],
queryFn: async () => {
// λ¨Όμ € 원본 κ²€μƒ‰μ–΄λ‘œ 검색
const originalResults = await getSearchResults(
formatNoSpecialChar(debounceValue),
);

// κ²°κ³Όκ°€ μ—†μœΌλ©΄ λ³€ν™˜λœ κ²€μƒ‰μ–΄λ‘œ 검색
if (originalResults.length === 0 && convertedSearch) {
return getSearchResults(formatNoSpecialChar(convertedSearch));
}

return originalResults;
},
enabled: !!debounceValue && !isDebouncing,
staleTime: 10000,
cacheTime: 1000 * 60,
});

const data = originalData?.length ? originalData : convertedData || [];
const isLoading = isOriginalLoading || isConvertedLoading;
const isFetching = isOriginalFetching || isConvertedFetching;

useEffect(() => {
if (data && data.length > 0 && debounceValue && !isLoading) {
addSearchHistory(formatNoSpecialChar(debounceValue));
Expand Down

0 comments on commit c2b2be1

Please sign in to comment.