m/cup
1
0
mirror of https://github.com/sergi0g/cup.git synced 2025-11-14 16:13:48 -05:00

refactor: better data fetching (#100)

This commit is contained in:
Raphaël Catarino
2025-05-02 18:12:19 +02:00
committed by GitHub
parent 2ac036d353
commit 5ea924c5ad
4 changed files with 76 additions and 14 deletions

View File

@@ -4,11 +4,12 @@ import Statistic from "./components/Statistic";
import Image from "./components/Image";
import { LastChecked } from "./components/LastChecked";
import Loading from "./components/Loading";
import { Data } from "./types";
import { theme } from "./theme";
import RefreshButton from "./components/RefreshButton";
import Search from "./components/Search";
import { Server } from "./components/Server";
import { useData } from "./hooks/use-data";
import DataLoadingError from "./components/DataLoadingError";
const SORT_ORDER = [
"monitored_images",
@@ -22,10 +23,11 @@ const SORT_ORDER = [
];
function App() {
const [data, setData] = useState<Data | null>(null);
const { data, isLoading, isError } = useData();
const [searchQuery, setSearchQuery] = useState("");
if (!data) return <Loading onLoad={setData} />;
if (isLoading) return <Loading />;
if (isError || !data) return <DataLoadingError />;
return (
<div
className={`flex min-h-screen justify-center bg-white dark:bg-${theme}-950`}