Support broke: a donate link and a one-time ask after two hours
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f550865e93
commit
de40f85407
3 files changed
+61
No files matched your search
@@ -0,0 +1,55 @@
|
||||
"use client";
|
||||
|
||||
import { Heart } from "lucide-react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Modal } from "@/components/Modal";
|
||||
|
||||
export const DONATE_URL = "https://buy.stripe.com/5kQ6oHgXWc1T33CbNt5Vu05";
|
||||
const USED = "broke.minutesUsed", ASKED = "broke.donateAsked";
|
||||
const ASK_AFTER = 120; // minutes with broke open and on screen
|
||||
|
||||
const read = (k: string) => { try { return localStorage.getItem(k); } catch { return null; } };
|
||||
const write = (k: string, v: string) => { try { localStorage.setItem(k, v); } catch { /* private window: just don't count */ } };
|
||||
|
||||
export function DonateLink({ className = "" }: { className?: string }) {
|
||||
return (
|
||||
<a href={DONATE_URL} target="_blank" rel="noopener noreferrer" className={className}>
|
||||
<Heart size={18} strokeWidth={1.6} className="shrink-0" />
|
||||
<span className="flex-1 text-left">Support broke</span>
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
||||
// Asks once, after about two hours of use: minutes count only while a broke tab is open and visible, in this browser.
|
||||
export function DonatePrompt() {
|
||||
const [open, setOpen] = useState(false);
|
||||
useEffect(() => {
|
||||
if (read(ASKED)) return;
|
||||
const tick = setInterval(() => {
|
||||
if (document.visibilityState !== "visible") return;
|
||||
const used = Number(read(USED) ?? 0) + 1;
|
||||
write(USED, String(used));
|
||||
if (used < ASK_AFTER || read(ASKED)) return;
|
||||
write(ASKED, new Date().toISOString());
|
||||
setOpen(true);
|
||||
clearInterval(tick);
|
||||
}, 60_000);
|
||||
return () => clearInterval(tick);
|
||||
}, []);
|
||||
if (!open) return null;
|
||||
return (
|
||||
<Modal label="Support broke" onClose={() => setOpen(false)}>
|
||||
<div className="space-y-4">
|
||||
<Heart size={22} strokeWidth={1.6} className="text-muted" />
|
||||
<div className="space-y-1.5">
|
||||
<h2 className="text-lg font-semibold">Finding broke useful?</h2>
|
||||
<p className="text-sm text-muted">broke is free and open source. If it's saved you money, you can chip in to keep it going. This is the only time it asks.</p>
|
||||
</div>
|
||||
<div className="flex gap-3">
|
||||
<a href={DONATE_URL} target="_blank" rel="noopener noreferrer" onClick={() => setOpen(false)} className="btn-primary" data-autofocus>Donate</a>
|
||||
<button className="btn" onClick={() => setOpen(false)}>Not now</button>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import { usePathname, useRouter } from "next/navigation";
|
||||
import { Suspense, useEffect, useState } from "react";
|
||||
import { useAssistant } from "@/components/Assistant";
|
||||
import { BookmarkButton, SavedList } from "@/components/Bookmarks";
|
||||
import { DonateLink, DonatePrompt } from "@/components/Donate";
|
||||
|
||||
// Home is the three steps. Spending holds Budgets and Recurring as tabs, More holds the rest; every page keeps its own URL.
|
||||
type Icon = ComponentType<{ size?: number; strokeWidth?: number }>;
|
||||
@@ -59,8 +60,10 @@ export function Nav() {
|
||||
<MessageCircle size={18} strokeWidth={1.6} />
|
||||
<span className="flex-1 text-left">Ask broke ai</span>
|
||||
</button>
|
||||
<DonateLink className="flex items-center gap-3 px-3 py-2 rounded-xl text-[14px] whitespace-nowrap text-ink/70 hover:text-ink hover:bg-canvas/60" />
|
||||
<Suspense><SavedList /></Suspense>
|
||||
</nav>
|
||||
<DonatePrompt />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user