Initial commit

This commit is contained in:
2026-03-04 01:58:10 +01:00
commit 19c9295809
29 changed files with 5232 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
import { useQuery } from "@tanstack/react-query";
import { useParams } from "react-router";
import { ErrorView } from "~/components/error/ErrorView";
import { LoadingView } from "~/components/loading/LoadingView";
import { fetchApi } from "~/lib/fetch";
import type { CryptocurrencyDetailsResponse } from "~/types/crypto-api";
import { DescriptionSection } from "./DescriptionSection";
import { useState } from "react";
import { KeyStats } from "./KeyStats";
import { PriceChart } from "./PriceChart";
export function CryptoDetailsPage() {
const { id } = useParams();
const [expandedView, setExpandedView] = useState(false);
const { data, isPending, error } = useQuery({
queryKey: ["cryptocurrencies", id],
queryFn: () => fetchApi<CryptocurrencyDetailsResponse>(`https://api.next.code-camp.org/cryptocurrencies/${id}`)
});
if (isPending) {
return <LoadingView />;
}
if (error) {
return <ErrorView />;
}
return (
<div>
<DescriptionSection currency={data.currency} />
<section className={expandedView ? "flex flex-col gap-4" : "grid gap-4 lg:grid-cols-5"}>
<KeyStats currency={data.currency} />
<PriceChart currency={data.currency} expanded={expandedView} onToggleExpand={() => setExpandedView(!expandedView)} />
</section>
</div>
);
}