Skip to content

Commit

Permalink
Revert "Merge pull request #2122 from glifem/cfx-ui-sorting-name"
Browse files Browse the repository at this point in the history
This reverts commit 81968d9, reversing
changes made to 8b8d9f6.
  • Loading branch information
nihonium-cfx committed Oct 10, 2023
1 parent e12a02b commit 9bb323b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 72 deletions.
15 changes: 1 addition & 14 deletions ext/cfx-ui/src/cfx/base/serverUtils.ts
Expand Up @@ -6,7 +6,7 @@ import emojiRegex from 'emoji-regex';
import { IServerListConfig, ServersListType } from "cfx/common/services/servers/lists/types";

This comment has been minimized.

Copy link
@pat013

pat013 Oct 19, 2023

wtts

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';
Expand Down Expand Up @@ -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
*/
Expand Down
Expand Up @@ -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";
Expand Down Expand Up @@ -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(
Expand Down
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
));
}

Expand Down
47 changes: 1 addition & 46 deletions 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";
Expand Down Expand Up @@ -102,48 +102,3 @@ function sortByProperty(servers: Record<string, IListableServerView>, property:

return -dir;
}

export const sortFilteredList = (servers: Record<string, IListableServerView>, 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<string, IListableServerView>, 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;
}

0 comments on commit 9bb323b

Please sign in to comment.