mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-02-24 07:25:10 +00:00
minor fixes
This commit is contained in:
parent
916d827b1b
commit
bc4ed128b6
1 changed files with 89 additions and 85 deletions
|
@ -64,14 +64,14 @@ interface DestinationItem {
|
|||
}
|
||||
|
||||
interface UnspecificRowProps {
|
||||
key: string
|
||||
key: string;
|
||||
destination: DestinationItem,
|
||||
rowMode: string
|
||||
rowMode: string;
|
||||
disabled: boolean,
|
||||
isSelected: boolean,
|
||||
onPressDestination: (destination: DestinationItem) => void,
|
||||
"aria-posinset": number,
|
||||
"aria-setsize": number
|
||||
"aria-setsize": number;
|
||||
}
|
||||
|
||||
interface SpecificRowProps extends UnspecificRowProps {
|
||||
|
@ -113,8 +113,18 @@ interface GuildResult {
|
|||
}
|
||||
|
||||
type Result = UserResult | ChannelResult | GuildResult;
|
||||
type SearchType = ("USERS" | "CHANNELS" | "GUILDS")[] | "USERS" | "CHANNELS" | "GUILDS" | "ALL";
|
||||
|
||||
const searchTypesToResultTypes = (type: string | string[]) => {
|
||||
export interface SearchModalProps {
|
||||
modalProps: ModalProps;
|
||||
onSubmit(selected: DestinationItem[]): void;
|
||||
input?: string;
|
||||
searchType?: SearchType;
|
||||
subText?: string;
|
||||
excludeIds?: string[],
|
||||
}
|
||||
|
||||
const searchTypesToResultTypes = (type: SearchType) => {
|
||||
if (type === "ALL") return ["USER", "TEXT_CHANNEL", "VOICE_CHANNEL", "GROUP_DM", "GUILD"];
|
||||
if (typeof type === "string") {
|
||||
if (type === "USERS") return ["USER"];
|
||||
|
@ -125,10 +135,10 @@ const searchTypesToResultTypes = (type: string | string[]) => {
|
|||
}
|
||||
};
|
||||
|
||||
function searchTypeToText(type: string | string[]) {
|
||||
function searchTypeToText(type: SearchType) {
|
||||
if (type === undefined || type === "ALL") return "Users, Channels, and Servers";
|
||||
if (typeof type === "string") {
|
||||
if (type === "GUILD") return "Servers";
|
||||
if (type === "GUILDS") return "Servers";
|
||||
else return type.charAt(0) + type.slice(1).toLowerCase();
|
||||
} else {
|
||||
if (type.length === 1) {
|
||||
|
@ -144,23 +154,17 @@ function searchTypeToText(type: string | string[]) {
|
|||
/**
|
||||
* SearchModal component for displaying a modal with search functionality, built after Discord's forwarding Modal.
|
||||
*
|
||||
* @param {Object} props - The props for the SearchModal component.
|
||||
* @param {ModalProps} props.modalProps - The modal props.
|
||||
* @param {SearchModalProps} props - The props for the SearchModal component.
|
||||
* @param {ModalProps} props.modalProps - The modal props. You get these from the `openModal` function.
|
||||
* @param {function} props.onSubmit - The function to call when the user submits their selection.
|
||||
* @param {string} [props.input] - The initial input value for the search bar.
|
||||
* @param {("USERS" | "CHANNELS" | "GUILDS")[] | "USERS" | "CHANNELS" | "GUILDS" | "ALL"} [props.searchType="ALL"] - The type of items to search for.
|
||||
* @param {SearchType} [props.searchType="ALL"] - The type of items to search for.
|
||||
* @param {string} [props.subText] - Additional text to display below the heading.
|
||||
* @param {string[]} [props.excludeIds] - An array of IDs to exclude from the search results.
|
||||
* @returns The rendered SearchModal component.
|
||||
*/
|
||||
export default function SearchModal({ modalProps, onSubmit, input, searchType = "ALL", subText, excludeIds }: {
|
||||
modalProps: ModalProps;
|
||||
onSubmit(selected: DestinationItem[]): void;
|
||||
input?: string;
|
||||
searchType?: ("USERS" | "CHANNELS" | "GUILDS")[] | "USERS" | "CHANNELS" | "GUILDS" | "ALL";
|
||||
subText?: string
|
||||
excludeIds?: string[],
|
||||
}) {
|
||||
export default function SearchModal({ modalProps, onSubmit, input, searchType = "ALL", subText, excludeIds }: SearchModalProps) {
|
||||
|
||||
const UserIcon = React.memo(function ({
|
||||
user,
|
||||
size = SearchBarModule.AvatarSizes.SIZE_32,
|
||||
|
@ -396,7 +400,7 @@ export default function SearchModal({ modalProps, onSubmit, input, searchType =
|
|||
hasQuery: boolean;
|
||||
frequentChannels: Channel[];
|
||||
channelHistory: string[];
|
||||
guilds: GuildResult[]
|
||||
guilds: GuildResult[];
|
||||
}): Result[] {
|
||||
const removeDuplicates = (arr: Result[]): Result[] => {
|
||||
const clean: any[] = [];
|
||||
|
@ -433,8 +437,8 @@ export default function SearchModal({ modalProps, onSubmit, input, searchType =
|
|||
return ref_.current;
|
||||
}
|
||||
|
||||
function getSearchHandler(searchOptions: Record<string, any>): { search: (e: { query: string, resultTypes: string[] }) => void, results: Result[], query: string } {
|
||||
const [results, setResults] = useState<{ results: Result[], query: string }>({
|
||||
function getSearchHandler(searchOptions: Record<string, any>): { search: (e: { query: string, resultTypes: string[]; }) => void, results: Result[], query: string; } {
|
||||
const [results, setResults] = useState<{ results: Result[], query: string; }>({
|
||||
results: [],
|
||||
query: ""
|
||||
});
|
||||
|
@ -530,11 +534,11 @@ export default function SearchModal({ modalProps, onSubmit, input, searchType =
|
|||
|
||||
const rowHeight = useCallback(() => 48, []);
|
||||
|
||||
function ModalScroller({ rowData, handleToggleDestination, paddingBottom, paddingTop }: { rowData: Result[], handleToggleDestination: (destination: DestinationItem) => void, paddingBottom?: number, paddingTop?: number }) {
|
||||
function ModalScroller({ rowData, handleToggleDestination, paddingBottom, paddingTop }: { rowData: Result[], handleToggleDestination: (destination: DestinationItem) => void, paddingBottom?: number, paddingTop?: number; }) {
|
||||
|
||||
const sectionCount: number[] = useMemo(() => [rowData.length], [rowData.length]);
|
||||
|
||||
const callback = useCallback((e: { section: number, row: number }) => {
|
||||
const callback = useCallback((e: { section: number, row: number; }) => {
|
||||
const { section, row } = e;
|
||||
if (section > 0)
|
||||
return;
|
||||
|
|
Loading…
Add table
Reference in a new issue