mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-25 13:45:03 +08:00
fix(providers): scope preset search to provider names only
The preset search text also included websiteUrl and the shared category label, producing imprecise matches: a single category term matched the whole group, and URL fragments like "com"/"api" matched nearly everything. Restrict the search text to the display name and raw name; category labels are still used for rendering.
This commit is contained in:
@@ -63,19 +63,9 @@ export function getPresetDisplayName(
|
||||
|
||||
export function getPresetSearchText(
|
||||
entry: PresetEntry,
|
||||
presetCategoryLabels: Record<string, string>,
|
||||
t: PresetTranslator,
|
||||
): string {
|
||||
const presetCategory = entry.preset.category ?? "others";
|
||||
const categoryLabel =
|
||||
presetCategoryLabels[presetCategory] ?? String(t("providerPreset.other"));
|
||||
|
||||
return [
|
||||
getPresetDisplayName(entry.preset, t),
|
||||
entry.preset.name,
|
||||
entry.preset.websiteUrl,
|
||||
categoryLabel,
|
||||
]
|
||||
return [getPresetDisplayName(entry.preset, t), entry.preset.name]
|
||||
.join(" ")
|
||||
.toLowerCase();
|
||||
}
|
||||
@@ -83,7 +73,6 @@ export function getPresetSearchText(
|
||||
export function filterPresetEntries(
|
||||
entries: PresetEntry[],
|
||||
query: string,
|
||||
presetCategoryLabels: Record<string, string>,
|
||||
t: PresetTranslator,
|
||||
): PresetEntry[] {
|
||||
const normalizedQuery = query.trim().toLowerCase();
|
||||
@@ -92,9 +81,7 @@ export function filterPresetEntries(
|
||||
}
|
||||
|
||||
return entries.filter((entry) =>
|
||||
getPresetSearchText(entry, presetCategoryLabels, t).includes(
|
||||
normalizedQuery,
|
||||
),
|
||||
getPresetSearchText(entry, t).includes(normalizedQuery),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -117,7 +104,6 @@ export function sortPresetEntries(
|
||||
export interface PresetVisibilityOptions {
|
||||
query: string;
|
||||
sortMode: PresetSortMode;
|
||||
presetCategoryLabels: Record<string, string>;
|
||||
t: PresetTranslator;
|
||||
}
|
||||
|
||||
@@ -125,13 +111,9 @@ export function getVisiblePresetEntries(
|
||||
entries: PresetEntry[],
|
||||
options: PresetVisibilityOptions,
|
||||
): PresetEntry[] {
|
||||
const { query, sortMode, presetCategoryLabels, t } = options;
|
||||
const { query, sortMode, t } = options;
|
||||
|
||||
return sortPresetEntries(
|
||||
filterPresetEntries(entries, query, presetCategoryLabels, t),
|
||||
sortMode,
|
||||
t,
|
||||
);
|
||||
return sortPresetEntries(filterPresetEntries(entries, query, t), sortMode, t);
|
||||
}
|
||||
|
||||
interface ProviderPresetSelectorProps {
|
||||
@@ -165,10 +147,9 @@ export function ProviderPresetSelector({
|
||||
getVisiblePresetEntries(presetEntries, {
|
||||
query: searchQuery,
|
||||
sortMode,
|
||||
presetCategoryLabels,
|
||||
t,
|
||||
}),
|
||||
[presetEntries, presetCategoryLabels, searchQuery, sortMode, t],
|
||||
[presetEntries, searchQuery, sortMode, t],
|
||||
);
|
||||
|
||||
const getCategoryHint = (): ReactNode => {
|
||||
|
||||
Reference in New Issue
Block a user