Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Bit-Barron committed Sep 23, 2024
1 parent 4993111 commit f2c42fc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
6 changes: 5 additions & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import createNextIntlPlugin from "next-intl/plugin";
const withNextIntl = createNextIntlPlugin();

/** @type {import('next').NextConfig} */
const nextConfig = {};
const nextConfig = {
images: {
domains: ["coin-images.coingecko.com"],
},
};

export default withNextIntl(nextConfig);
4 changes: 2 additions & 2 deletions src/app/[locale]/(home)/coin/[coinId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export default function CoinInfoPage() {
<Card className="mb-8">
<CardHeader className="flex flex-row items-center space-y-0 pb-2">
<Avatar className="h-16 w-16 mr-4">
<AvatarImage src={coin?.image.large} alt={coin?.name} />
<AvatarFallback>{coin?.symbol.toUpperCase()}</AvatarFallback>
<AvatarImage src={coin?.image?.large} alt={coin?.name} />
<AvatarFallback>{coin?.symbol?.toUpperCase()}</AvatarFallback>
</Avatar>
<div>
<CardTitle className="text-2xl">{coin?.name}</CardTitle>
Expand Down
10 changes: 7 additions & 3 deletions src/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Navbar } from "@/components/pages/container/navbar";
import QueryProvider from "@/components/providers/query-provider";
import { fetchCoins } from "@/lib/fetch-coins";
// import { fetchCoins } from "@/lib/fetch-coins";
import { fetchCoinData, fetchCoins } from "@/lib/fetch-coins";
import getQueryClient from "@/lib/react-query";
import { dehydrate, HydrationBoundary } from "@tanstack/react-query";
import { NextIntlClientProvider } from "next-intl";
Expand All @@ -18,9 +17,14 @@ export default async function LocaleLayout({
const queryClient = getQueryClient();

const initialCoins = await fetchCoins();

queryClient.setQueryData(["coin", "market_cap_desc", 1], initialCoins);

const firstCoinId = initialCoins[0]?.id;
if (firstCoinId) {
const coinData = await fetchCoinData(firstCoinId);
queryClient.setQueryData(["coin", firstCoinId], coinData);
}

return (
<NextIntlClientProvider messages={messages} locale={locale}>
<QueryProvider>
Expand Down
12 changes: 2 additions & 10 deletions src/components/hooks/coin-hook.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fetchCoins } from "@/lib/fetch-coins";
import { fetchCoinData, fetchCoins } from "@/lib/fetch-coins";
import { useQuery } from "@tanstack/react-query";
import { useParams } from "next/navigation";

Expand All @@ -17,15 +17,7 @@ export const CoinHook = (

const coinIdQuery = useQuery<CoinIdData>({
queryKey: ["coin", params.coinId],
queryFn: async () => {
const response = await fetch(
`https://api.coingecko.com/api/v3/coins/${params.coinId}`
);
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.json();
},
queryFn: () => fetchCoinData(),
enabled: !!params.coinId,
staleTime: 60000,
refetchOnWindowFocus: false,
Expand Down

0 comments on commit f2c42fc

Please sign in to comment.