mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-02-24 15:35:11 +00:00
more slight improvements
This commit is contained in:
parent
fcdfd0795a
commit
25dd64dd11
1 changed files with 30 additions and 29 deletions
|
@ -16,7 +16,7 @@ import {
|
||||||
ModalRoot,
|
ModalRoot,
|
||||||
ModalSize
|
ModalSize
|
||||||
} from "@utils/modal";
|
} from "@utils/modal";
|
||||||
import { findByCodeLazy, findByPropsLazy, findComponentByCodeLazy } from "@webpack";
|
import { findByCodeLazy, findByPropsLazy, findComponentByCodeLazy, findStoreLazy } from "@webpack";
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
ChannelStore,
|
ChannelStore,
|
||||||
|
@ -33,7 +33,7 @@ import {
|
||||||
UsernameUtils,
|
UsernameUtils,
|
||||||
UserStore,
|
UserStore,
|
||||||
useState,
|
useState,
|
||||||
useStateFromStores
|
useStateFromStores,
|
||||||
} from "@webpack/common";
|
} from "@webpack/common";
|
||||||
import { Channel, Guild, User } from "discord-types/general";
|
import { Channel, Guild, User } from "discord-types/general";
|
||||||
|
|
||||||
|
@ -42,19 +42,21 @@ const cl = classNameFactory("vc-search-modal-");
|
||||||
const SearchBarModule = findByPropsLazy("SearchBar", "Checkbox", "AvatarSizes");
|
const SearchBarModule = findByPropsLazy("SearchBar", "Checkbox", "AvatarSizes");
|
||||||
const SearchBarWrapper = findByPropsLazy("SearchBar", "Item");
|
const SearchBarWrapper = findByPropsLazy("SearchBar", "Item");
|
||||||
const TextTypes = findByPropsLazy("APPLICATION", "GROUP_DM", "GUILD");
|
const TextTypes = findByPropsLazy("APPLICATION", "GROUP_DM", "GUILD");
|
||||||
const FrequencyModule = findByPropsLazy("getFrequentlyWithoutFetchingLatest");
|
const SearchHandler = findByCodeLazy("createSearchContext", "setLimit");
|
||||||
const FrequentsModule = findByPropsLazy("getChannelHistory", "getFrequentGuilds");
|
|
||||||
|
|
||||||
const convertItem = findByCodeLazy("GROUP_DM:return{", "GUILD_VOICE:case");
|
const convertItem = findByCodeLazy("GROUP_DM:return{", "GUILD_VOICE:case");
|
||||||
const loadFunction = findByCodeLazy(".frecencyWithoutFetchingLatest)");
|
const loadFrecency = findByCodeLazy(".frecencyWithoutFetchingLatest)");
|
||||||
const SearchHandler = findByCodeLazy("createSearchContext", "setLimit");
|
|
||||||
const navigatorWrapper = findByCodeLazy("useMemo(()=>({onKeyDown:");
|
const navigatorWrapper = findByCodeLazy("useMemo(()=>({onKeyDown:");
|
||||||
const createNavigator = findByCodeLazy(".keyboardModeEnabled)", "useCallback(()=>new Promise(", "Number.MAX_SAFE_INTEGER");
|
const createNavigator = findByCodeLazy(".keyboardModeEnabled)", "useCallback(()=>new Promise(", "Number.MAX_SAFE_INTEGER");
|
||||||
const getChannelLabel = findByCodeLazy("recipients.map(", "getNickname(");
|
const getChannelLabel = findByCodeLazy("recipients.map(", "getNickname(");
|
||||||
const ChannelIcon = findByCodeLazy("channelGuildIcon,");
|
|
||||||
|
|
||||||
|
const ChannelIcon = findComponentByCodeLazy("channelGuildIcon,");
|
||||||
const GroupDMAvatars = findComponentByCodeLazy("facepileSizeOverride", "recipients.length");
|
const GroupDMAvatars = findComponentByCodeLazy("facepileSizeOverride", "recipients.length");
|
||||||
|
|
||||||
|
const FrecencyStore = findStoreLazy("FrecencyStore");
|
||||||
|
const QuickSwitcherStore = findStoreLazy("QuickSwitcherStore");
|
||||||
|
|
||||||
|
|
||||||
interface DestinationItem {
|
interface DestinationItem {
|
||||||
type: "channel" | "user" | "guild";
|
type: "channel" | "user" | "guild";
|
||||||
id: string;
|
id: string;
|
||||||
|
@ -278,14 +280,10 @@ export default function SearchModal({ modalProps, onSubmit, input, searchType =
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateChannelLabel(channel: Channel): string {
|
|
||||||
return getChannelLabel(channel, UserStore, RelationshipStore, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
function generateChannelItem(channel: Channel, otherProps: UnspecificRowProps) {
|
function generateChannelItem(channel: Channel, otherProps: UnspecificRowProps) {
|
||||||
const guild = GuildStore.getGuild(channel?.guild_id);
|
const guild = GuildStore.getGuild(channel?.guild_id);
|
||||||
|
|
||||||
const channelLabel = generateChannelLabel(channel);
|
const channelLabel = getChannelLabel(channel, UserStore, RelationshipStore, false);
|
||||||
|
|
||||||
const parentChannelLabel = (): string => {
|
const parentChannelLabel = (): string => {
|
||||||
const parentChannel = ChannelStore.getChannel(channel.parent_id);
|
const parentChannel = ChannelStore.getChannel(channel.parent_id);
|
||||||
|
@ -492,9 +490,21 @@ export default function SearchModal({ modalProps, onSubmit, input, searchType =
|
||||||
}
|
}
|
||||||
, [search, queryData]);
|
, [search, queryData]);
|
||||||
|
|
||||||
loadFunction();
|
loadFrecency();
|
||||||
|
|
||||||
|
const frequentChannels: Channel[] = useStateFromStores([FrecencyStore], () => FrecencyStore.getFrequentlyWithoutFetchingLatest());
|
||||||
|
const channelHistory: string[] = useStateFromStores([QuickSwitcherStore], () => QuickSwitcherStore.getChannelHistory());
|
||||||
|
const guilds: GuildResult[] = useStateFromStores([GuildStore], () => Object.values(GuildStore.getGuilds()).map(
|
||||||
|
guild => {
|
||||||
|
return {
|
||||||
|
type: TextTypes.GUILD,
|
||||||
|
record: guild,
|
||||||
|
score: 0,
|
||||||
|
comparator: guild.name
|
||||||
|
};
|
||||||
|
}
|
||||||
|
));
|
||||||
|
|
||||||
const frequentChannels: Channel[] = useStateFromStores([FrequencyModule], () => FrequencyModule.getFrequentlyWithoutFetchingLatest());
|
|
||||||
const hasQuery = query !== "";
|
const hasQuery = query !== "";
|
||||||
|
|
||||||
function getItem(e: DestinationItem): Result {
|
function getItem(e: DestinationItem): Result {
|
||||||
|
@ -532,6 +542,8 @@ export default function SearchModal({ modalProps, onSubmit, input, searchType =
|
||||||
hasQuery: boolean;
|
hasQuery: boolean;
|
||||||
frequentChannels: Channel[];
|
frequentChannels: Channel[];
|
||||||
pinnedDestinations: DestinationItem[];
|
pinnedDestinations: DestinationItem[];
|
||||||
|
channelHistory: string[];
|
||||||
|
guilds: GuildResult[]
|
||||||
}): Result[] {
|
}): Result[] {
|
||||||
const removeDuplicates = (arr: Result[]): Result[] => {
|
const removeDuplicates = (arr: Result[]): Result[] => {
|
||||||
const clean: any[] = [];
|
const clean: any[] = [];
|
||||||
|
@ -546,22 +558,9 @@ export default function SearchModal({ modalProps, onSubmit, input, searchType =
|
||||||
return clean;
|
return clean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const { results, hasQuery, frequentChannels, pinnedDestinations } = props;
|
const { results, hasQuery, frequentChannels, pinnedDestinations, channelHistory, guilds } = props;
|
||||||
if (hasQuery) return filterItems(results);
|
if (hasQuery) return filterItems(results);
|
||||||
|
|
||||||
const channelHistory: string[] = FrequentsModule.getChannelHistory();
|
|
||||||
const guilds = Object.values(GuildStore.getGuilds()).map(
|
|
||||||
guild => {
|
|
||||||
if (guild == null) return;
|
|
||||||
return {
|
|
||||||
type: TextTypes.GUILD,
|
|
||||||
record: guild,
|
|
||||||
score: 0,
|
|
||||||
comparator: guild.name
|
|
||||||
};
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
const recentDestinations = filterItems([
|
const recentDestinations = filterItems([
|
||||||
...(channelHistory.length > 0 ? channelHistory.map(e => convertItem(e)) : []),
|
...(channelHistory.length > 0 ? channelHistory.map(e => convertItem(e)) : []),
|
||||||
...(frequentChannels.length > 0 ? frequentChannels.map(e => convertItem(e.id)) : []),
|
...(frequentChannels.length > 0 ? frequentChannels.map(e => convertItem(e.id)) : []),
|
||||||
|
@ -580,7 +579,9 @@ export default function SearchModal({ modalProps, onSubmit, input, searchType =
|
||||||
hasQuery: hasQuery,
|
hasQuery: hasQuery,
|
||||||
frequentChannels: frequentChannels,
|
frequentChannels: frequentChannels,
|
||||||
pinnedDestinations: pinned,
|
pinnedDestinations: pinned,
|
||||||
}), [results, hasQuery, frequentChannels, pinned]),
|
channelHistory: channelHistory,
|
||||||
|
guilds: guilds
|
||||||
|
}), [results, hasQuery, frequentChannels, pinned, channelHistory, guilds]),
|
||||||
updateSearchText: updateSearch
|
updateSearchText: updateSearch
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue