11import h from "./main.module.sass" ;
2- import { useAPIResult , InfiniteScrollView } from "@macrostrat/ui-components" ;
2+ import { InfiniteScrollView } from "@macrostrat/ui-components" ;
33import { apiDomain } from "@macrostrat-web/settings" ;
4- import { StickyHeader , LinkCard , PageBreadcrumbs , Link } from "~/components" ;
5- import { Spinner } from "@blueprintjs/core" ;
6- import { useState , useEffect , useRef } from "react" ;
4+ import { StickyHeader , LinkCard , PageBreadcrumbs } from "~/components" ;
5+ import { useState } from "react" ;
76import { ContentPage } from "~/layouts" ;
87import { SearchBar } from "~/components/general" ;
98import { useData } from "vike-react/useData" ;
109
1110export function Page ( ) {
1211 const { res } = useData ( ) ;
13- const startingID = res [ res . length - 1 ] . id ;
1412
1513 const [ input , setInput ] = useState ( "" ) ;
16- const [ lastID , setLastID ] = useState ( startingID ) ;
17- const [ data , setData ] = useState ( res ) ;
1814 const pageSize = 20 ;
1915
20- const result = useMineralData ( lastID , input , pageSize ) ;
21- const prevInputRef = useRef ( input ) ;
22-
23- useEffect ( ( ) => {
24- if ( prevInputRef . current !== input ) {
25- setData ( [ ] ) ;
26- setLastID ( 0 ) ;
27-
28- prevInputRef . current = input ;
29- }
30- } , [ input ] ) ;
31-
32- useEffect ( ( ) => {
33- if (
34- result &&
35- data [ data . length - 1 ] ?. id !==
36- result [ result . length - 1 ] ?. id
37- ) {
38- setData ( ( prevData ) => {
39- return [ ...prevData , ...result ] ;
40- } ) ;
41- }
42- } , [ result ] ) ;
43-
4416 const handleChange = ( event ) => {
4517 setInput ( event . toLowerCase ( ) ) ;
4618 } ;
@@ -59,7 +31,7 @@ export function Page() {
5931 params : {
6032 order : "id.asc" ,
6133 mineral : `ilike.*${ input } *` ,
62- id : `gt.${ lastID } ` ,
34+ id : `gt.0 ` ,
6335 limit : pageSize ,
6436 } ,
6537 route : `${ apiDomain } /api/pg/minerals` ,
@@ -83,14 +55,6 @@ function MineralItem({ data }) {
8355 ) ;
8456}
8557
86- function useMineralData ( lastID , input , pageSize ) {
87- const url = `${ apiDomain } /api/pg/minerals?limit=${ pageSize } &id=gt.${ lastID } &order=id.asc&mineral=ilike.*${ input } *` ;
88-
89- const result = useAPIResult ( url ) ;
90-
91- return result ;
92- }
93-
9458function getNextParams ( response , params ) {
9559 console . log ( "getNextParams" , response , params , "gt." + response [ response . length - 1 ] . id ) ;
9660 return {
0 commit comments