File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -108,6 +108,10 @@ const AppList = ({ queryTerm }) => {
108108 } ) ;
109109 } , [ appsLoadable . contents , setAppsData , appsLoadable . state ] ) ;
110110
111+ useEffect ( ( ) => {
112+ setNextPage ( null ) ;
113+ } , [ queryTerm ] ) ;
114+
111115 useEffect ( ( ) => {
112116 if ( loaderRef . current && appsLoadable . state === "hasValue" ) {
113117 setAppsData ( appsLoadable . contents ) ;
@@ -181,7 +185,6 @@ export default function Search({ appSlug }) {
181185 sx = { { p : "2px 4px" , display : "flex" , alignItems : "center" } }
182186 onSubmit = { ( e ) => {
183187 e . preventDefault ( ) ;
184- // searchApps(searchTerm);
185188 setQueryTerm ( `search?query=${ searchTerm } ` ) ;
186189 } }
187190 >
Original file line number Diff line number Diff line change @@ -455,7 +455,7 @@ export const storeAppState = atomFamily({
455455
456456export const appsPageState = atomFamily ( {
457457 key : "appsPageState" ,
458- default : { apps : [ ] , nextPage : null } ,
458+ default : { apps : [ ] , nextPage : null , empty : false } ,
459459} ) ;
460460
461461export const fetchAppsFromStore = selectorFamily ( {
@@ -464,7 +464,12 @@ export const fetchAppsFromStore = selectorFamily({
464464 ( { queryTerm, nextPage } ) =>
465465 async ( { get } ) => {
466466 const currentPageData = get ( appsPageState ( queryTerm ) ) ;
467- if ( nextPage === currentPageData . nextPage ) {
467+ if (
468+ ( nextPage && nextPage === currentPageData . nextPage ) ||
469+ ( ! nextPage &&
470+ currentPageData . apps . length === 0 &&
471+ ! currentPageData . empty )
472+ ) {
468473 try {
469474 const response = await axios ( ) . get (
470475 nextPage ?. replaceAll ( "http://localhost:8000" , "" ) ||
@@ -474,6 +479,7 @@ export const fetchAppsFromStore = selectorFamily({
474479 return {
475480 apps : [ ...currentPageData . apps , ...data . results ] ,
476481 nextPage : data . next ,
482+ empty : data . results . length === 0 ,
477483 } ;
478484 } catch ( error ) {
479485 console . error ( error ) ;
You can’t perform that action at this time.
0 commit comments