- Remove hardcoded Dennis Konkol idle quote from rotation - Double quote pool (5 → 12 quotes per locale) - Start at a random quote on page load - Cycle to a random non-repeating quote every 10s instead of sequential - Fix dev-deploy.yml: postgres:15-alpine → postgres:16-alpine Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
236 lines
12 KiB
TypeScript
236 lines
12 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect, useState } from "react";
|
|
import { motion, AnimatePresence } from "framer-motion";
|
|
import { Disc3, Gamepad2, Zap, Quote as QuoteIcon } from "lucide-react";
|
|
import { useTranslations } from "next-intl";
|
|
|
|
interface CustomActivity {
|
|
[key: string]: unknown;
|
|
}
|
|
|
|
interface StatusData {
|
|
music: { isPlaying: boolean; track: string; artist: string; albumArt: string; url: string; } | null;
|
|
gaming: { isPlaying: boolean; name: string; image: string | null; state?: string | number; details?: string | number; } | null;
|
|
coding: { isActive: boolean; project?: string; file?: string; language?: string; } | null;
|
|
customActivities?: Record<string, CustomActivity>;
|
|
}
|
|
|
|
const techQuotes = {
|
|
de: [
|
|
{ content: "Informatik hat nicht mehr mit Computern zu tun als Astronomie mit Teleskopen.", author: "Edsger W. Dijkstra" },
|
|
{ content: "Einfachheit ist die Voraussetzung für Verlässlichkeit.", author: "Edsger W. Dijkstra" },
|
|
{ content: "Wenn Debugging der Prozess des Entfernens von Fehlern ist, dann muss Programmieren der Prozess des Einbauens sein.", author: "Edsger W. Dijkstra" },
|
|
{ content: "Gelöschter Code ist gedebuggter Code.", author: "Jeff Sickel" },
|
|
{ content: "Zuerst löse das Problem. Dann schreibe den Code.", author: "John Johnson" },
|
|
{ content: "Jedes Programm kann um mindestens einen Faktor zwei vereinfacht werden. Jedes Programm hat mindestens einen Bug.", author: "Kernighan's Law" },
|
|
{ content: "Code lesen ist schwieriger als Code schreiben — deshalb schreibt jeder neu.", author: "Joel Spolsky" },
|
|
{ content: "Die beste Performance-Optimierung ist der Übergang von nicht-funktionierend zu funktionierend.", author: "J. Osterhout" },
|
|
{ content: "Mach es funktionierend, dann mach es schön, dann mach es schnell — in dieser Reihenfolge.", author: "Kent Beck" },
|
|
{ content: "Software ist wie Entropie: Es ist schwer zu fassen, wiegt nichts und gehorcht dem zweiten Hauptsatz der Thermodynamik.", author: "Norman Augustine" },
|
|
{ content: "Gute Software ist nicht die, die keine Bugs hat — sondern die, deren Bugs keine Rolle spielen.", author: "Bruce Eckel" },
|
|
{ content: "Der einzige Weg, schnell zu gehen, ist, gut zu gehen.", author: "Robert C. Martin" },
|
|
],
|
|
en: [
|
|
{ content: "Computer Science is no more about computers than astronomy is about telescopes.", author: "Edsger W. Dijkstra" },
|
|
{ content: "Simplicity is prerequisite for reliability.", author: "Edsger W. Dijkstra" },
|
|
{ content: "If debugging is the process of removing software bugs, then programming must be the process of putting them in.", author: "Edsger W. Dijkstra" },
|
|
{ content: "Deleted code is debugged code.", author: "Jeff Sickel" },
|
|
{ content: "First, solve the problem. Then, write the code.", author: "John Johnson" },
|
|
{ content: "Any program can be simplified by at least a factor of two. Every program has at least one bug.", author: "Kernighan's Law" },
|
|
{ content: "It's harder to read code than to write it — that's why everyone rewrites.", author: "Joel Spolsky" },
|
|
{ content: "The best performance optimization is the transition from a non-working state to a working state.", author: "J. Osterhout" },
|
|
{ content: "Make it work, make it right, make it fast — in that order.", author: "Kent Beck" },
|
|
{ content: "Software is like entropy: it is difficult to grasp, weighs nothing, and obeys the second law of thermodynamics.", author: "Norman Augustine" },
|
|
{ content: "Good software isn't software with no bugs — it's software whose bugs don't matter.", author: "Bruce Eckel" },
|
|
{ content: "The only way to go fast is to go well.", author: "Robert C. Martin" },
|
|
]
|
|
};
|
|
|
|
function getSafeGamingText(details: string | number | undefined, state: string | number | undefined, fallback: string): string {
|
|
if (typeof details === 'string' && details.trim().length > 0) return details;
|
|
if (typeof state === 'string' && state.trim().length > 0) return state;
|
|
return fallback;
|
|
}
|
|
|
|
export default function ActivityFeed({
|
|
onActivityChange,
|
|
locale = 'en'
|
|
}: {
|
|
onActivityChange?: (active: boolean) => void;
|
|
locale?: string;
|
|
}) {
|
|
const [data, setData] = useState<StatusData | null>(null);
|
|
const [hasActivity, setHasActivity] = useState(false);
|
|
const [quoteIndex, setQuoteIndex] = useState(() => Math.floor(Math.random() * (techQuotes[locale as keyof typeof techQuotes] || techQuotes.en).length));
|
|
const [loading, setLoading] = useState(true);
|
|
const t = useTranslations("home.about.activity");
|
|
|
|
const allQuotes = techQuotes[locale as keyof typeof techQuotes] || techQuotes.en;
|
|
|
|
useEffect(() => {
|
|
const fetchData = async () => {
|
|
try {
|
|
const res = await fetch("/api/n8n/status");
|
|
if (!res.ok) throw new Error();
|
|
const json = await res.json();
|
|
const activityData = Array.isArray(json) ? json[0] : json;
|
|
|
|
setData(activityData);
|
|
const isActive = Boolean(
|
|
activityData.coding?.isActive ||
|
|
activityData.gaming?.isPlaying ||
|
|
activityData.music?.isPlaying ||
|
|
Object.values(activityData.customActivities || {}).some((act) => Boolean((act as { enabled?: boolean })?.enabled))
|
|
);
|
|
setHasActivity(isActive);
|
|
onActivityChange?.(isActive);
|
|
} catch {
|
|
setHasActivity(false);
|
|
onActivityChange?.(false);
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
};
|
|
|
|
fetchData();
|
|
const statusInterval = setInterval(fetchData, 30000);
|
|
|
|
// Pick a random quote every 10 seconds (never the same one twice in a row)
|
|
const quoteInterval = setInterval(() => {
|
|
setQuoteIndex((prev) => {
|
|
let next;
|
|
do { next = Math.floor(Math.random() * allQuotes.length); } while (next === prev && allQuotes.length > 1);
|
|
return next;
|
|
});
|
|
}, 10000);
|
|
|
|
return () => {
|
|
clearInterval(statusInterval);
|
|
clearInterval(quoteInterval);
|
|
};
|
|
}, [onActivityChange]);
|
|
|
|
if (loading) {
|
|
return <div className="animate-pulse space-y-4">
|
|
<div className="h-24 bg-stone-100 dark:bg-stone-800 rounded-2xl" />
|
|
</div>;
|
|
}
|
|
|
|
if (!hasActivity) {
|
|
return (
|
|
<div className="h-full flex flex-col justify-center space-y-6">
|
|
<div className="w-10 h-10 rounded-full bg-liquid-mint/10 flex items-center justify-center">
|
|
<QuoteIcon size={18} className="text-emerald-600 dark:text-liquid-mint" />
|
|
</div>
|
|
<div className="min-h-[80px] sm:min-h-[120px] relative">
|
|
<AnimatePresence mode="wait">
|
|
<motion.div
|
|
key={quoteIndex}
|
|
initial={{ opacity: 0, y: 10 }}
|
|
animate={{ opacity: 1, y: 0 }}
|
|
exit={{ opacity: 0, y: -10 }}
|
|
transition={{ duration: 0.5 }}
|
|
className="space-y-4"
|
|
>
|
|
<p className="text-base sm:text-lg md:text-xl lg:text-2xl font-light leading-tight text-stone-700 dark:text-stone-300 italic">
|
|
“{allQuotes[quoteIndex].content}”
|
|
</p>
|
|
<p className="text-xs font-black text-stone-400 dark:text-stone-500 uppercase tracking-widest">
|
|
— {allQuotes[quoteIndex].author}
|
|
</p>
|
|
</motion.div>
|
|
</AnimatePresence>
|
|
</div>
|
|
<div className="flex items-center gap-2 text-[10px] font-black uppercase tracking-widest text-stone-400 dark:text-stone-600 pt-4 border-t border-stone-100 dark:border-stone-800">
|
|
<span className="w-1.5 h-1.5 rounded-full bg-stone-200 dark:bg-stone-700 animate-pulse" />
|
|
{t("idleStatus")}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className="space-y-4">
|
|
{data?.coding?.isActive && (
|
|
<motion.div initial={{ opacity: 0, y: 10 }} animate={{ opacity: 1, y: 0 }} className="bg-emerald-500/5 dark:bg-emerald-500/10 border border-emerald-500/20 rounded-2xl p-5">
|
|
<div className="flex items-center gap-3 mb-2">
|
|
<Zap size={14} className="text-emerald-600 dark:text-emerald-400 animate-pulse" />
|
|
<span className="text-[10px] font-black uppercase tracking-widest text-emerald-600 dark:text-emerald-400">{t("codingNow")}</span>
|
|
</div>
|
|
<p className="font-bold text-stone-900 dark:text-white text-lg truncate">{data.coding.project}</p>
|
|
<p className="text-xs text-stone-500 dark:text-white/50 truncate">{data.coding.file}</p>
|
|
</motion.div>
|
|
)}
|
|
|
|
{data?.gaming?.isPlaying && (
|
|
<motion.div initial={{ opacity: 0, y: 10 }} animate={{ opacity: 1, y: 0 }} className="bg-indigo-500/5 dark:bg-indigo-500/10 border border-indigo-500/20 rounded-2xl p-5">
|
|
<div className="flex items-center gap-3 mb-3">
|
|
<Gamepad2 size={14} className="text-indigo-600 dark:text-indigo-400" />
|
|
<span className="text-[10px] font-black uppercase tracking-widest text-indigo-600 dark:text-indigo-400">{t("gaming")}</span>
|
|
</div>
|
|
<div className="flex gap-4">
|
|
{data.gaming.image && (
|
|
<div className="w-12 h-12 rounded-xl overflow-hidden shrink-0 shadow-lg relative">
|
|
<img src={data.gaming.image} alt={data.gaming.name} className="w-full h-full object-cover" />
|
|
</div>
|
|
)}
|
|
<div className="min-w-0 flex flex-col justify-center">
|
|
<p className="font-bold text-stone-900 dark:text-white text-base truncate">{data.gaming.name}</p>
|
|
<p className="text-xs text-stone-500 dark:text-white/50 truncate">
|
|
{getSafeGamingText(data.gaming.details, data.gaming.state, t("inGame"))}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</motion.div>
|
|
)}
|
|
|
|
{data?.music?.isPlaying && (
|
|
<motion.div
|
|
initial={{ opacity: 0, y: 10 }}
|
|
animate={{ opacity: 1, y: 0 }}
|
|
className="bg-[#1DB954]/5 dark:bg-[#1DB954]/10 border border-[#1DB954]/20 rounded-2xl p-5 relative overflow-hidden group"
|
|
>
|
|
<div className="flex items-center justify-between mb-3 relative z-10">
|
|
<div className="flex items-center gap-2">
|
|
<Disc3 size={14} className="text-[#1DB954] animate-spin-slow" />
|
|
<span className="text-[10px] font-black uppercase tracking-widest text-[#1DB954]">{t("listening")}</span>
|
|
</div>
|
|
{/* Simple Animated Music Bars */}
|
|
<div className="flex items-end gap-[2px] h-3">
|
|
{[0, 1, 2].map((i) => (
|
|
<motion.div
|
|
key={i}
|
|
animate={{ height: ["20%", "100%", "20%"] }}
|
|
transition={{
|
|
duration: 0.8,
|
|
repeat: Infinity,
|
|
delay: i * 0.2,
|
|
ease: "easeInOut"
|
|
}}
|
|
className="w-[2px] bg-[#1DB954] rounded-full"
|
|
/>
|
|
))}
|
|
</div>
|
|
</div>
|
|
<div className="flex gap-4 relative z-10">
|
|
<div className="w-16 h-16 rounded-lg overflow-hidden shrink-0 shadow-md relative group-hover:shadow-xl transition-shadow duration-500">
|
|
<img
|
|
src={data.music.albumArt}
|
|
alt="Album Art"
|
|
className="w-full h-full object-cover transition-transform duration-700 group-hover:scale-110"
|
|
/>
|
|
</div>
|
|
<div className="min-w-0 flex flex-col justify-center">
|
|
<p className="font-bold text-[#1DB954] dark:text-[#1DB954] text-base truncate leading-tight mb-1">{data.music.track}</p>
|
|
<p className="text-sm text-stone-600 dark:text-white/60 truncate font-medium">{data.music.artist}</p>
|
|
</div>
|
|
</div>
|
|
{/* Subtle Spotify branding gradient */}
|
|
<div className="absolute top-0 right-0 w-32 h-32 bg-[#1DB954]/5 blur-[60px] rounded-full -mr-16 -mt-16 pointer-events-none" />
|
|
</motion.div>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|