diff --git a/src/app/(app)/more/page.tsx b/src/app/(app)/more/page.tsx index 9451c59..e26d610 100644 --- a/src/app/(app)/more/page.tsx +++ b/src/app/(app)/more/page.tsx @@ -1,4 +1,5 @@ import { ChevronRight, Sparkles } from "lucide-react"; +import { DonateLink } from "@/components/Donate"; import Link from "next/link"; import { countryOf } from "@/lib/countries"; import { getUser } from "@/lib/data"; @@ -30,6 +31,8 @@ export default async function More() { Connect your AI + {/* The sidebar has this link too; on a phone, More is the only place. */} + ); } diff --git a/src/components/Donate.tsx b/src/components/Donate.tsx new file mode 100644 index 0000000..81265bc --- /dev/null +++ b/src/components/Donate.tsx @@ -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 ( + + + Support broke + + ); +} + +// 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 ( + setOpen(false)}> +
+ +
+

Finding broke useful?

+

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.

+
+ +
+
+ ); +} diff --git a/src/components/Nav.tsx b/src/components/Nav.tsx index 50cc043..9031dbe 100644 --- a/src/components/Nav.tsx +++ b/src/components/Nav.tsx @@ -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() { Ask broke ai + + ); }