From ddd271fa89b46809c9e198201d59b6bbf44bd78b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20S=C3=B6derberg?= Date: Thu, 7 May 2026 13:26:23 +0200 Subject: [PATCH] Updatable notification --- app/admin/NoticeTab.tsx | 115 ++ app/admin/page.tsx | 7 +- app/components/ui/SectionCard.tsx | 63 +- app/data/notice.json | 5 + app/page.tsx | 60 +- package-lock.json | 2139 ++++++++++++++--------------- package.json | 6 +- 7 files changed, 1245 insertions(+), 1150 deletions(-) create mode 100644 app/admin/NoticeTab.tsx create mode 100644 app/data/notice.json diff --git a/app/admin/NoticeTab.tsx b/app/admin/NoticeTab.tsx new file mode 100644 index 0000000..d046c8b --- /dev/null +++ b/app/admin/NoticeTab.tsx @@ -0,0 +1,115 @@ +// app/admin/NoticeTab.tsx + +"use client"; + +import { AlertCircle, AlertTriangle, BellRing, Info, Loader2, Save, CheckCircle } from 'lucide-react'; +import React, { useEffect, useState } from 'react'; +import { readJsonFile, writeJsonFile } from '../actions/jsonEditor'; + +interface NoticeData { + isActive: boolean; + type: 'notice' | 'warning' | 'important'; + message: string; +} + +export const NoticeTab = ({ isOffline }: { isOffline: boolean }) => { + const [notice, setNotice] = useState({ isActive: false, type: 'warning', message: '' }); + const [isLoading, setIsLoading] = useState(true); + const [isSaving, setIsSaving] = useState(false); + const [saveStatus, setSaveStatus] = useState<'idle' | 'success' | 'error'>('idle'); + + useEffect(() => { + const fetchNotice = async () => { + const res = await readJsonFile('notice.json'); + if (res.success && res.data) { + setNotice(res.data); + } + setIsLoading(false); + }; + fetchNotice(); + }, []); + + const handleSave = async () => { + setIsSaving(true); + setSaveStatus('idle'); + const res = await writeJsonFile('notice.json', notice); + if (res.success) { + setSaveStatus('success'); + setTimeout(() => setSaveStatus('idle'), 3000); + } else { + setSaveStatus('error'); + } + setIsSaving(false); + }; + + if (isLoading) return
; + + return ( +
+
+
+

+
+ +
+ Meddelande på startsidan +

+ + {/* Av/På Switch */} + +
+ +
+
+
+ +
+ + + +
+
+ +
+ +