widgeta z novicami: isti izvajalec vsaj 5 mest narazen
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { artistKey } from "@/lib/artists";
|
||||||
import { useState, useEffect, useCallback } from "react";
|
import { useState, useEffect, useCallback } from "react";
|
||||||
import { Globe, ExternalLink } from "lucide-react";
|
import { Globe, ExternalLink } from "lucide-react";
|
||||||
|
|
||||||
@@ -19,7 +20,24 @@ export function BreakingNewsWidget() {
|
|||||||
const [offset, setOffset] = useState(0);
|
const [offset, setOffset] = useState(0);
|
||||||
const [paused, setPaused] = useState(false);
|
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 total = items.length;
|
||||||
|
|
||||||
const advance = useCallback(() => {
|
const advance = useCallback(() => {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { artistKey } from "@/lib/artists";
|
||||||
import { useState, useEffect, useCallback } from "react";
|
import { useState, useEffect, useCallback } from "react";
|
||||||
import { Newspaper, ExternalLink } from "lucide-react";
|
import { Newspaper, ExternalLink } from "lucide-react";
|
||||||
|
|
||||||
@@ -19,7 +20,24 @@ export function NewsWidget() {
|
|||||||
const [offset, setOffset] = useState(0);
|
const [offset, setOffset] = useState(0);
|
||||||
const [paused, setPaused] = useState(false);
|
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 total = items.length;
|
||||||
|
|
||||||
const advance = useCallback(() => {
|
const advance = useCallback(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user