Skip to content

Commit

Permalink
Merge pull request #152 from shamvrueth/feature/copy-confirmation
Browse files Browse the repository at this point in the history
Added copy confirmation and loading state
  • Loading branch information
TenzDelek authored Oct 25, 2024
2 parents 19c4587 + 18c92a9 commit fadb280
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/app/daily-quote/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default function DailyQuote() {
const [quote, setQuote] = useState("Loading...");
const [author, setAuthor] = useState("Anonymous");
const [error, setError] = useState();
const [copied, setCopied] = useState(false);

useEffect(() => {
async function fetchData() {
Expand All @@ -24,13 +25,16 @@ export default function DailyQuote() {
}, []);

const getNewQuote = async () => {
setQuote("Loading...");
setCopied(false);
const response = await axios.get("/api/quote");
setQuote(response.data[0].q);
setAuthor(response.data[0].a);
};

const copyQuote = async () => {
await navigator.clipboard.writeText(`${quote} - ${author}`);
setCopied(true);
};

return (
Expand Down Expand Up @@ -68,6 +72,7 @@ export default function DailyQuote() {
<RiFileCopyLine className="w-5 h-5" /> <span>Copy</span>
</button>
</div>
{copied && <p className="text-green-300 text-center mt-8">Copied successfully!</p>}
</div>

<footer className="text-center text-sm text-gray-500 mt-16">
Expand Down

0 comments on commit fadb280

Please sign in to comment.