Files
Psychotoxical-psysonic/src/components/settings/settingsSearch.ts
T
Psychotoxical 7c724a642f chore(eslint): add ESLint toolchain and clean src to strict 0/0 (#1165)
* chore(eslint): add eslint toolchain and configs

* fix(eslint): resolve gradual-config errors (rules-of-hooks, no-empty, prefer-const, …)

* chore(eslint): clear unused vars in config, contexts, app and test

* chore(eslint): clear unused vars in api and music-network

* chore(eslint): clear unused vars in utils

* chore(eslint): clear unused vars in store

* chore(eslint): clear unused vars in cover and hooks

* chore(eslint): clear unused vars in components

* chore(eslint): clear unused vars in pages

* chore(eslint): remove explicit any in src

* chore(eslint): align react-hooks exhaustive-deps

* chore(eslint): zero gradual config on src

* chore(eslint): strict hook rules in store and utils

* chore(eslint): strict hook rules in hooks and cover

* chore(eslint): strict hook rules in components

* chore(eslint): strict hook rules in pages and contexts

* chore(eslint): document scripts ignore in eslint config

* chore(eslint): add lint script and zero strict findings

* chore(eslint): address review round 1 (gradual 0/0, per-site disable reasons)

* chore(eslint): tighten two set-state disable comments (review round 2 LOW)

* chore(nix): sync npmDepsHash with package-lock.json

* docs(changelog): add Under the Hood entry for ESLint setup (PR #1165)

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-06-24 01:33:34 +02:00

55 lines
1.9 KiB
TypeScript

import type { TFunction } from 'i18next';
import { GLOBAL_SHORTCUT_ACTIONS, IN_APP_SHORTCUT_ACTIONS } from '../../config/shortcutActions';
import { SETTINGS_INDEX, matchScore, type Tab } from './settingsTabs';
export type SettingsSearchHit = {
tab: Tab;
title: string;
focusTitle: string;
score: number;
key: string;
};
export function searchSettings(query: string, activeTab: Tab, t: TFunction): SettingsSearchHit[] {
const q = query.trim();
if (!q) return [];
const hits: SettingsSearchHit[] = [];
for (const entry of SETTINGS_INDEX) {
const title = t(entry.titleKey);
const hay = entry.keywords ? `${title} ${entry.keywords}` : title;
const score = matchScore(hay, q);
if (score <= 0) continue;
const focusTitle = entry.focusTitleKey ? t(entry.focusTitleKey) : title;
hits.push({ tab: entry.tab, title, focusTitle, score, key: entry.titleKey });
}
const inAppSection = t('settings.inputKeybindingsTitle');
for (const { id, getLabel } of IN_APP_SHORTCUT_ACTIONS) {
const title = getLabel(t);
const hay = `${title} ${inAppSection} shortcut hotkey keyboard in-app ${id.replace(/-/g, ' ')}`;
const score = matchScore(hay, q);
if (score <= 0) continue;
hits.push({ tab: 'input', title, focusTitle: inAppSection, score, key: `in-app:${id}` });
}
const globalSection = t('settings.globalShortcutsTitle');
for (const { id, getLabel } of GLOBAL_SHORTCUT_ACTIONS) {
const title = getLabel(t);
const hay = `${title} ${globalSection} shortcut hotkey global media ${id.replace(/-/g, ' ')}`;
const score = matchScore(hay, q);
if (score <= 0) continue;
hits.push({ tab: 'input', title, focusTitle: globalSection, score, key: `global:${id}` });
}
hits.sort((a, b) => {
const aCurrent = a.tab === activeTab ? 1 : 0;
const bCurrent = b.tab === activeTab ? 1 : 0;
if (aCurrent !== bCurrent) return bCurrent - aCurrent;
return b.score - a.score;
});
return hits;
}