Skip to content

Commit

Permalink
πŸ‘Œ IMPROVE: Refactor Title component and add Title to Stats component.…
Browse files Browse the repository at this point in the history
… Add loading component
  • Loading branch information
All-Khwarizmi committed Mar 19, 2024
1 parent 0586bea commit d75bf1b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/components/Title.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function Title() {
export function Title({ title }: { title: string }) {
return (
<h1
className="text-6xl font-bold dark:text-purple-700 text-black"
Expand All @@ -8,7 +8,7 @@ export function Title() {
WebkitTextFillColor: "transparent",
}}
>
Dico
{title}
</h1>
);
}
2 changes: 1 addition & 1 deletion src/components/TranslationDirection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function TitleAndDirection({
}: TranslationDirectionProps) {
return (
<section className="flex flex-col h-[20%] items-center gap-5">
<Title />
<Title title="Dico" />
<div className="grid place-items-center w-full ">
{isFr ? (
<div
Expand Down
5 changes: 3 additions & 2 deletions src/components/stats/Stats.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Title } from "../Title";
import WordsList from "./WordsList";

export default function Stats() {
return (
<main className="pt-24 mx-auto h-full w-full justify-start">
<header className="flex flex-col gap-4 gap-y-12 pb-10">
<h1 className="text-5xl">Dico en nombres</h1>
<header className="flex flex-col items-center gap-4 gap-y-12 pb-10">
<Title title="Statistiques" />
</header>
<section className="w-full flex gap-4 gap-y-8 flex-col md:flex-row px-4">
<WordsList />
Expand Down
14 changes: 11 additions & 3 deletions src/components/stats/WordsList.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { useQuery, useQueryClient } from "@tanstack/react-query";
import React from "react";
import { AxisOptions, Chart } from "react-charts";
import { LoadingGlass } from "../LoadingGlass";

// async function fetchWords() {
// const response = await import("@/utils/schemas/top-searches.json");
// return response.default;
// }
async function fetchWords() {
const response = await import("@/utils/schemas/top-searches.json");
return response.default;
const response = await fetch("/api/stats");
if (!response.ok) {
throw new Error("Failed to fetch data");
}
return response.json();
}

interface WordSearches {
Expand Down Expand Up @@ -39,7 +47,7 @@ export default function WordsList() {
return <div>Failed to load data</div>;
}
if (query.isLoading) {
return <div>Loading...</div>;
return <LoadingGlass />;
}
return (
<article className="w-full h-full">
Expand Down
2 changes: 1 addition & 1 deletion src/unit-tests/components/title.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React from "react";

describe("Title", () => {
it("should work", () => {
render(<Title />);
render(<Title title="Dico" />);
const title = screen.getByText("Dico");
expect(title).toBeDefined();
});
Expand Down

0 comments on commit d75bf1b

Please sign in to comment.