@@ -5,15 +5,23 @@ import { Tabs } from '@zicdding-web/ui/Tabs';
5
5
import { Input } from '@zicdding-web/ui/Input' ;
6
6
import { Button } from '@zicdding-web/ui' ;
7
7
import { ClassCard , useGetClasses } from '@/src/features/class-card' ;
8
+ import type { SortType } from '../model/type' ;
9
+ import { useSearch } from './use-search' ;
8
10
import { useRouter } from 'next/navigation' ;
11
+ import { useMemo } from 'react' ;
9
12
10
13
export function ClassListPage ( ) {
11
- const { data : classList , isLoading } = useGetClasses ( ) ;
12
14
const router = useRouter ( ) ;
13
15
14
- // GYU-TODO: 인기순/최신순 query 로 관리하고 데이터가 없으면 기본값 설정해서 tabs 와 데이터 일치하게 하기!
15
- // tabs 도 상태로 해야하나? 아니면 onChange 가 발생할때 url 로 제어해서 따로 client-component 로 추출하지 않게 해야하나?
16
- // URL 로 제어하는게 좋을듯
16
+ const { data : classList , isLoading } = useGetClasses ( ) ;
17
+
18
+ const { localSearchValue, searchValue, sortType, onSearchSubmit, onChangeSearchValue, onSearch, onSortTypeChange } =
19
+ useSearch ( ) ;
20
+
21
+ const _classList = useMemo ( ( ) => {
22
+ return classList ?. filter ( ( classItem ) => classItem . classTitle . includes ( searchValue ) ) ;
23
+ } , [ classList , searchValue ] ) ;
24
+
17
25
return (
18
26
< div className = "px-6" >
19
27
< div className = "flex justify-between items-center" >
@@ -23,7 +31,8 @@ export function ClassListPage() {
23
31
{ title : '인기순' , value : 'popular' } ,
24
32
{ title : '최신순' , value : 'recent' } ,
25
33
] }
26
- onChange = { ( ) => { } }
34
+ value = { sortType }
35
+ onChange = { ( value ) => onSortTypeChange ( value as SortType ) }
27
36
defaultValue = "popular"
28
37
/>
29
38
</ div >
@@ -32,14 +41,23 @@ export function ClassListPage() {
32
41
33
42
< div className = "flex justify-between items-center" >
34
43
< Button > 클래스 만들기</ Button >
35
- < Input type = "search" width = { 366 } onClickSearch = { ( ) => { } } />
44
+ < form onSubmit = { onSearchSubmit } >
45
+ < Input
46
+ type = "search" //
47
+ name = "search"
48
+ width = { 366 }
49
+ value = { localSearchValue }
50
+ onChange = { onChangeSearchValue }
51
+ onClickSearch = { onSearch }
52
+ />
53
+ </ form >
36
54
</ div >
37
55
38
56
< ul className = "flex flex-wrap items-start gap-8 mx-auto mt-8" >
39
57
{ isLoading ? (
40
58
< div > loading...</ div >
41
59
) : (
42
- classList ?. map ( ( classItem ) => (
60
+ _classList ?. map ( ( classItem ) => (
43
61
< ClassCard
44
62
key = { classItem . classId }
45
63
title = { classItem . classTitle }
0 commit comments