Logo świąteczne, poprawka w SEO, oraz wyszukiwaniu kanałów

This commit is contained in:
dm
2025-12-17 06:11:33 +01:00
parent 4f0f171bdc
commit ce8b627160
11 changed files with 104 additions and 57 deletions

View File

@@ -126,17 +126,34 @@ export default function JamboxChannelsSearch() {
setWanted([]);
}
// =========================================
// ✅ sugestie pakietów dla koszyka
// - GŁÓWNE: exact/ranked (z count)
// - TEMATYCZNE: dodatki do dokupienia (bez liczenia)
// =========================================
const packageSuggestions = useMemo(() => {
if (!wanted.length) return { exact: [], ranked: [], thematic: [] };
if (!wanted.length) return { exact: [], ranked: [], thematic: [], baseWantedLen: 0, wantedLen: 0 };
// ✅ kanały, które mają pakiety główne (tylko te liczymy w dopasowaniu "głównych")
const baseWanted = wanted.filter((ch) => Array.isArray(ch.packages) && ch.packages.length > 0);
const baseWantedLen = baseWanted.length;
// ======= GŁÓWNE =======
// jeśli nie ma żadnego kanału "bazowego", nie ma co liczyć dopasowania bazowych
if (baseWantedLen === 0) {
// nadal zwracamy tematyczne
const thematicMap = new Map();
for (const ch of wanted) {
const tp = Array.isArray(ch.thematic_packages) ? ch.thematic_packages : [];
for (const p of tp) {
const tid = String(p?.tid ?? "").trim();
const name = String(p?.name ?? "").trim();
if (!tid || !name) continue;
if (!thematicMap.has(tid)) thematicMap.set(tid, { tid, name });
}
}
const thematic = Array.from(thematicMap.values()).sort((a, b) => a.name.localeCompare(b.name, "pl"));
return { exact: [], ranked: [], thematic, baseWantedLen, wantedLen: wanted.length };
}
const counts = new Map(); // key = packageName
for (const ch of wanted) {
for (const ch of baseWanted) {
const pkgs = Array.isArray(ch.packages) ? ch.packages : [];
for (const p of pkgs) {
const name = String(p?.name ?? "").trim();
@@ -150,20 +167,18 @@ export default function JamboxChannelsSearch() {
const all = Array.from(counts.values());
const exact = all
.filter((p) => p.count === wanted.length)
.filter((p) => p.count === baseWantedLen)
.sort((a, b) => a.name.localeCompare(b.name, "pl"));
const ranked = all
.filter((p) => p.count < wanted.length)
.filter((p) => p.count < baseWantedLen)
.sort((a, b) => b.count - a.count || a.name.localeCompare(b.name, "pl"))
.slice(0, 12);
// ======= TEMATYCZNE (dodatki) =======
const thematicMap = new Map(); // key = tid
for (const ch of wanted) {
const tp = Array.isArray(ch.thematic_packages)
? ch.thematic_packages
: [];
const tp = Array.isArray(ch.thematic_packages) ? ch.thematic_packages : [];
for (const p of tp) {
const tid = String(p?.tid ?? "").trim();
const name = String(p?.name ?? "").trim();
@@ -176,9 +191,10 @@ export default function JamboxChannelsSearch() {
a.name.localeCompare(b.name, "pl")
);
return { exact, ranked, thematic };
return { exact, ranked, thematic, baseWantedLen, wantedLen: wanted.length };
}, [wanted]);
return (
<div class="f-chsearch">
<h1 class="f-section-title">Wyszukiwanie kanałów w pakietach telewizji</h1>
@@ -260,7 +276,7 @@ export default function JamboxChannelsSearch() {
onClick={() => scrollToPackage(p.name)}
title={`Zawiera ${p.count}/${wanted.length} wybranych kanałów`}
>
{p.name} ({p.count}/{wanted.length})
{p.name} ({p.count}/{packageSuggestions.baseWantedLen})
</button>
))}
</div>