Files
discord-decomp/modules/emoji_picker/native/components/useComputeEmojiPickerFunctions.tsx
T
2026-11-01 12:12:55 +02:00

182 lines
5.9 KiB
TypeScript

// Metro module 9357 (f9358).
import _slicedToArray from "../../../../_bundle/_slicedToArray";
import { useState } from "react";
import { EmojiCategories, EmojiCategoryTypes } from "../../EmojiPickerConstants";
import { EmojiPickerRenderingDataType } from "./EmojiPickerListConstants";
import { shouldNSFWGateGuild } from "../../../age_gate/native/AgeGateUtils";
import UnicodeEmojis from "../../../emojis/UnicodeEmojis";
import Module12 from "../../../../_bundle/Module12";
import { getStringForEmojiCategory } from "../../EmojiPickerUtils";
import { cachedFunction } from "../../../../utils/FunctionUtils";
let _computeSearchResults, pushCategory, pushNativeCategory;
const _computeCategories = function _computeCategories({ categories, rowSize, isNativeEmojiPickerEnabled }) {
const emojiSections = [];
for (const item of categories) {
const type = item.type;
if (EmojiCategoryTypes.TOP_GUILD_EMOJI === type) {
pushCategory({
emojiSections,
renderingData: {
type: EmojiPickerRenderingDataType.EMOJI,
emojis: item.emojis.slice(0, rowSize),
emojisDisabled: item.emojisDisabled,
label: item.name,
footer: EmojiCategoryTypes.TOP_GUILD_EMOJI
},
rowSize
});
} else if (EmojiCategoryTypes.FAVORITES === type) {
pushCategory({
emojiSections,
renderingData: {
type: EmojiPickerRenderingDataType.EMOJI,
emojis: item.emojis,
emojisDisabled: item.emojisDisabled,
label: item.name,
footer: EmojiCategoryTypes.FAVORITES
},
rowSize
});
} else if (EmojiCategoryTypes.RECENT === type) {
pushCategory({
emojiSections,
renderingData: {
type: EmojiPickerRenderingDataType.EMOJI,
emojisDisabled: item.emojisDisabled,
emojis: item.emojis,
label: item.name,
footer: EmojiCategoryTypes.RECENT
},
rowSize
});
} else if (EmojiCategoryTypes.GUILD === type) {
const { guild, emojis, emojisDisabled, emojisHidden } = item;
if (isNativeEmojiPickerEnabled) {
pushNativeCategory({
emojiSections,
renderingData: {
type: EmojiPickerRenderingDataType.NATIVE_SECTION,
label: guild.name,
guildId: guild.id,
emojiCount: emojis.length,
emojisDisabled,
emojisHidden,
isSectionNitroLocked: item.isNitroLocked
}
});
} else if (shouldNSFWGateGuild(guild.id)) {
emojiSections.push({
type: EmojiPickerRenderingDataType.NSFW,
label: guild.name,
footer: EmojiCategoryTypes.GUILD,
emojis: [],
isSectionNitroLocked: item.isNitroLocked
});
} else {
pushCategory({
emojiSections,
renderingData: {
type: EmojiPickerRenderingDataType.EMOJI,
emojis,
emojisDisabled,
label: guild.name,
footer: EmojiCategoryTypes.GUILD,
isSectionNitroLocked: item.isNitroLocked
},
rowSize
});
}
} else if (EmojiCategoryTypes.UNICODE === type) {
const byCategory = UnicodeEmojis.getByCategory(item.name);
if (isNativeEmojiPickerEnabled) {
const renderingData = {
type: EmojiPickerRenderingDataType.NATIVE_SECTION,
label: Module12.capitalize(item.name),
emojiCount: null,
emojisDisabled: null,
emojisHidden: null
};
let emojiCount = byCategory?.length;
if (emojiCount == null) {
emojiCount = 0;
}
renderingData.emojiCount = emojiCount;
renderingData.emojisDisabled = new Set();
renderingData.emojisHidden = new Set();
pushNativeCategory({
emojiSections,
renderingData
});
} else {
let emojis2 = byCategory;
if (emojis2 == null) {
emojis2 = [];
}
pushCategory({
emojiSections,
renderingData: {
type: EmojiPickerRenderingDataType.EMOJI,
emojis: emojis2,
emojisDisabled: new Set(),
label: Module12.capitalize(item.name),
footer: EmojiCategoryTypes.UNICODE
},
rowSize
});
}
}
}
return emojiSections;
};
_computeSearchResults = function _computeSearchResults(a0) {
const emojis = a0.emojis;
const { locked, unlocked } = emojis;
const { rowSize, limit = Number.MAX_SAFE_INTEGER } = a0;
const emojiSections = [];
pushCategory({
emojiSections,
renderingData: {
type: EmojiPickerRenderingDataType.EMOJI,
emojis: unlocked.length > limit ? unlocked.slice(0, limit) : unlocked,
emojisDisabled: new Set(),
label: "",
footer: EmojiCategoryTypes.SEARCH_RESULTS
},
rowSize
});
const emojis2 = locked.length > limit ? locked.slice(0, limit) : locked;
const set = new Set();
for (const item of locked) {
if (item.id != null) {
set.add(item.id);
}
}
pushCategory({
emojiSections,
renderingData: {
type: EmojiPickerRenderingDataType.EMOJI,
emojis: emojis2,
emojisDisabled: set,
label: getStringForEmojiCategory(EmojiCategories.PREMIUM_UPSELL),
footer: EmojiCategoryTypes.PREMIUM_UPSELL
},
rowSize
});
return emojiSections;
};
pushCategory = function pushCategory(a0) {
const emojis = a0.renderingData.emojis;
if (emojis != null && emojis.length !== 0) {
a0.emojiSections.push(a0.renderingData);
}
};
pushNativeCategory = function pushNativeCategory(a0) {
a0.emojiSections.push(a0.renderingData);
};
export default function useComputeEmojiPickerFunctions() {
return _slicedToArray(useState(() => ({
computeCategories: cachedFunction(_computeCategories),
computeSearchResults: cachedFunction(_computeSearchResults)
})), 1)[0];
};