Ajout d'une fonctionnalité de citation aléatoire dans le composant QuoteCard avec récupération des données depuis un fichier JSON.

This commit is contained in:
Kevin 2025-02-21 23:06:13 +01:00
parent cb1cd951ad
commit 032c4ed3f3
3 changed files with 244 additions and 15 deletions

View File

@ -1,4 +1,3 @@
import { SpaceNav } from "@/components/space-nav";
import { QuoteCard } from "@/components/quote-card"; import { QuoteCard } from "@/components/quote-card";
import { Messages } from "@/components/messages"; import { Messages } from "@/components/messages";
import { Podcast } from "@/components/podcast"; import { Podcast } from "@/components/podcast";

View File

@ -1,22 +1,50 @@
import { RefreshCw } from 'lucide-react' "use client";
import { Card, CardContent } from "@/components/ui/card"
import { RefreshCw } from "lucide-react";
import { Card, CardContent } from "@/components/ui/card";
import { useEffect, useState } from "react";
interface Quote {
quote: string;
author: string;
}
export function QuoteCard() { export function QuoteCard() {
const fetchQuote = async (): Promise<Quote> => {
// Récupere la liste des citations depuis le fichier dans /public/quotes.json
const response = await fetch("/quotes.json");
const data = await response.json();
// Retourne une citation aléatoire
return data[Math.floor(Math.random() * data.length)];
};
const [quote, setQuote] = useState<Quote | null>(null);
useEffect(() => {
fetchQuote().then(setQuote);
}, []);
const handleRefresh = () => {
fetchQuote().then(setQuote);
};
return ( return (
<Card className="relative"> <Card className='relative'>
<CardContent className="p-6"> <CardContent className='p-6'>
<blockquote className="space-y-2"> <blockquote className='space-y-2'>
<p className="text-lg"> <p className='text-lg'>{quote ? quote.quote : "Loading..."}</p>
"To be a good artist / letterer / designer / guitar player, it takes practice. A lot of it. More than you can even <footer className='text-sm text-gray-500'>
fathom when you're starting out." {quote ? quote.author : "Loading..."}
</p> </footer>
<footer className="text-sm text-gray-500">Jessica Hische</footer>
</blockquote> </blockquote>
<button className="absolute bottom-4 right-4 p-1 hover:bg-gray-100 rounded-full"> <button
<RefreshCw className="w-4 h-4" /> className='absolute bottom-4 right-4 p-1 hover:bg-gray-100 rounded-full'
onClick={handleRefresh}
>
<RefreshCw className='w-4 h-4' />
</button> </button>
</CardContent> </CardContent>
</Card> </Card>
) );
} }

202
front/public/quotes.json Normal file
View File

