@@ -7,18 +7,22 @@ import { ButtonLink } from "../../components/Button";
77import { Input } from "../../components/Form" ;
88import { Spinner } from "../../components/Icons" ;
99import { Heading , Link } from "../../components/Typography" ;
10+ import { boolAsString } from "../../lib/helpers" ;
1011import { CreateNoteForm } from "../CreateNote/CreateNoteForm" ;
1112
1213export const Notes = ( ) => {
1314 const queryClient = useQueryClient ( ) ;
1415 const [ search , setSearch ] = useState ( "" ) ;
16+ const [ favouritesOnly , setFavouritesOnly ] = useState < boolean > ( false ) ;
1517 const {
1618 data : notes ,
1719 isLoading,
1820 isFetching,
1921 isError,
2022 } = useQuery ( {
21- ...api . notes . getAll . query ( { searchParams : { search } } ) ,
23+ ...api . notes . getAll . query ( {
24+ searchParams : { search, favouritesOnly : boolAsString ( favouritesOnly ) } ,
25+ } ) ,
2226 placeholderData : keepPreviousData ,
2327 } ) ;
2428 const { mutate, submittedAt } = useMutation ( {
@@ -37,23 +41,39 @@ export const Notes = () => {
3741 return (
3842 < section className = "space-y-6" >
3943 < div className = "flex items-center justify-between" >
40- < Heading level = { 1 } > Notes</ Heading >
44+ < div className = "flex items-center gap-4" >
45+ < Heading level = { 1 } > Notes</ Heading >
46+ { isFetching && < Spinner /> }
47+ </ div >
4148 < ButtonLink to = "/create" > Create note</ ButtonLink >
4249 </ div >
4350
44- < label htmlFor = "search" className = "sr-only" >
45- Filter notes
46- </ label >
47- < div className = "flex items-center gap-2" >
48- < Input
49- placeholder = "Filter notes..."
50- type = "text"
51- name = "search"
52- id = "search"
53- value = { search }
54- onChange = { ( e ) => setSearch ( e . target . value ) }
55- />
56- { isFetching && < Spinner /> }
51+ < div className = "flex items-center gap-8" >
52+ < div className = "flex items-center gap-2" >
53+ < label htmlFor = "search" className = "sr-only" >
54+ Filter notes
55+ </ label >
56+ < Input
57+ placeholder = "Filter notes..."
58+ type = "text"
59+ name = "search"
60+ id = "search"
61+ value = { search }
62+ onChange = { ( e ) => setSearch ( e . target . value ) }
63+ />
64+ </ div >
65+
66+ < div className = "flex items-center gap-2" >
67+ < label htmlFor = "favs" > Only favs</ label >
68+ < Input
69+ className = "w-fit"
70+ type = "checkbox"
71+ name = "favs"
72+ id = "favs"
73+ checked = { favouritesOnly }
74+ onChange = { ( e ) => setFavouritesOnly ( e . target . checked ) }
75+ />
76+ </ div >
5777 </ div >
5878
5979 < ul >
0 commit comments