diff --git a/client/src/components/breaking-news-widget.tsx b/client/src/components/breaking-news-widget.tsx index 82f8167..0e19e04 100644 --- a/client/src/components/breaking-news-widget.tsx +++ b/client/src/components/breaking-news-widget.tsx @@ -1,4 +1,5 @@ import { useQuery } from "@tanstack/react-query"; +import { artistKey } from "@/lib/artists"; import { useState, useEffect, useCallback } from "react"; import { Globe, ExternalLink } from "lucide-react"; @@ -19,7 +20,24 @@ export function BreakingNewsWidget() { const [offset, setOffset] = useState(0); const [paused, setPaused] = useState(false); - const items = news || []; + // Isti izvajalec ne sme stati drug ob drugem: vsaj 5 mest razmika. + const items = (() => { + const rest = [...(news || [])]; + const out: NewsItem[] = []; + const recent: string[] = []; + while (rest.length) { + let idx = rest.findIndex((n: any) => { + const k = artistKey(n?.title || ""); + return !k || !recent.includes(k); + }); + if (idx < 0) idx = 0; + const n = rest.splice(idx, 1)[0]; + out.push(n); + recent.push(artistKey((n as any)?.title || "")); + if (recent.length >= 5) recent.shift(); + } + return out; + })(); const total = items.length; const advance = useCallback(() => { diff --git a/client/src/components/news-widget.tsx b/client/src/components/news-widget.tsx index 6cd2f21..3bf8c27 100644 --- a/client/src/components/news-widget.tsx +++ b/client/src/components/news-widget.tsx @@ -1,4 +1,5 @@ import { useQuery } from "@tanstack/react-query"; +import { artistKey } from "@/lib/artists"; import { useState, useEffect, useCallback } from "react"; import { Newspaper, ExternalLink } from "lucide-react"; @@ -19,7 +20,24 @@ export function NewsWidget() { const [offset, setOffset] = useState(0); const [paused, setPaused] = useState(false); - const items = news || []; + // Isti izvajalec ne sme stati drug ob drugem: vsaj 5 mest razmika. + const items = (() => { + const rest = [...(news || [])]; + const out: NewsItem[] = []; + const recent: string[] = []; + while (rest.length) { + let idx = rest.findIndex((n: any) => { + const k = artistKey(n?.title || ""); + return !k || !recent.includes(k); + }); + if (idx < 0) idx = 0; + const n = rest.splice(idx, 1)[0]; + out.push(n); + recent.push(artistKey((n as any)?.title || "")); + if (recent.length >= 5) recent.shift(); + } + return out; + })(); const total = items.length; const advance = useCallback(() => {