@@ -38,8 +38,14 @@ function usePatientListFilterForCurrentTab(selectedTab: number, search: string)
3838const PatientListList : React . FC = ( ) => {
3939 const { t } = useTranslation ( ) ;
4040 const [ selectedTab , setSelectedTab ] = useState < number > ( TabIndices . STARRED_LISTS ) ;
41- const [ searchString , setSearchString ] = useState ( '' ) ;
42- const patientListFilter = usePatientListFilterForCurrentTab ( selectedTab , searchString ) ;
41+ const [ searchTerms , setSearchTerms ] = useState ( {
42+ [ TabIndices . STARRED_LISTS ] : '' ,
43+ [ TabIndices . SYSTEM_LISTS ] : '' ,
44+ [ TabIndices . MY_LISTS ] : '' ,
45+ [ TabIndices . ALL_LISTS ] : '' ,
46+ } ) ;
47+ const currentSearchTerm = searchTerms [ selectedTab ] ;
48+ const patientListFilter = usePatientListFilterForCurrentTab ( selectedTab , currentSearchTerm ) ;
4349 const { patientLists, isLoading, isValidating, error, mutate } = useAllPatientLists ( patientListFilter ) ;
4450 const { search } = useLocation ( ) ;
4551 const createNewList =
@@ -81,6 +87,13 @@ const PatientListList: React.FC = () => {
8187 { id : 4 , key : 'isStarred' , header : '' } ,
8288 ] ;
8389
90+ const handleSearch = ( searchString : string ) => {
91+ setSearchTerms ( ( prevSearchTerms ) => ( {
92+ ...prevSearchTerms ,
93+ [ selectedTab ] : searchString ,
94+ } ) ) ;
95+ } ;
96+
8497 return (
8598 < main className = { `omrs-main-content ${ styles . patientListListPage } ` } >
8699 < section className = { styles . patientListList } >
@@ -123,8 +136,8 @@ const PatientListList: React.FC = () => {
123136 isValidating = { isValidating }
124137 headers = { tableHeaders }
125138 patientLists = { patientLists }
126- searchString = { searchString }
127- setSearchString = { setSearchString }
139+ searchTerm = { currentSearchTerm }
140+ setSearchTerm = { handleSearch }
128141 refetch = { mutate }
129142 error = { error }
130143 />
0 commit comments