From 29afba2199ebb0741428ddda5dbab39d29d9fb71 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 23 Jan 2026 20:33:06 +0000 Subject: [PATCH] chore(ai): remove dead code (agent) Removed unused `js/search/searchFacetState.js` and cleaned up broken calls in `js/searchView.js`. --- js/search/searchFacetState.js | 40 ---------- js/searchView.js | 146 ---------------------------------- 2 files changed, 186 deletions(-) delete mode 100644 js/search/searchFacetState.js diff --git a/js/search/searchFacetState.js b/js/search/searchFacetState.js deleted file mode 100644 index 88c46093..00000000 --- a/js/search/searchFacetState.js +++ /dev/null @@ -1,40 +0,0 @@ -const listeners = new Set(); - -const cloneFacetList = (list) => - Array.isArray(list) ? list.map((entry) => ({ ...entry })) : []; - -let state = { - tags: [], - authors: [], - relays: [], -}; - -function notify() { - const snapshot = getSearchFacetCounts(); - listeners.forEach((listener) => listener(snapshot)); -} - -export function getSearchFacetCounts() { - return { - tags: cloneFacetList(state.tags), - authors: cloneFacetList(state.authors), - relays: cloneFacetList(state.relays), - }; -} - -export function setSearchFacetCounts(nextState = {}) { - state = { - tags: cloneFacetList(nextState.tags), - authors: cloneFacetList(nextState.authors), - relays: cloneFacetList(nextState.relays), - }; - notify(); -} - -export function subscribeSearchFacetCounts(listener) { - if (typeof listener !== "function") { - return () => {}; - } - listeners.add(listener); - return () => listeners.delete(listener); -} diff --git a/js/searchView.js b/js/searchView.js index 5e1be8e6..7f9422d6 100644 --- a/js/searchView.js +++ b/js/searchView.js @@ -23,12 +23,6 @@ function getApp() { } const FALLBACK_AVATAR = "assets/svg/default-profile.svg"; -const EMPTY_FACET_COUNTS = { tags: [], authors: [], relays: [] }; -const MAX_FACET_RESULTS = { - tags: 8, - authors: 6, - relays: 6, -}; const normalizeFacetText = (value) => { if (typeof value !== "string") { @@ -37,38 +31,6 @@ const normalizeFacetText = (value) => { return value.trim(); }; -const resolveShortPubkeyLabel = (pubkey) => { - const trimmed = normalizeFacetText(pubkey); - if (!trimmed) { - return ""; - } - let npub = ""; - try { - if (window.NostrTools && window.NostrTools.nip19) { - npub = window.NostrTools.nip19.npubEncode(trimmed); - } - } catch (error) { - // ignore - } - const formattedNpub = formatShortNpub(npub); - if (formattedNpub) { - return formattedNpub; - } - return truncateMiddle(trimmed, 18); -}; - -const resolveAuthorFacetLabel = (video) => { - const name = normalizeFacetText(video?.authorName); - if (name) { - return name; - } - const npub = normalizeFacetText(video?.authorNpub); - if (npub) { - return formatShortNpub(npub) || npub; - } - return resolveShortPubkeyLabel(video?.pubkey); -}; - const extractRelayHints = (event) => { if (!event || typeof event !== "object") { return []; @@ -92,109 +54,6 @@ const extractRelayHints = (event) => { ); }; -const normalizeTagFacetValue = (value) => - normalizeFacetText(value) - .replace(/^#/, "") - .toLowerCase(); - -const buildFacetEntries = (map, limit) => { - if (!map.size) { - return []; - } - return Array.from(map.values()) - .sort((a, b) => (b.count - a.count) || a.label.localeCompare(b.label)) - .slice(0, limit); -}; - -const buildSearchFacetCounts = (videos = []) => { - const tagCounts = new Map(); - const authorCounts = new Map(); - const relayCounts = new Map(); - - videos.forEach((video) => { - if (!video) { - return; - } - - const authorKey = normalizeFacetText(video.pubkey || ""); - if (authorKey) { - const label = resolveAuthorFacetLabel(video) || authorKey; - const entry = authorCounts.get(authorKey) || { - value: authorKey, - label, - count: 0, - }; - entry.count += 1; - if (!entry.label && label) { - entry.label = label; - } - authorCounts.set(authorKey, entry); - } - - const tagSet = new Set(); - if (Array.isArray(video.tags)) { - video.tags.forEach((tag) => { - if (Array.isArray(tag)) { - if (tag[0] === "t") { - const normalized = normalizeTagFacetValue(tag[1] || ""); - if (normalized) { - tagSet.add(normalized); - } - } - return; - } - const normalized = normalizeTagFacetValue(tag); - if (normalized) { - tagSet.add(normalized); - } - }); - } - tagSet.forEach((tag) => { - const label = `#${tag}`; - const entry = tagCounts.get(tag) || { value: tag, label, count: 0 }; - entry.count += 1; - tagCounts.set(tag, entry); - }); - - const relaySet = new Set(); - if (Array.isArray(video.relays)) { - video.relays.forEach((relay) => { - const normalized = normalizeFacetText(relay); - if (normalized) { - relaySet.add(normalized); - } - }); - } - if (Array.isArray(video.relayHints)) { - video.relayHints.forEach((relay) => { - const normalized = normalizeFacetText(relay); - if (normalized) { - relaySet.add(normalized); - } - }); - } - const relayField = normalizeFacetText(video.relay || video.eventRelay || ""); - if (relayField) { - relaySet.add(relayField); - } - relaySet.forEach((relay) => { - const entry = relayCounts.get(relay) || { - value: relay, - label: relay, - count: 0, - }; - entry.count += 1; - relayCounts.set(relay, entry); - }); - }); - - return { - tags: buildFacetEntries(tagCounts, MAX_FACET_RESULTS.tags), - authors: buildFacetEntries(authorCounts, MAX_FACET_RESULTS.authors), - relays: buildFacetEntries(relayCounts, MAX_FACET_RESULTS.relays), - }; -}; - function renderProfileCards(profiles, container) { if (!container) return; container.innerHTML = ""; @@ -314,7 +173,6 @@ export async function initSearchView() { if (!query) { if (channelList) channelList.innerHTML = `
Please enter a search term.
`; if (videoList) videoList.innerHTML = `Please enter a search term.
`; - setSearchFacetCounts(EMPTY_FACET_COUNTS); return; } @@ -335,16 +193,12 @@ export async function initSearchView() { performVideoSearch(query, searchToken, parsedQuery.filters).then(videos => { if (searchToken !== currentSearchToken) return; const app = getApp(); - setSearchFacetCounts(buildSearchFacetCounts(videos)); renderSearchVideos(videos, videoList, app); }).catch(err => { devLogger.warn("[Search] Video search failed", err); if (videoList && searchToken === currentSearchToken) { videoList.innerHTML = `Failed to load videos.
`; } - if (searchToken === currentSearchToken) { - setSearchFacetCounts(EMPTY_FACET_COUNTS); - } }); }