minor fixes

This commit is contained in:
Elvy 2025-01-28 19:24:34 +01:00
parent 916d827b1b
commit bc4ed128b6

View file

@ -64,14 +64,14 @@ interface DestinationItem {
} }
interface UnspecificRowProps { interface UnspecificRowProps {
key: string key: string;
destination: DestinationItem, destination: DestinationItem,
rowMode: string rowMode: string;
disabled: boolean, disabled: boolean,
isSelected: boolean, isSelected: boolean,
onPressDestination: (destination: DestinationItem) => void, onPressDestination: (destination: DestinationItem) => void,
"aria-posinset": number, "aria-posinset": number,
"aria-setsize": number "aria-setsize": number;
} }
interface SpecificRowProps extends UnspecificRowProps { interface SpecificRowProps extends UnspecificRowProps {
@ -113,8 +113,18 @@ interface GuildResult {
} }
type Result = UserResult | ChannelResult | 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 (type === "ALL") return ["USER", "TEXT_CHANNEL", "VOICE_CHANNEL", "GROUP_DM", "GUILD"];
if (typeof type === "string") { if (typeof type === "string") {
if (type === "USERS") return ["USER"]; 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 (type === undefined || type === "ALL") return "Users, Channels, and Servers";
if (typeof type === "string") { if (typeof type === "string") {
if (type === "GUILD") return "Servers"; if (type === "GUILDS") return "Servers";
else return type.charAt(0) + type.slice(1).toLowerCase(); else return type.charAt(0) + type.slice(1).toLowerCase();
} else { } else {
if (type.length === 1) { 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. * 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 {SearchModalProps} props - The props for the SearchModal component.
* @param {ModalProps} props.modalProps - The modal props. * @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 {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 {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.subText] - Additional text to display below the heading.
* @param {string[]} [props.excludeIds] - An array of IDs to exclude from the search results. * @param {string[]} [props.excludeIds] - An array of IDs to exclude from the search results.
* @returns The rendered SearchModal component. * @returns The rendered SearchModal component.
*/ */
export default function SearchModal({ modalProps, onSubmit, input, searchType = "ALL", subText, excludeIds }: { export default function SearchModal({ modalProps, onSubmit, input, searchType = "ALL", subText, excludeIds }: SearchModalProps) {
modalProps: ModalProps;
onSubmit(selected: DestinationItem[]): void;
input?: string;
searchType?: ("USERS" | "CHANNELS" | "GUILDS")[] | "USERS" | "CHANNELS" | "GUILDS" | "ALL";
subText?: string
excludeIds?: string[],
}) {
const UserIcon = React.memo(function ({ const UserIcon = React.memo(function ({
user, user,
size = SearchBarModule.AvatarSizes.SIZE_32, size = SearchBarModule.AvatarSizes.SIZE_32,
@ -396,7 +400,7 @@ export default function SearchModal({ modalProps, onSubmit, input, searchType =
hasQuery: boolean; hasQuery: boolean;
frequentChannels: Channel[]; frequentChannels: Channel[];
channelHistory: string[]; channelHistory: string[];
guilds: GuildResult[] guilds: GuildResult[];
}): Result[] { }): Result[] {
const removeDuplicates = (arr: Result[]): Result[] => { const removeDuplicates = (arr: Result[]): Result[] => {
const clean: any[] = []; const clean: any[] = [];
@ -433,8 +437,8 @@ export default function SearchModal({ modalProps, onSubmit, input, searchType =
return ref_.current; return ref_.current;
} }
function getSearchHandler(searchOptions: Record<string, any>): { search: (e: { query: string, resultTypes: string[] }) => void, 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 }>({ const [results, setResults] = useState<{ results: Result[], query: string; }>({
results: [], results: [],
query: "" query: ""
}); });
@ -530,11 +534,11 @@ export default function SearchModal({ modalProps, onSubmit, input, searchType =
const rowHeight = useCallback(() => 48, []); 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 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; const { section, row } = e;
if (section > 0) if (section > 0)
return; return;