Skip to content

Commit 14e68d5

Browse files
committed
Done except for has more
1 parent e551166 commit 14e68d5

File tree

2 files changed

+5
-40
lines changed

2 files changed

+5
-40
lines changed

pages/lex/minerals/+Page.ts

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,18 @@
11
import h from "./main.module.sass";
2-
import { useAPIResult, InfiniteScrollView } from "@macrostrat/ui-components";
2+
import { InfiniteScrollView } from "@macrostrat/ui-components";
33
import { 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";
76
import { ContentPage } from "~/layouts";
87
import { SearchBar } from "~/components/general";
98
import { useData } from "vike-react/useData";
109

1110
export 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-
9458
function getNextParams(response, params) {
9559
console.log("getNextParams", response, params, "gt." + response[response.length - 1].id);
9660
return {

pages/lex/minerals/+data.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ export async function data() {
55
const res = await fetch(url).then((r) => {
66
return r.json();
77
});
8+
89
return { res };
910
}

0 commit comments

Comments
 (0)