diff --git a/ext/cfx-ui/src/cfx/base/serverUtils.ts b/ext/cfx-ui/src/cfx/base/serverUtils.ts index 990ab298ed..64881e47ff 100644 --- a/ext/cfx-ui/src/cfx/base/serverUtils.ts +++ b/ext/cfx-ui/src/cfx/base/serverUtils.ts @@ -6,7 +6,7 @@ import emojiRegex from 'emoji-regex'; import { IServerListConfig, ServersListType } from "cfx/common/services/servers/lists/types"; import { IPinnedServersConfig, IServerView } from 'cfx/common/services/servers/types'; import { IAutocompleteIndex } from 'cfx/common/services/servers/source/types'; -import { ISearchTerm, isAddressSearchTerm } from './searchTermsParser'; +import { isAddressSearchTerm } from './searchTermsParser'; export const EOL_LINK = 'aka.cfx.re/eol'; export const EOS_LINK = 'aka.cfx.re/eos'; @@ -156,19 +156,6 @@ export function shouldPrioritizePinnedServers(config: IServerListConfig): boolea return config.type === ServersListType.Supporters; } -export function getPrioritizedServerName(config: IServerListConfig): ISearchTerm | undefined { - const name = config.searchTextParsed.find((item) => item.type === 'name'); - if (!name) { - return; - } - - if (name.value.length < 3) { - return; - } - - return name; -} - /** * Returns server tags list to render in servers list */ diff --git a/ext/cfx-ui/src/cfx/common/services/servers/lists/FavoriteServersList.ts b/ext/cfx-ui/src/cfx/common/services/servers/lists/FavoriteServersList.ts index 8f173bf628..3fe9a1a10b 100644 --- a/ext/cfx-ui/src/cfx/common/services/servers/lists/FavoriteServersList.ts +++ b/ext/cfx-ui/src/cfx/common/services/servers/lists/FavoriteServersList.ts @@ -2,7 +2,7 @@ import { makeAutoObservable } from "mobx"; import { IServersService } from "../servers.service"; import { IServersStorageService } from "../serversStorage.service"; import { filterList } from "../source/listFilter"; -import { sortList, sortFilteredList } from "../source/listSorter"; +import { sortList } from "../source/listSorter"; import { IListableServerView } from "../source/types"; import { serverView2ListableServerView } from "../transformers"; import { IPinnedServersConfig, IServerView } from "../types"; @@ -35,13 +35,11 @@ export class FavoriteServersList implements IServersList { this._config.get(), ); - const filteredList = filterList( + return filterList( listableFavoriteServers, sortedList, this._config.get(), ); - - return sortFilteredList(listableFavoriteServers, filteredList, this._config.get()); } constructor( diff --git a/ext/cfx-ui/src/cfx/common/services/servers/source/WorkerSource.worker.ts b/ext/cfx-ui/src/cfx/common/services/servers/source/WorkerSource.worker.ts index 7ea7250da6..2cb0cee892 100644 --- a/ext/cfx-ui/src/cfx/common/services/servers/source/WorkerSource.worker.ts +++ b/ext/cfx-ui/src/cfx/common/services/servers/source/WorkerSource.worker.ts @@ -3,7 +3,7 @@ import { filterList } from "./listFilter"; import { getAllMasterListServers } from "./utils/fetchers"; import { IAutocompleteIndex, IListableServerView } from "./types"; import { IServerListConfig } from "../lists/types"; -import { sortFilteredList, sortList } from "./listSorter"; +import { sortList } from "./listSorter"; import { serverView2ListableServerView } from "../transformers"; import { AutocompleteIndexer } from "./autocomplete"; import { shouldPrioritizePinnedServers } from "cfx/base/serverUtils"; @@ -152,16 +152,10 @@ export class ServersWorker { return; } - const filteredList = filterList( + this.sendList(list.config, list.id, filterList( this.listableServersMap, this.getSortedList(list.config), list.config, - ); - - this.sendList(list.config, list.id, sortFilteredList( - this.listableServersMap, - filteredList, - list.config, )); } diff --git a/ext/cfx-ui/src/cfx/common/services/servers/source/listSorter.ts b/ext/cfx-ui/src/cfx/common/services/servers/source/listSorter.ts index 58de38d1f3..3f9993c10d 100644 --- a/ext/cfx-ui/src/cfx/common/services/servers/source/listSorter.ts +++ b/ext/cfx-ui/src/cfx/common/services/servers/source/listSorter.ts @@ -1,4 +1,4 @@ -import { shouldPrioritizePinnedServers, getPrioritizedServerName, normalizeSearchString } from "cfx/base/serverUtils"; +import { shouldPrioritizePinnedServers } from "cfx/base/serverUtils"; import { IServerListConfig, ServerListSortDir, ServersListSortBy } from "../lists/types"; import { IPinnedServersConfig } from "../types"; import { IListableServerView } from "./types"; @@ -102,48 +102,3 @@ function sortByProperty(servers: Record, property: return -dir; } - -export const sortFilteredList = (servers: Record, sortedList: string[], config: IServerListConfig): string[] => { - const sorters: Array<(a: string, b: string) => number> = []; - - const searchName = getPrioritizedServerName(config); - - if (searchName) { - sorters.push(sortByServerName.bind(null, servers, normalizeSearchString(searchName.value.toLowerCase()))); - } - - if (sorters.length === 0) { - return sortedList; - } - - return sortedList.sort((a, b) => { - for (const sorter of sorters) { - const retval = sorter(a, b); - - if (retval !== 0) { - return retval; - } - } - - return 0; - }); -} - -function sortByServerName(servers: Record, searchName: string, a: string, b: string): number { - const aIndex = servers[a].sortableName.indexOf(searchName); - const bIndex = servers[b].sortableName.indexOf(searchName); - - if (aIndex !== -1 && bIndex !== -1) { - return aIndex - bIndex; - } - - if (aIndex !== -1) { - return -1; - } - - if (bIndex !== -1) { - return 1; - } - - return 0; -}