Skip to content

Commit 586a4ef

Browse files
authored
Merge pull request #178 from GulSam00/feat/175-searchHistoryUiImprove
[Feat] : 검색어 히스토리 컴포넌트 UI 개선 (#175)
2 parents 1098450 + 2580aea commit 586a4ef

2 files changed

Lines changed: 60 additions & 45 deletions

File tree

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import { ChartNoAxesCombined } from 'lucide-react';
3+
import { ChartNoAxesCombined, Loader2 } from 'lucide-react';
44

55
import { useSearchLogQuery } from '@/queries/searchLogQuery';
66

@@ -9,33 +9,36 @@ interface PopularSearchHistoryProps {
99
}
1010

1111
export default function PopularSearchHistory({ onHistoryClick }: PopularSearchHistoryProps) {
12-
const { data: searchLogs } = useSearchLogQuery();
13-
14-
if (!searchLogs || searchLogs.length === 0) return null;
12+
const { data: searchLogs, isPending } = useSearchLogQuery();
1513

1614
return (
17-
<div>
15+
<div className="h-30 overflow-hidden">
1816
<div className="flex items-center gap-2">
1917
<ChartNoAxesCombined className="h-4 w-4" />
2018
<p className="m-2">인기 검색어</p>
2119
</div>
22-
<div className="flex flex-wrap gap-2 pb-4">
23-
{searchLogs.slice(0, 10).map((log, index) => (
24-
<div
25-
key={`${log.text}-${index}`}
26-
className="bg-background flex items-center gap-2 rounded-full border px-3 py-1.5 text-sm"
27-
>
28-
<span className="text-xs">{index + 1}</span>
29-
<span
30-
className="hover:text-primary max-w-30 cursor-pointer truncate text-left"
31-
onClick={() => onHistoryClick(log.text)}
20+
{isPending ? (
21+
<div className="flex items-center justify-center py-4">
22+
<Loader2 className="h-5 w-5 animate-spin" />
23+
</div>
24+
) : (
25+
<div className="flex flex-wrap gap-2 pb-4">
26+
{searchLogs?.slice(0, 10).map((log, index) => (
27+
<div
28+
key={`${log.text}-${index}`}
29+
className="bg-background flex items-center gap-2 rounded-full border px-3 py-1.5 text-sm"
3230
>
33-
{log.text}
34-
</span>
35-
<span className="text-muted-foreground text-xs">{log.count}</span>
36-
</div>
37-
))}
38-
</div>
31+
<span
32+
className="hover:text-primary max-w-30 cursor-pointer truncate text-left"
33+
onClick={() => onHistoryClick(log.text)}
34+
>
35+
{log.text}
36+
</span>
37+
<span className="text-muted-foreground text-xs">{log.count}</span>
38+
</div>
39+
))}
40+
</div>
41+
)}
3942
</div>
4043
);
4144
}
Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Clock, X } from 'lucide-react';
1+
import { Clock, Loader2, X } from 'lucide-react';
2+
import { useEffect, useState } from 'react';
23

34
import useSearchHistoryStore from '@/stores/useSearchHistoryStore';
45

@@ -8,37 +9,48 @@ interface SearchHistoryProps {
89

910
export default function SearchHistory({ onHistoryClick }: SearchHistoryProps) {
1011
const { searchHistory, removeFromHistory } = useSearchHistoryStore();
12+
const [isHydrated, setIsHydrated] = useState(false);
1113

12-
if (searchHistory.length === 0) return null;
14+
useEffect(() => {
15+
if (searchHistory.length > 0) {
16+
setIsHydrated(true);
17+
}
18+
}, [searchHistory]);
1319

1420
return (
15-
<div>
21+
<div className="h-30 overflow-hidden">
1622
<div className="flex items-center gap-2">
1723
<Clock className="h-4 w-4" />
1824
<p className="m-2">최근 검색어</p>
1925
</div>
20-
<div className="flex flex-wrap gap-2 pb-4">
21-
{searchHistory.slice(10).map((term, index) => (
22-
<div
23-
key={`${term}-${index}`}
24-
className="bg-background flex items-center gap-2 rounded-full border px-3 py-1.5 text-sm"
25-
>
26-
<span
27-
className="hover:text-primary max-w-30 cursor-pointer truncate text-left"
28-
onClick={() => onHistoryClick(term)}
26+
{!isHydrated ? (
27+
<div className="flex items-center justify-center py-4">
28+
<Loader2 className="h-5 w-5 animate-spin" />
29+
</div>
30+
) : (
31+
<div className="flex flex-wrap gap-2 pb-4">
32+
{searchHistory.slice(0, 10).map((term, index) => (
33+
<div
34+
key={`${term}-${index}`}
35+
className="bg-background flex items-center gap-2 rounded-full border px-3 py-1.5 text-sm"
2936
>
30-
{term}
31-
</span>
32-
<span
33-
className="hover:text-destructive cursor-pointer"
34-
onClick={() => removeFromHistory(term)}
35-
title="검색 기록 삭제"
36-
>
37-
<X className="h-4 w-4" />
38-
</span>
39-
</div>
40-
))}
41-
</div>
37+
<span
38+
className="hover:text-primary max-w-30 cursor-pointer truncate text-left"
39+
onClick={() => onHistoryClick(term)}
40+
>
41+
{term}
42+
</span>
43+
<span
44+
className="hover:text-destructive cursor-pointer"
45+
onClick={() => removeFromHistory(term)}
46+
title="검색 기록 삭제"
47+
>
48+
<X className="h-4 w-4" />
49+
</span>
50+
</div>
51+
))}
52+
</div>
53+
)}
4254
</div>
4355
);
4456
}

0 commit comments

Comments
 (0)