Prevent news and breaking news widgets from appearing together

Modify the widget shuffling logic to ensure that the 'news' and 'breaking' widgets are never placed in the same row by repeatedly shuffling until the condition is met.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 517dfa7b-26ac-463d-a6e1-a58c6df97188
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: a31b32f5-282c-4fb1-bce8-8f2822899957
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/f209e72a-0939-48fa-84fc-57854de71967/517dfa7b-26ac-463d-a6e1-a58c6df97188/0ZGabQy
Replit-Helium-Checkpoint-Created: true
This commit is contained in:
sebastjanartic 2026-02-28 22:33:06 +00:00
parent 869aa7c611
commit 20f96fd01e

View File

@ -458,9 +458,20 @@ export default function Home() {
{ id: "breaking", el: <div key="breaking" className="flex flex-col gap-4"><BreakingNewsWidget /></div> },
{ id: "gallery2", el: <PhotoGalleryWidget key="gallery2" reverseOrder={true} /> },
];
for (let i = w.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[w[i], w[j]] = [w[j], w[i]];
let valid = false;
while (!valid) {
for (let i = w.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[w[i], w[j]] = [w[j], w[i]];
}
valid = true;
for (let i = 0; i < w.length - 1; i += 2) {
const pair = [w[i].id, w[i + 1]?.id];
if (pair.includes("news") && pair.includes("breaking")) {
valid = false;
break;
}
}
}
return w;
}, []);