Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { TbBrandTwitter, TbShare, TbDownload, TbCopy } from "react-icons/tb";
import React, { useRef, useState, useEffect } from "react";
import { useRouter } from "next/router";
import {
download,
fetchData,
Expand All @@ -11,6 +12,7 @@ import {
import ThemeSelector from "../components/themes";

const App = () => {
const router = useRouter();
const inputRef = useRef();
const canvasRef = useRef();
const contentRef = useRef();
Expand All @@ -27,6 +29,33 @@ const App = () => {
draw();
}, [data, theme]);

useEffect(() => {
const queryUsername = router.query.username;
if (queryUsername) {
const cleaned = cleanUsername(queryUsername);
setUsername(cleaned);
setLoading(true);
setError(null);
setData(null);

fetchData(cleaned)
.then((data) => {
setLoading(false);

if (data.years.length === 0) {
setError("Could not find your profile");
} else {
setData(data);
}
})
.catch((err) => {
console.log(err);
setLoading(false);
setError("I could not check your profile successfully...");
});
}
}, [router.query.username]);

const handleSubmit = (e) => {
e.preventDefault();

Expand Down