Your favorite shift management application!
feat: Adds update checks and changelog UI (#65)
panteL963e02080a8c
diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.mdindex 8e3141f..abdd92c 100644--- a/.github/copilot-instructions.md+++ b/.github/copilot-instructions.md@@ -145,9 +145,10 @@ Main page (`app/page.tsx`) patterns:next-intl setup with auto-detection:- Cookie `NEXT_LOCALE` overrides browser preference (`lib/i18n.ts`)-- Translations: `messages/{de,en}.json`+- Translations: `messages/{de,en,it}.json` (German, English, Italian)- Usage: `const t = useTranslations()` → `t("shift.create")`-- Date formatting: `locale === "de" ? de : enUS`+- Date formatting: `locale === "de" ? de : (locale === "it" ? it : enUS)`+- **Important**: When adding new translation keys, ALWAYS add them to all three files (de.json, en.json, it.json)**Translation Structure (Optimized)**:diff --git a/app/api/releases/route.ts b/app/api/releases/route.tsnew file mode 100644index 0000000..81e159c--- /dev/null+++ b/app/api/releases/route.ts@@ -0,0 +1,58 @@+import { NextResponse } from "next/server";++const GITHUB_REPO_OWNER = process.env.GITHUB_REPO_OWNER || "panteLx";+const GITHUB_REPO_NAME = process.env.GITHUB_REPO_NAME || "BetterShift";+const GITHUB_TOKEN = process.env.GITHUB_TOKEN;++// Unified cache duration: 15 minutes+const CACHE_SECONDS = 15 * 60; // 15 minutes++export interface GitHubRelease {+ id: number;+ tag_name: string;+ name: string;+ body: string;+ created_at: string;+ published_at: string;+ html_url: string;+ draft: boolean;+ prerelease: boolean;+}++export async function GET() {+ try {+ const response = await fetch(+ `https://api.github.com/repos/${GITHUB_REPO_OWNER}/${GITHUB_REPO_NAME}/releases`,+ {+ headers: {+ Accept: "application/vnd.github.v3+json",+ ...(GITHUB_TOKEN && { Authorization: `Bearer ${GITHUB_TOKEN}` }),+ },+ next: { revalidate: CACHE_SECONDS },+ }+ );++ if (!response.ok) {+ throw new Error(`GitHub API error: ${response.status}`);+ }++ const releases: GitHubRelease[] = await response.json();++ // Filter out drafts and prereleases+ const publicReleases = releases.filter(+ (release) => !release.draft && !release.prerelease+ );++ return NextResponse.json(publicReleases, {+ headers: {+ "Cache-Control": `public, max-age=${CACHE_SECONDS}`,+ },+ });+ } catch (error) {+ console.error("Failed to fetch releases:", error);+ return NextResponse.json(+ { error: "Failed to fetch releases" },+ { status: 500 }+ );+ }+}diff --git a/app/api/version/route.ts b/app/api/version/route.tsindex 8817697..79e7ec0 100644--- a/app/api/version/route.ts+++ b/app/api/version/route.ts@@ -2,6 +2,14 @@ import { NextResponse } from "next/server";import { readFileSync, existsSync } from "fs";import { join } from "path";+/**+ * Cache Strategy: 15 minutes unified across all version/release endpoints+ * - Server-side cache (cachedVersion): 15 minutes+ * - HTTP Cache-Control: 15 minutes+ * - GitHub API revalidation: 15 minutes+ * - Client polling interval: 15 minutes+ */+// Cache version infolet cachedVersion: {version: string;@@ -9,11 +17,19 @@ let cachedVersion: {timestamp: number;} | null = null;+// Cache latest release info+let cachedLatestRelease: {+ version: string;+ url: string;+} | null = null;+let cachedLatestReleaseExpiresAt = 0;+let cachedDockerVersion: string | null = null;let cachedPackageVersion = "";-const CACHE_DURATION = 3600 * 1000; // 1 hour-const CACHE_SECONDS = 3600;+// Unified cache duration: 15 minutes+const CACHE_DURATION = 15 * 60 * 1000; // 15 minutes+const CACHE_SECONDS = 15 * 60; // 15 minutesconst GITHUB_REPO_OWNER = process.env.GITHUB_REPO_OWNER || "panteLx";const GITHUB_REPO_NAME = process.env.GITHUB_REPO_NAME || "BetterShift";@@ -99,6 +115,69 @@ function buildGitHubUrl(version: string, commitHash: string): string {return baseUrl;}+async function getLatestRelease(): Promise<{+ version: string;+ url: string;+} | null> {+ // Return cached release if still valid+ if (cachedLatestRelease && Date.now() < cachedLatestReleaseExpiresAt) {+ return cachedLatestRelease;+ }++ try {+ const response = await fetch(+ `https://api.github.com/repos/${GITHUB_REPO_OWNER}/${GITHUB_REPO_NAME}/releases/latest`,+ {+ headers: {+ Accept: "application/vnd.github.v3+json",+ ...(GITHUB_TOKEN && { Authorization: `Bearer ${GITHUB_TOKEN}` }),+ },+ next: { revalidate: CACHE_SECONDS },+ }+ );++ if (!response.ok) {+ return null;+ }++ const data = await response.json();+ const release = {+ version: data.tag_name.replace(/^v/, ""), // Remove 'v' prefix+ url: data.html_url,+ };++ // Cache the fetched release+ cachedLatestRelease = release;+ cachedLatestReleaseExpiresAt = Date.now() + CACHE_DURATION;++ return release;+ } catch (error) {+ console.error("Failed to fetch latest release:", error);+ return null;+ }+}++function compareVersions(current: string, latest: string): boolean {+ // Returns true if latest is newer than current+ const parseCurrent = current.split(".").map(Number);+ const parseLatest = latest.split(".").map(Number);++ for (let i = 0; i < 3; i++) {+ const curr = parseCurrent[i] || 0;+ const lat = parseLatest[i] || 0;++ if (lat > curr) return true;+ if (lat < curr) return false;+ }++ return false;+}++function isDevVersion(version: string): boolean {+ // Check if version contains 'dev' or if it's a Docker :dev tag+ return version.includes("dev") || version === "dev";+}+export async function GET() {// Check cacheif (cachedVersion && Date.now() - cachedVersion.timestamp < CACHE_DURATION) {@@ -106,11 +185,26 @@ export async function GET() {cachedVersion.version,cachedVersion.commitHash);++ // Get latest release for update check (only if not dev version)+ const isDev = isDevVersion(cachedVersion.version);+ const latestRelease = !isDev ? await getLatestRelease() : null;+ const hasUpdate =+ latestRelease &&+ !isDev &&+ compareVersions(cachedVersion.version, latestRelease.version);+return NextResponse.json({version: cachedVersion.version,commitHash: cachedVersion.commitHash,githubUrl,+ isDev,+ ...(latestRelease && {+ latestVersion: latestRelease.version,+ latestUrl: latestRelease.url,+ hasUpdate,+ }),},{headers: {@@ -133,11 +227,23 @@ export async function GET() {const githubUrl = buildGitHubUrl(version, commitHash);+ // Get latest release for update check (only if not dev version)+ const isDev = isDevVersion(version);+ const latestRelease = !isDev ? await getLatestRelease() : null;+ const hasUpdate =+ latestRelease && !isDev && compareVersions(version, latestRelease.version);+return NextResponse.json({version,commitHash,githubUrl,+ isDev,+ ...(latestRelease && {+ latestVersion: latestRelease.version,+ latestUrl: latestRelease.url,+ hasUpdate,+ }),},{headers: {diff --git a/components/app-footer.tsx b/components/app-footer.tsxindex 9e127ab..8e7b141 100644--- a/components/app-footer.tsx+++ b/components/app-footer.tsx@@ -1,9 +1,12 @@"use client";import { useTranslations } from "next-intl";-import { Coffee, Github } from "lucide-react";+import { Heart, ExternalLink, FileText } from "lucide-react";import { LanguageSwitcher } from "./language-switcher";import { ThemeSwitcher } from "./theme-switcher";+import { useState } from "react";+import { ChangelogDialog } from "./changelog-dialog";+import { useLocale } from "next-intl";interface VersionInfo {version: string;@@ -17,6 +20,8 @@ interface AppFooterProps {export function AppFooter({ versionInfo }: AppFooterProps) {const t = useTranslations();+ const locale = useLocale();+ const [showChangelog, setShowChangelog] = useState(false);// Format version display based on version typeconst displayVersion =@@ -25,63 +30,79 @@ export function AppFooter({ versionInfo }: AppFooterProps) {: versionInfo?.version;return (- <footer className="border-t bg-background mt-auto">- <div className="container max-w-4xl mx-auto p-3 sm:p-4">- {/* Mobile: Two rows (language + links), Desktop: One row */}- <div className="flex flex-col gap-2 sm:flex-row sm:justify-between sm:items-center sm:gap-4">- {/* Language and theme switcher */}- <div className="flex justify-center sm:justify-start items-center gap-2">- <LanguageSwitcher />- <ThemeSwitcher />- </div>+ <>+ <footer className="border-t bg-background mt-auto">+ <div className="container max-w-4xl mx-auto p-3 sm:p-4">+ {/* Mobile: Two rows (language + links), Desktop: One row */}+ <div className="flex flex-col gap-2 sm:flex-row sm:justify-between sm:items-center sm:gap-4">+ {/* Language and theme switcher */}+ <div className="flex justify-center sm:justify-start items-center gap-2">+ <LanguageSwitcher />+ <ThemeSwitcher />+ </div>- {/* Links row - horizontal on all screen sizes */}- <div className="flex flex-row items-center justify-center sm:justify-end gap-3 sm:gap-4 text-xs">- {/* Version info */}- {versionInfo && (+ {/* Links row - horizontal on all screen sizes */}+ <div className="flex flex-row items-center justify-center sm:justify-end gap-3 sm:gap-4 text-xs">+ {/* Version info */}+ {versionInfo && (+ <a+ href={versionInfo.githubUrl}+ target="_blank"+ rel="noopener noreferrer"+ className="text-muted-foreground hover:text-foreground transition-colors font-mono whitespace-nowrap"+ title={+ versionInfo.commitHash+ ? `${t("footer.version")}: ${versionInfo.version} (${+ versionInfo.commitHash+ })`+ : `${t("footer.version")}: ${versionInfo.version}`+ }+ >+ {t("footer.version")}: {displayVersion}+ </a>+ )}+ {/* Changelog link */}+ <button+ onClick={() => setShowChangelog(true)}+ className="flex items-center gap-1.5 text-muted-foreground hover:text-foreground transition-colors cursor-pointer"+ title={t("changelog.title")}+ >+ <FileText className="w-4 h-4" />+ <span className="hidden sm:inline">{t("changelog.title")}</span>+ </button>+ {/* GitHub repo link */}<a- href={versionInfo.githubUrl}+ href="https://github.com/panteLx/BetterShift"target="_blank"rel="noopener noreferrer"- className="text-muted-foreground hover:text-foreground transition-colors font-mono whitespace-nowrap"- title={- versionInfo.commitHash- ? `${t("footer.version")}: ${versionInfo.version} (${- versionInfo.commitHash- })`- : `${t("footer.version")}: ${versionInfo.version}`- }+ className="flex items-center gap-1.5 text-muted-foreground hover:text-foreground transition-colors"+ title={t("footer.github")}>- {t("footer.version")}: {displayVersion}+ <ExternalLink className="w-4 h-4" />+ <span className="hidden sm:inline">{t("footer.github")}</span></a>- )}-- {/* GitHub repo link */}- <a- href="https://github.com/panteLx/BetterShift"- target="_blank"- rel="noopener noreferrer"- className="flex items-center gap-1.5 text-muted-foreground hover:text-foreground transition-colors"- title={t("footer.github")}- >- <Github className="w-4 h-4" />- <span className="hidden sm:inline">{t("footer.github")}</span>- </a>-- {/* Buy Me a Coffee link */}- <a- href="https://buymeacoffee.com/pantelx"- target="_blank"- rel="noopener noreferrer"- className="flex items-center gap-1.5 text-muted-foreground hover:text-amber-500 transition-colors"- title={t("footer.support")}- >- <Coffee className="w-4 h-4" />- <span className="hidden sm:inline">{t("footer.support")}</span>- </a>+ {/* Buy Me a Coffee link */}+ <a+ href="https://buymeacoffee.com/pantelx"+ target="_blank"+ rel="noopener noreferrer"+ className="flex items-center gap-1.5 text-muted-foreground hover:text-amber-500 transition-colors"+ title={t("footer.support")}+ >+ <Heart className="w-4 h-4" />+ <span className="hidden sm:inline">{t("footer.support")}</span>+ </a>+ </div></div></div>- </div>- </footer>+ </footer>++ {/* Changelog Dialog */}+ <ChangelogDialog+ open={showChangelog}+ onOpenChange={setShowChangelog}+ locale={locale}+ />+ </>);}diff --git a/components/app-header.tsx b/components/app-header.tsxindex 3bd0581..67cca02 100644--- a/components/app-header.tsx+++ b/components/app-header.tsx@@ -1,5 +1,6 @@import { motion } from "motion/react";import { useTranslations } from "next-intl";+import { useState } from "react";import { CalendarWithCount } from "@/lib/types";import { CalendarSelector } from "@/components/calendar-selector";import { PresetSelector } from "@/components/preset-selector";@@ -11,8 +12,17 @@ import {DialogTitle,DialogDescription,} from "@/components/ui/dialog";-import { Calendar as CalendarIcon, Plus, Settings2 } from "lucide-react";+import {+ Calendar as CalendarIcon,+ Plus,+ Settings2,+ Bell,+ ExternalLink,+} from "lucide-react";import { ShiftPreset } from "@/lib/db/schema";+import { useVersionUpdateCheck } from "@/hooks/useVersionUpdate";+import { ChangelogDialog } from "@/components/changelog-dialog";+import { useLocale } from "next-intl";interface AppHeaderProps {calendars: CalendarWithCount[];@@ -64,6 +74,9 @@ export function AppHeader({presetsLoading = false,}: AppHeaderProps) {const t = useTranslations();+ const locale = useLocale();+ const { versionInfo } = useVersionUpdateCheck();+ const [showChangelog, setShowChangelog] = useState(false);return (<>@@ -142,6 +155,46 @@ export function AppHeader({</motion.div></div>+ {/* Update Notification Banner - Desktop & Mobile */}+ {versionInfo?.hasUpdate && !versionInfo.isDev && (+ <motion.div+ initial={{ opacity: 0, y: -10 }}+ animate={{ opacity: 1, y: 0 }}+ transition={{ duration: 0.3, delay: 0.15 }}+ className="relative"+ >+ <button+ onClick={() => setShowChangelog(true)}+ className="w-full bg-gradient-to-r from-primary/10 via-primary/5 to-primary/10 backdrop-blur-sm border border-primary/30 rounded-xl p-3 sm:p-3.5 flex items-center justify-between gap-3 hover:from-primary/15 hover:via-primary/10 hover:to-primary/15 hover:border-primary/40 transition-all shadow-sm hover:shadow-md active:scale-[0.99] group"+ >+ <div className="flex items-center gap-2.5 sm:gap-3 flex-1 min-w-0">+ <div className="relative shrink-0 w-9 h-9 sm:w-10 sm:h-10 rounded-lg bg-primary/10 flex items-center justify-center group-hover:bg-primary/15 transition-colors">+ <Bell className="h-4 w-4 sm:h-5 sm:w-5 text-primary group-hover:scale-110 transition-transform" />+ <div className="absolute -top-0.5 -right-0.5 w-2.5 h-2.5 bg-primary rounded-full animate-pulse shadow-sm"></div>+ </div>+ <div className="text-left flex-1 min-w-0">+ <p className="text-sm sm:text-base font-semibold text-primary mb-0.5">+ {t("update.available")}+ </p>+ <p className="text-xs sm:text-sm text-muted-foreground font-medium">+ {t("update.newVersion", {+ version: versionInfo.latestVersion || "unknown",+ })}+ </p>+ </div>+ </div>+ <div className="shrink-0 flex items-center gap-2 text-primary">+ <span className="text-xs sm:text-sm font-medium hidden sm:inline">+ {t("update.viewChangelog")}+ </span>+ <div className="w-8 h-8 rounded-lg bg-primary/10 flex items-center justify-center group-hover:bg-primary/15 transition-colors">+ <ExternalLink className="h-4 w-4 group-hover:rotate-12 transition-transform" />+ </div>+ </div>+ </button>+ </motion.div>+ )}+{/* Mobile: Logo Icon + Calendar Card + Add Button */}<div className="sm:hidden flex items-center gap-2">{/* Logo Icon Only */}@@ -304,6 +357,13 @@ export function AppHeader({</div></DialogContent></Dialog>++ {/* Changelog Dialog */}+ <ChangelogDialog+ open={showChangelog}+ onOpenChange={setShowChangelog}+ locale={locale}+ /></>);}diff --git a/components/calendar-selector.tsx b/components/calendar-selector.tsxindex aeed262..c913280 100644--- a/components/calendar-selector.tsx+++ b/components/calendar-selector.tsx@@ -178,7 +178,7 @@ export function CalendarSelector({size="sm"variant="outline"className="h-9"- title={t("externalSync.manage")}+ title={t("externalSync.manageTitle")}><Cloud className="h-4 w-4" /></Button>diff --git a/components/changelog-dialog.tsx b/components/changelog-dialog.tsxnew file mode 100644index 0000000..1c381b8--- /dev/null+++ b/components/changelog-dialog.tsx@@ -0,0 +1,418 @@+"use client";++import { useEffect, useState, Fragment, ReactNode } from "react";+import { useTranslations } from "next-intl";+import {+ Dialog,+ DialogContent,+ DialogHeader,+ DialogTitle,+ DialogDescription,+} from "@/components/ui/dialog";+import { Loader2, ExternalLink, Calendar, Tag } from "lucide-react";+import { Button } from "@/components/ui/button";+import { format } from "date-fns";+import { de, enUS, it } from "date-fns/locale";++interface GitHubRelease {+ id: number;+ tag_name: string;+ name: string;+ body: string;+ created_at: string;+ published_at: string;+ html_url: string;+ draft: boolean;+ prerelease: boolean;+}++interface ChangelogDialogProps {+ open: boolean;+ onOpenChange: (open: boolean) => void;+ locale: string;+}++export function ChangelogDialog({+ open,+ onOpenChange,+ locale,+}: ChangelogDialogProps) {+ const t = useTranslations();+ const [releases, setReleases] = useState<GitHubRelease[]>([]);+ const [loading, setLoading] = useState(true);++ useEffect(() => {+ if (open) {+ fetchReleases();+ }+ }, [open]);++ const fetchReleases = async () => {+ setLoading(true);+ try {+ const response = await fetch("/api/releases");+ if (response.ok) {+ const data = await response.json();+ setReleases(data);+ }+ } catch (error) {+ console.error("Failed to fetch releases:", error);+ } finally {+ setLoading(false);+ }+ };++ const formatDate = (dateString: string) => {+ const date = new Date(dateString);+ return format(date, "PPP", {+ locale: locale === "de" ? de : locale === "it" ? it : enUS,+ });+ };++ // Sanitize and validate URLs to prevent XSS+ const sanitizeUrl = (url: string): string | null => {+ try {+ const parsed = new URL(url, window.location.href);+ // Only allow http, https, and data:image URLs+ if (+ parsed.protocol === "http:" ||+ parsed.protocol === "https:" ||+ (parsed.protocol === "data:" && url.startsWith("data:image/"))+ ) {+ return parsed.href;+ }+ return null;+ } catch {+ return null;+ }+ };++ // Parse inline markdown elements (bold, code, links) into React elements+ const parseInlineMarkdown = (text: string): ReactNode[] => {+ const elements: ReactNode[] = [];+ let currentText = "";+ let index = 0;+ let key = 0;++ const flushText = () => {+ if (currentText) {+ elements.push(<Fragment key={`text-${key++}`}>{currentText}</Fragment>);+ currentText = "";+ }+ };++ while (index < text.length) {+ // Auto-link URLs+ const urlMatch = text+ .slice(index)+ .match(/^https?:\/\/[^\s<]+[^\s<.,;:!?"')]/);+ if (urlMatch) {+ flushText();+ const url = urlMatch[0];+ const sanitized = sanitizeUrl(url);+ if (sanitized) {+ elements.push(+ <a+ key={`link-${key++}`}+ href={sanitized}+ target="_blank"+ rel="noopener noreferrer"+ className="text-primary hover:underline font-medium break-all"+ >+ {url}+ </a>+ );+ } else {+ currentText += url;+ }+ index += url.length;+ continue;+ }++ // Markdown links [text](url)+ const linkMatch = text.slice(index).match(/^\[([^\]]+)\]\(([^)]+)\)/);+ if (linkMatch) {+ flushText();+ const linkText = linkMatch[1];+ const linkUrl = linkMatch[2];+ const sanitized = sanitizeUrl(linkUrl);+ if (sanitized) {+ elements.push(+ <a+ key={`link-${key++}`}+ href={sanitized}+ target="_blank"+ rel="noopener noreferrer"+ className="text-primary hover:underline font-medium"+ >+ {linkText}+ </a>+ );+ } else {+ currentText += linkText;+ }+ index += linkMatch[0].length;+ continue;+ }++ // Bold **text**+ const boldMatch = text.slice(index).match(/^\*\*([^*]+)\*\*/);+ if (boldMatch) {+ flushText();+ elements.push(+ <strong+ key={`bold-${key++}`}+ className="font-semibold text-foreground"+ >+ {boldMatch[1]}+ </strong>+ );+ index += boldMatch[0].length;+ continue;+ }++ // Inline code `text`+ const codeMatch = text.slice(index).match(/^`([^`]+)`/);+ if (codeMatch) {+ flushText();+ elements.push(+ <code+ key={`code-${key++}`}+ className="px-1.5 py-0.5 rounded bg-muted/80 text-xs font-mono text-foreground whitespace-nowrap"+ >+ {codeMatch[1]}+ </code>+ );+ index += codeMatch[0].length;+ continue;+ }++ // Regular character+ currentText += text[index];+ index++;+ }++ flushText();+ return elements;+ };++ // Parse markdown text into React elements+ const parseMarkdown = (text: string): ReactNode[] => {+ const lines = text.split("\n");+ const elements: ReactNode[] = [];+ let listItems: ReactNode[] = [];+ let inCodeBlock = false;+ let codeBlockLines: string[] = [];+ let elementKey = 0;++ const flushList = () => {+ if (listItems.length > 0) {+ elements.push(+ <ul+ key={`list-${elementKey++}`}+ className="list-disc ml-6 space-y-1 my-2"+ >+ {listItems}+ </ul>+ );+ listItems = [];+ }+ };++ for (let i = 0; i < lines.length; i++) {+ const line = lines[i];++ // Code blocks (```)+ if (line.startsWith("```")) {+ flushList();+ if (inCodeBlock) {+ // Close code block+ elements.push(+ <pre+ key={`code-${elementKey++}`}+ className="bg-muted/50 border border-border/50 rounded-lg p-4 my-3 overflow-x-auto"+ >+ <code className="text-sm font-mono text-foreground block">+ {codeBlockLines.join("\n")}+ </code>+ </pre>+ );+ codeBlockLines = [];+ inCodeBlock = false;+ } else {+ inCodeBlock = true;+ }+ continue;+ }++ // Inside code block+ if (inCodeBlock) {+ codeBlockLines.push(line);+ continue;+ }++ // Headers+ if (line.startsWith("### ")) {+ flushList();+ elements.push(+ <h4+ key={`h4-${elementKey++}`}+ className="text-base font-semibold mt-4 mb-2 text-foreground"+ >+ {parseInlineMarkdown(line.slice(4))}+ </h4>+ );+ continue;+ }+ if (line.startsWith("## ")) {+ flushList();+ elements.push(+ <h3+ key={`h3-${elementKey++}`}+ className="text-lg font-semibold mt-5 mb-3 text-foreground"+ >+ {parseInlineMarkdown(line.slice(3))}+ </h3>+ );+ continue;+ }+ if (line.startsWith("# ")) {+ flushList();+ elements.push(+ <h2+ key={`h2-${elementKey++}`}+ className="text-xl font-bold mt-6 mb-4 text-foreground"+ >+ {parseInlineMarkdown(line.slice(2))}+ </h2>+ );+ continue;+ }++ // Bullet points+ if (line.startsWith("- ") || line.startsWith("* ")) {+ const content = line.slice(2);+ listItems.push(+ <li+ key={`li-${elementKey++}`}+ className="text-sm text-muted-foreground leading-relaxed"+ >+ {parseInlineMarkdown(content)}+ </li>+ );+ continue;+ }++ // Close list if we're in one and hit a non-list line+ if (listItems.length > 0) {+ flushList();+ }++ // Empty lines+ if (line.trim() === "") {+ elements.push(<div key={`space-${elementKey++}`} className="h-2" />);+ continue;+ }++ // Regular paragraphs+ elements.push(+ <p+ key={`p-${elementKey++}`}+ className="text-sm text-muted-foreground my-1"+ >+ {parseInlineMarkdown(line)}+ </p>+ );+ }++ // Close list if still open at end+ flushList();++ // Close code block if still open at end+ if (inCodeBlock) {+ elements.push(+ <pre+ key={`code-${elementKey++}`}+ className="bg-muted/50 border border-border/50 rounded-lg p-4 my-3 overflow-x-auto"+ >+ <code className="text-sm font-mono text-foreground block">+ {codeBlockLines.join("\n")}+ </code>+ </pre>+ );+ }++ return elements;+ };++ return (+ <Dialog open={open} onOpenChange={onOpenChange}>+ <DialogContent className="sm:max-w-[700px] max-w-[95vw] max-h-[85vh] flex flex-col p-0 gap-0 border border-border/50 bg-gradient-to-b from-background via-background to-muted/30 backdrop-blur-xl shadow-2xl">+ <DialogHeader className="border-b border-border/50 bg-gradient-to-r from-primary/10 via-primary/5 to-transparent p-6 pb-5 space-y-1.5">+ <DialogTitle className="text-xl font-semibold bg-gradient-to-r from-foreground to-foreground/70 bg-clip-text flex items-center gap-2">+ <ExternalLink className="h-5 w-5" />+ {t("changelog.title")}+ </DialogTitle>+ <DialogDescription className="text-sm text-muted-foreground">+ {t("changelog.description")}+ </DialogDescription>+ </DialogHeader>+ <div className="overflow-y-auto flex-1 px-6 pb-6">+ {loading ? (+ <div className="flex items-center justify-center py-12">+ <Loader2 className="h-8 w-8 animate-spin text-muted-foreground" />+ </div>+ ) : releases.length === 0 ? (+ <div className="text-center py-12 text-muted-foreground">+ {t("changelog.noReleases")}+ </div>+ ) : (+ <div className="space-y-6 mt-6">+ {releases.map((release) => (+ <div+ key={release.id}+ className="border border-border/50 rounded-lg p-4 bg-gradient-to-br from-background to-muted/20 hover:border-border transition-colors"+ >+ <div className="flex items-start justify-between gap-4 mb-3">+ <div className="flex-1">+ <div className="flex items-center gap-2 mb-1">+ <Tag className="h-4 w-4 text-primary" />+ <h3 className="text-lg font-semibold text-foreground">+ {release.name || release.tag_name}+ </h3>+ </div>+ <div className="flex items-center gap-2 text-xs text-muted-foreground">+ <Calendar className="h-3 w-3" />+ {formatDate(release.published_at)}+ </div>+ </div>+ <Button+ variant="outline"+ size="sm"+ onClick={() =>+ window.open(+ release.html_url,+ "_blank",+ "noopener,noreferrer"+ )+ }+ className="shrink-0"+ >+ <ExternalLink className="h-4 w-4 mr-1.5" />+ {t("changelog.viewOnGitHub")}+ </Button>+ </div>+ {release.body && (+ <div className="prose prose-sm max-w-none dark:prose-invert">+ {parseMarkdown(release.body)}+ </div>+ )}+ </div>+ ))}+ </div>+ )}+ </div>+ </DialogContent>+ </Dialog>+ );+}diff --git a/hooks/useVersionUpdate.ts b/hooks/useVersionUpdate.tsnew file mode 100644index 0000000..fa277cf--- /dev/null+++ b/hooks/useVersionUpdate.ts@@ -0,0 +1,44 @@+import { useState, useEffect } from "react";++interface VersionInfo {+ version: string;+ commitHash: string;+ githubUrl: string;+ isDev: boolean;+ latestVersion?: string;+ latestUrl?: string;+ hasUpdate?: boolean;+}++export function useVersionUpdateCheck() {+ const [versionInfo, setVersionInfo] = useState<VersionInfo | null>(null);+ const [loading, setLoading] = useState(true);++ useEffect(() => {+ fetchVersionInfo();++ // Check for updates every 15 minutes (aligned with server cache)+ const interval = setInterval(() => {+ fetchVersionInfo();+ }, 15 * 60 * 1000); // 15 minutes++ return () => clearInterval(interval);+ }, []);++ const fetchVersionInfo = async () => {+ try {+ // Server has 15-minute cache, no need for cache-busting+ const response = await fetch("/api/version");+ if (response.ok) {+ const data = await response.json();+ setVersionInfo(data);+ }+ } catch (error) {+ console.error("Failed to fetch version info:", error);+ } finally {+ setLoading(false);+ }+ };++ return { versionInfo, loading, refetch: fetchVersionInfo };+}diff --git a/messages/de.json b/messages/de.jsonindex b854411..74061ad 100644--- a/messages/de.json+++ b/messages/de.json@@ -269,5 +269,16 @@"markAsRead": "Als gelesen markieren","markedAsRead": "Fehler als gelesen markiert","read": "Gelesen"+ },+ "changelog": {+ "title": "Changelog",+ "description": "Alle Versionshinweise und Änderungen von BetterShift",+ "noReleases": "Keine Releases verfügbar",+ "viewOnGitHub": "Auf GitHub ansehen"+ },+ "update": {+ "available": "Update verfügbar",+ "newVersion": "Version {version} ist verfügbar",+ "viewChangelog": "Changelog anzeigen"}}diff --git a/messages/en.json b/messages/en.jsonindex 0a17c93..7a2e9e4 100644--- a/messages/en.json+++ b/messages/en.json@@ -269,5 +269,16 @@"markAsRead": "Mark as read","markedAsRead": "Errors marked as read","read": "Read"+ },+ "changelog": {+ "title": "Changelog",+ "description": "All release notes and changes for BetterShift",+ "noReleases": "No releases available",+ "viewOnGitHub": "View on GitHub"+ },+ "update": {+ "available": "Update available",+ "newVersion": "Version {version} is available",+ "viewChangelog": "View changelog"}}diff --git a/messages/it.json b/messages/it.jsonindex 3f7243d..992c152 100644--- a/messages/it.json+++ b/messages/it.json@@ -268,5 +268,16 @@"markAsRead": "Segna come letto","markedAsRead": "Errori segnati come letti","read": "Letto"+ },+ "changelog": {+ "title": "Changelog",+ "description": "Tutte le note di rilascio e modifiche di BetterShift",+ "noReleases": "Nessun rilascio disponibile",+ "viewOnGitHub": "Visualizza su GitHub"+ },+ "update": {+ "available": "Aggiornamento disponibile",+ "newVersion": "Versione {version} è disponibile",+ "viewChangelog": "Visualizza changelog"}}