Skip to content

Commit 6de1c6f

Browse files
committed
re-add GitHub star modal on first load
1 parent bdd7922 commit 6de1c6f

2 files changed

Lines changed: 113 additions & 0 deletions

File tree

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
'use client';
2+
3+
import { track } from '@/lib/analytics';
4+
import { Star } from 'lucide-react';
5+
import { useCallback, useEffect, useState } from 'react';
6+
7+
import { GITHUB_OWNER, GITHUB_REPO } from '@semianalysisai/inferencex-constants';
8+
import { Button } from '@/components/ui/button';
9+
import {
10+
Dialog,
11+
DialogContent,
12+
DialogDescription,
13+
DialogFooter,
14+
DialogHeader,
15+
DialogTitle,
16+
} from '@/components/ui/dialog';
17+
18+
const GITHUB_REPO_URL = `https://github.com/${GITHUB_OWNER}/${GITHUB_REPO}`;
19+
export const STORAGE_KEY = 'inferencex-star-modal-dismissed';
20+
export const DISMISS_DURATION_MS = 7 * 24 * 60 * 60 * 1000; // 1 week
21+
22+
export function shouldShowModal(): boolean {
23+
try {
24+
const value = localStorage.getItem(STORAGE_KEY);
25+
if (!value) return true;
26+
const dismissedAt = Number(value);
27+
if (Number.isNaN(dismissedAt)) return true;
28+
return Date.now() - dismissedAt >= DISMISS_DURATION_MS;
29+
} catch {
30+
return false;
31+
}
32+
}
33+
34+
export function saveDismissTimestamp(): void {
35+
try {
36+
localStorage.setItem(STORAGE_KEY, String(Date.now()));
37+
} catch {
38+
// localStorage unavailable
39+
}
40+
}
41+
42+
export function GitHubStarModal() {
43+
const [open, setOpen] = useState(false);
44+
const [ready, setReady] = useState(false);
45+
46+
useEffect(() => {
47+
if (shouldShowModal()) {
48+
setOpen(true);
49+
track('github_star_modal_shown');
50+
}
51+
setReady(true);
52+
}, []);
53+
54+
const handleDismiss = useCallback(() => {
55+
setOpen(false);
56+
saveDismissTimestamp();
57+
track('github_star_modal_dismissed');
58+
}, []);
59+
60+
const handleStar = useCallback(() => {
61+
window.open(GITHUB_REPO_URL, '_blank', 'noopener,noreferrer');
62+
setOpen(false);
63+
saveDismissTimestamp();
64+
track('github_star_modal_starred');
65+
}, []);
66+
67+
return (
68+
<>
69+
{ready && <span data-testid="star-modal-ready" hidden aria-hidden="true" />}
70+
<Dialog open={open} onOpenChange={(value) => !value && handleDismiss()}>
71+
<DialogContent data-testid="github-star-modal" className="sm:max-w-md">
72+
<DialogHeader>
73+
<DialogTitle className="flex items-center gap-2">
74+
<Star className="h-5 w-5 text-yellow-500 fill-yellow-500" />
75+
Star InferenceX on GitHub
76+
</DialogTitle>
77+
<DialogDescription>
78+
Star InferenceX on GitHub to get notified when we publish new benchmark data. We
79+
update GPU performance comparisons regularly — starring is the easiest way to stay in
80+
the loop and help the project grow.
81+
</DialogDescription>
82+
</DialogHeader>
83+
<DialogFooter className="flex-row gap-2 sm:gap-0">
84+
<Button
85+
variant="outline"
86+
onClick={handleDismiss}
87+
data-testid="github-star-modal-dismiss"
88+
>
89+
Maybe Later
90+
</Button>
91+
<Button
92+
onClick={handleStar}
93+
data-testid="github-star-modal-star"
94+
className="star-button-glow"
95+
>
96+
<svg
97+
xmlns="http://www.w3.org/2000/svg"
98+
viewBox="0 0 16 16"
99+
fill="currentColor"
100+
className="w-4 h-4"
101+
>
102+
<path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z" />
103+
</svg>
104+
Star on GitHub
105+
</Button>
106+
</DialogFooter>
107+
</DialogContent>
108+
</Dialog>
109+
</>
110+
);
111+
}

packages/app/src/components/page-content.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { GpuSpecsContent } from '@/components/gpu-specs/gpu-specs-content';
1010
import GpuMetricsDisplay from '@/components/gpu-power/GpuPowerDisplay';
1111
import HistoricalTrendsDisplay from '@/components/trends/HistoricalTrendsDisplay';
1212
import { ExportNudge } from '@/components/export-nudge';
13+
import { GitHubStarModal } from '@/components/github-star-modal';
1314
import { StarNudge } from '@/components/star-nudge';
1415
import { InferenceProvider } from '@/components/inference/InferenceContext';
1516
import InferenceChartDisplay from '@/components/inference/ui/ChartDisplay';
@@ -244,6 +245,7 @@ function ChartTabs({ initialTab }: { initialTab: string }) {
244245
export function PageContent({ initialTab = 'inference' }: { initialTab?: string }) {
245246
return (
246247
<>
248+
<GitHubStarModal />
247249
<StarNudge />
248250
<ExportNudge />
249251
<UnofficialRunProvider>

0 commit comments

Comments
 (0)