@@ -5,14 +5,20 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
55import { Button } from "@/components/ui/button" ;
66import { ScrollArea , ScrollBar } from "@/components/ui/scroll-area" ;
77import { buildSearchParams } from "@/lib/helpers" ;
8+ import { useEffect , useState } from "react" ;
89
910export default function ConceptList ( { concepts } : { concepts : Concept [ ] } ) {
1011 const router = useRouter ( ) ;
1112 const pathname = usePathname ( ) ;
1213 const searchParams = useSearchParams ( ) ;
13- const selectedConcepts = searchParams . getAll ( "conceptId" ) . sort ( ) ;
14+ const selectedConcepts = searchParams . getAll ( "conceptId" )
15+ const [ loading , setLoading ] = useState ( false ) ;
1416
1517 const onSelect = ( conceptId : string ) => {
18+ if ( loading ) return ;
19+
20+ setLoading ( true ) ;
21+
1622 const current = searchParams . getAll ( "conceptId" ) ;
1723
1824 const nextConceptIds = current . includes ( conceptId )
@@ -25,9 +31,14 @@ export default function ConceptList({ concepts }: { concepts: Concept[] }) {
2531 page : 1 ,
2632 } ) ;
2733
28- router . replace ( `${ pathname } ?${ query } ` , { scroll : false } ) ;
29- router . refresh ( ) ;
34+ router . replace ( `${ pathname } ?${ query } ` , {
35+ scroll : false ,
36+ } ) ;
37+
3038 } ;
39+ useEffect ( ( ) => {
40+ setLoading ( false ) ;
41+ } , [ searchParams ] ) ;
3142 const clearSelection = ( ) => {
3243 const query = buildSearchParams ( {
3344 conceptIds : [ ] ,
@@ -36,7 +47,6 @@ export default function ConceptList({ concepts }: { concepts: Concept[] }) {
3647 } ) ;
3748
3849 router . replace ( `${ pathname } ?${ query } ` , { scroll : false } ) ;
39-
4050 } ;
4151
4252 return (
0 commit comments