feat: build production-ready wtr weather PWA

This commit is contained in:
zv
2026-06-01 18:43:56 +02:00
commit 840555f4f5
60 changed files with 9052 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
"use client";
import { useEffect, useState } from "react";
import { Download } from "lucide-react";
import { Button } from "@/components/ui/button";
interface BeforeInstallPromptEvent extends Event {
prompt: () => Promise<void>;
userChoice: Promise<{ outcome: "accepted" | "dismissed" }>;
}
export function InstallPWAButton() {
const [event, setEvent] = useState<BeforeInstallPromptEvent | null>(null);
useEffect(() => {
const handlePrompt = (promptEvent: Event) => {
promptEvent.preventDefault();
setEvent(promptEvent as BeforeInstallPromptEvent);
};
window.addEventListener("beforeinstallprompt", handlePrompt);
return () => window.removeEventListener("beforeinstallprompt", handlePrompt);
}, []);
if (!event) return null;
return (
<Button
variant="glass"
onClick={async () => {
await event.prompt();
await event.userChoice;
setEvent(null);
}}
>
<Download className="size-4" />
Zainstaluj
</Button>
);
}