@ -0,0 +1,202 @@
[
{
"quote": "Imagination is more important than knowledge.",
"author": "Albert Einstein"
},
{
"quote": "The important thing is not to stop questioning.",
"author": "Albert Einstein"
},
{
"quote": "If you can't explain it simply, you don't understand it well enough.",
"author": "Albert Einstein"
},
{
"quote": "If I have seen further it is by standing on the shoulders of giants.",
"author": "Isaac Newton"
},
{
"quote": "The present is theirs; the future, for which I really worked, is mine.",
"author": "Nikola Tesla"
},
{
"quote": "Our virtues and our failures are inseparable, like force and matter. When they separate, man is no more.",
"author": "Nikola Tesla"
},
{
"quote": "Nothing in life is to be feared, it is only to be understood.",
"author": "Marie Curie"
},
{
"quote": "One never notices what has been done; one can only see what remains to be done.",
"author": "Marie Curie"
},
{
"quote": "Intelligence is the ability to adapt to change.",
"author": "Stephen Hawking"
},
{
"quote": "However difficult life may seem, there is always something you can do and succeed at.",
"author": "Stephen Hawking"
},
{
"quote": "I learned very early the difference between knowing the name of something and knowing something.",
"author": "Richard Feynman"
},
{
"quote": "The first principle is that you must not fool yourself, and you are the easiest person to fool.",
"author": "Richard Feynman"
},
{
"quote": "Somewhere, something incredible is waiting to be known.",
"author": "Carl Sagan"
},
{
"quote": "Science is more than a body of knowledge; it's a way of thinking.",
"author": "Carl Sagan"
},
{
"quote": "All truths are easy to understand once they are discovered; the point is to discover them.",
"author": "Galileo Galilei"
},
{
"quote": "You cannot teach a man anything; you can only help him find it within himself.",
"author": "Galileo Galilei"
},
{
"quote": "Learning never exhausts the mind.",
"author": "Leonardo da Vinci"
},
{
"quote": "Simplicity is the ultimate sophistication.",
"author": "Leonardo da Vinci"
},
{
"quote": "I have not failed. I've just found 10,000 ways that won't work.",
"author": "Thomas Edison"
},
{
"quote": "Genius is one percent inspiration and ninety-nine percent perspiration.",
"author": "Thomas Edison"
},
{
"quote": "Thoroughly conscious ignorance is the prelude to every real advance in science.",
"author": "James Clerk Maxwell"
},
{
"quote": "Prediction is very difficult, especially if it's about the future.",
"author": "Niels Bohr"
},
{
"quote": "Give me a place to stand, and I shall move the earth.",
"author": "Archimedes"
},
{
"quote": "An investment in knowledge always pays the best interest.",
"author": "Benjamin Franklin"
},
{
"quote": "Tell me and I forget, teach me and I may remember, involve me and I learn.",
"author": "Benjamin Franklin"
},
{
"quote": "In mathematics you don't understand things. You just get used to them.",
"author": "John von Neumann"
},
{
"quote": "The most dangerous phrase in the language is, 'We've always done it this way.'",
"author": "Grace Hopper"
},
{
"quote": "The Analytical Engine weaves algebraic patterns just as the Jacquard loom weaves flowers and leaves.",
"author": "Ada Lovelace"
},
{
"quote": "Science, the product of human curiosity, is our best tool for understanding the universe.",
"author": "Richard Dawkins"
},
{
"quote": "We are all atheists about most of the gods that humanity has ever believed in.",
"author": "Richard Dawkins"
},
{
"quote": "We can only see a short distance ahead, but we can see plenty there that needs to be done.",
"author": "Alan Turing"
},
{
"quote": "Machines take me by surprise with great frequency.",
"author": "Alan Turing"
},
{
"quote": "Mathematics is the queen of the sciences.",
"author": "Carl Friedrich Gauss"
},
{
"quote": "I have had my results for a long time; but I do not yet know how I am to arrive at them.",
"author": "Carl Friedrich Gauss"
},
{
"quote": "Science and everyday life cannot and should not be separated.",
"author": "Rosalind Franklin"
},
{
"quote": "There is nothing in the world of science that does not have its wondrous and awe-inspiring element.",
"author": "Dmitri Mendeleev"
},
{
"quote": "When one door closes, another opens; but we often look so long and so regretfully upon the closed door that we do not see the one which has opened for us.",
"author": "Alexander Graham Bell"
},
{
"quote": "Before anything else, preparation is the key to success.",
"author": "Alexander Graham Bell"
},
{
"quote": "Heat is a mode of motion.",
"author": "James Prescott Joule"
},
{
"quote": "All science is either physics or stamp collecting.",
"author": "Ernest Rutherford"
},
{
"quote": "Equipped with his five senses, man explores the universe around him and calls the adventure science.",
"author": "Edwin Hubble"
},
{
"quote": "Science advances one funeral at a time.",
"author": "Max Planck"
},
{
"quote": "What we observe is not nature itself, but nature exposed to our method of questioning.",
"author": "Werner Heisenberg"
},
{
"quote": "There are no secrets about the world of nature. There are secrets about the thoughts and intentions of men.",
"author": "J. Robert Oppenheimer"
},
{
"quote": "There are two possible outcomes: if the result confirms the hypothesis, then you have made a measurement. If it doesn't, then you have made a discovery.",
"author": "Enrico Fermi"
},
{
"quote": "I am not thinking of all the misery but of the beauty that still remains.",
"author": "Lise Meitner"
},
{
"quote": "Look for the unexpected in the nature of things. There is wonder everywhere.",
"author": "Barbara McClintock"
},
{
"quote": "Nature uses only the longest threads to weave her patterns, so that each small piece of her fabric reveals the organization of the entire tapestry.",
"author": "Richard Feynman"
},
{
"quote": "Of all things, I liked books best.",
"author": "Nikola Tesla"
},
{
"quote": "Life would be tragic if it weren't funny.",
"author": "Stephen Hawking"
}
]