Skip to content

Commit 7173517

Browse files
committed
feat: 계획 관리 페이지 검색 기능 구현
1 parent bb2733f commit 7173517

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

app/(with-sidebar)/plans/page.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ const Page = () => {
3838
completed: 0, // 완료됨
3939
});
4040

41+
const [searchQuery, setSearchQuery] = useState('');
42+
4143
// 카드 업데이트를 위한 stats 가져오기 메서드
4244
const fetchAndCalculate = async (
4345
uid: string,
@@ -202,19 +204,29 @@ const Page = () => {
202204
}
203205
};
204206

207+
// 검색 로직
208+
const filteredPlans = plans.filter((plan) =>
209+
plan.title.toLowerCase().includes(searchQuery.toLowerCase())
210+
);
211+
205212
// 페이지네이션 파트
206-
const totalPages = Math.ceil(plans.length / itemsPerPage);
213+
const totalPages = Math.ceil(filteredPlans.length / itemsPerPage);
207214
const startIndex = (currentPage - 1) * itemsPerPage;
208215
const endIndex = startIndex + itemsPerPage;
209-
const paginatedPlans = plans.slice(startIndex, endIndex);
216+
const paginatedPlans = filteredPlans.slice(startIndex, endIndex);
217+
218+
const handleSearch = (query: string) => {
219+
setSearchQuery(query);
220+
setCurrentPage(1); // 검색 결과가 바뀌면 첫 페이지로 리셋
221+
};
210222

211223
useEffect(() => {
212224
if (currentPage > totalPages && totalPages > 0) {
213225
setCurrentPage(totalPages);
214226
} else if (totalPages === 0 && currentPage !== 1) {
215227
setCurrentPage(1);
216228
}
217-
}, [plans.length, totalPages, currentPage]);
229+
}, [totalPages, currentPage]);
218230

219231
return (
220232
<div className="bg-background min-h-screen p-11">
@@ -277,7 +289,7 @@ const Page = () => {
277289
</div>
278290

279291
{/* 검색 바 */}
280-
<SearchBar />
292+
<SearchBar value={searchQuery} onChange={handleSearch} />
281293

282294
{/* 하단 추가 버튼 or 인라인 폼 */}
283295
<div className="mt-6 mb-4">

components/plans/SearchBar.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import { Search } from 'lucide-react';
22

3-
export default function SearchBar() {
3+
interface SearchBarProps {
4+
value: string;
5+
onChange: (value: string) => void;
6+
}
7+
8+
export default function SearchBar({ value, onChange }: SearchBarProps) {
49
return (
510
<div className="mb-4 flex justify-end">
611
<div className="relative">
712
<input
813
type="text"
9-
placeholder="검색어를 입력하세요"
14+
value={value}
15+
onChange={(e) => onChange(e.target.value)}
16+
placeholder="플랜 제목으로 검색..."
1017
className="w-64 rounded-full border border-gray-200 bg-white py-2 pr-10 pl-4 text-sm shadow-sm focus:border-purple-400 focus:outline-none"
1118
/>
1219
<Search className="absolute top-2.5 right-3 text-gray-400" size={18} />

0 commit comments

Comments
 (0)