package-bottle.jsx edit to inlude loading

This commit is contained in:
Thomas Smith 2023-01-20 16:25:24 -05:00
parent 2be6f65817
commit 5de6a86c16

View file

@ -1,13 +1,19 @@
function PackageBottles() { function PackageBottles() {
const [bottles, setBottles] = React.useState(); const [bottles, setBottles] = React.useState();
const [isLoading, setIsLoading] = React.useState(true);
React.useEffect(() => { React.useEffect(() => {
const url = window.location.pathname.replace('/+', 'https://app.tea.xyz/api/bottles/'); const url = window.location.pathname.replace('/+', 'https://app.tea.xyz/api/bottles/');
fetch(url) fetch(url)
.then((res) => res.json()) .then((res) => res.json())
.then((res) => setBottles(res)); .then((res) => {
setBottles(res);
setIsLoading(false);
});
}, []); }, []);
if (isLoading) return <div>Loading...</div>;
if (!bottles) return null; if (!bottles) return null;
const names = [...new Set(bottles.map((b) => b.name))]; const names = [...new Set(bottles.map((b) => b.name))];