mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 01:35:39 -04:00
Checks current version against latest GitHub release every 6 hours via cron job, caches result in appSettings, and surfaces updates through a toast notification (once per browser session) and an animated badge in the settings footer. Includes an admin toggle to enable/disable checks (enabled by default). Also renames ServerSection to RegistrationSection now that update checks are in their own card. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
"use client";
|
|
|
|
import { useAtom } from "jotai";
|
|
import { useEffect } from "react";
|
|
import { toast } from "sonner";
|
|
import { updateToastShownAtom } from "@/lib/atoms/update-check";
|
|
|
|
export function UpdateToast() {
|
|
const [shown, setShown] = useAtom(updateToastShownAtom);
|
|
|
|
useEffect(() => {
|
|
if (shown) return;
|
|
|
|
async function check() {
|
|
try {
|
|
const res = await fetch("/api/admin/update-check");
|
|
if (!res.ok) return;
|
|
|
|
const data = (await res.json()) as {
|
|
updateAvailable: boolean;
|
|
currentVersion: string;
|
|
latestVersion: string | null;
|
|
releaseUrl: string | null;
|
|
};
|
|
|
|
if (data.updateAvailable) {
|
|
setShown(true);
|
|
toast.info(`Sofa v${data.latestVersion} is available`, {
|
|
description: `You're running v${data.currentVersion}.`,
|
|
duration: 15_000,
|
|
action: data.releaseUrl
|
|
? {
|
|
label: "View release",
|
|
onClick: () =>
|
|
window.open(data.releaseUrl as string, "_blank"),
|
|
}
|
|
: undefined,
|
|
});
|
|
}
|
|
} catch {
|
|
// Silently ignore network errors
|
|
}
|
|
}
|
|
|
|
check();
|
|
}, [shown, setShown]);
|
|
|
|
return null;
|
|
}
|