widgeta z novicami: isti izvajalec vsaj 5 mest narazen

This commit is contained in:
FOLX Claude
2026-08-29 19:40:16 +02:00
parent ef5df9cf77
commit 9c0e088f08
2 changed files with 38 additions and 2 deletions
+19 -1
View File
@@ -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(() => {
+19 -1
View File
@@ -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(() => {