Skip to content

Commit 3c2563b

Browse files
committed
refactor(stats): remove props and unused imports
- remove fontawesome imports from loginform and rely on oauth2 - remove nav profile dropdown import and simplify stats to no props - defer initial fetchstats with settimeout and clear timeout on unmount - simplify d/page to render <stats /> and stop passing user metadata - import metadataroute from "next/types" instead of "next"
1 parent cc4d49f commit 3c2563b

4 files changed

Lines changed: 9 additions & 31 deletions

File tree

app/components/auth/LoginForm.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ import { toast } from "react-toastify";
66
import { useRouter } from "next/navigation";
77
import { useSearchParams } from "next/navigation";
88
import HCaptcha from "@hcaptcha/react-hcaptcha";
9-
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
10-
import {
11-
faGithub,
12-
faGoogle,
13-
faMicrosoft,
14-
} from "@fortawesome/free-brands-svg-icons";
159
import Oauth2 from "./Oauth2";
1610

1711
export default function LoginForm() {

app/components/dashboard/Stats.tsx

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import Machines from "./widgets/Machines";
1616
import Categories from "./widgets/Categories";
1717
import Dependencies from "./widgets/Dependencies";
1818
import CodingConsistencyHeatmap from "./widgets/CodingConsistencyHeatmap";
19-
import NavProfileDropdown from "../common/NavProfileDropdown";
2019

2120
export interface StatsData {
2221
total_seconds: number;
@@ -33,17 +32,7 @@ export interface StatsData {
3332
last_fetched_at?: string;
3433
}
3534

36-
interface StatsProps {
37-
name?: string;
38-
email?: string;
39-
avatar: string | null;
40-
}
41-
42-
export default function Stats({
43-
name = "User",
44-
email = "user@example.com",
45-
avatar = null,
46-
}: StatsProps) {
35+
export default function Stats() {
4736
const toDateKey = (value: string) => value.slice(0, 10);
4837
const parseDateKeyLocal = (dateKey: string) => {
4938
const [y, m, d] = dateKey.split("-").map(Number);
@@ -120,8 +109,12 @@ export default function Stats({
120109
);
121110

122111
useEffect(() => {
123-
// Always fetch fresh data on first load so refresh reflects live values.
124-
void fetchStats(true);
112+
// Defer to avoid synchronous setState inside effect.
113+
const timeout = window.setTimeout(() => {
114+
void fetchStats(true);
115+
}, 0);
116+
117+
return () => window.clearTimeout(timeout);
125118
}, [fetchStats]);
126119

127120
useEffect(() => {

app/d/page.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,5 @@ export default async function Dashboard() {
1515
if (!profile?.wakatime_api_key) {
1616
return <DashboardWithoutKey email={profile?.email || user.email!} />;
1717
}
18-
19-
const email = profile?.email || user.email!;
20-
const name = user?.user_metadata?.name || email.split("@")[0];
21-
const prefferedAvatar =
22-
user?.user_metadata?.avatar_url ||
23-
user?.user_metadata?.picture ||
24-
user?.user_metadata?.avatar ||
25-
null;
26-
27-
return <Stats name={name} email={email} avatar={prefferedAvatar} />;
18+
return <Stats />;
2819
}

app/sitemaps/static.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { MetadataRoute } from "next";
1+
import type { MetadataRoute } from "next/types";
22

33
export default function sitemap(): MetadataRoute.Sitemap {
44
return [

0 commit comments

Comments
 (0)