Files
discord-decomp/modules/stickers/native/useStickerPickerListData.tsx
T
2026-11-01 12:12:55 +02:00

114 lines
3.6 KiB
TypeScript

// Metro module 9652 (f9653).
import { useMemo } from "react";
import { useStickerPickerStore } from "./StickerPickerStore";
import { LABEL_HEIGHT, MIN_MARGIN, STICKER_SIZE, ROW_HEIGHT } from "./StickerPickerConstants";
import { PADDING_VERTICAL } from "../../expression_picker/ExpressionPickerConstants";
import { useStickerCategories } from "./StickersUtils";
import Module12 from "../../../_bundle/Module12";
import { intl, t } from "../../../intl/index.native";
import { StickerCategoryTypes } from "../StickersTypes";
import { shouldNSFWGateGuild } from "../../age_gate/native/AgeGateUtils";
function $mk115521($env) {
return (a0) => $env[2].includes(a0.format_type);
}
let env6382 = {};
const c6382_8 = {
STICKERS: 0,
0: "STICKERS",
NSFW: 1,
1: "NSFW"
};
const c6382_9 = LABEL_HEIGHT + 2 * PADDING_VERTICAL;
export default function useStickerPickerListData(a0) {
let env17374 = {
$parent: env6382
};
const { channel, containerWidth } = a0;
env17374[0] = containerWidth;
const searchResults = a0.searchResults;
env17374[1] = searchResults;
const stickerFormats = a0.stickerFormats;
env17374[2] = stickerFormats;
env17374[3] = void 0;
env17374[4] = void 0;
const stickerCategories = useStickerCategories(channel);
env17374[3] = stickerCategories;
const r16 = (0, useStickerPickerStore)((a0) => a0.packToScrollTo);
env17374[4] = r16;
return useMemo(() => {
let packToScrollToIndex;
const r12 = env17374;
const rowSize = Math.floor((env17374[0] - MIN_MARGIN) / (STICKER_SIZE + MIN_MARGIN));
let c26501_0 = rowSize;
const sections = [];
let c26501_1 = sections;
const sectionHeights = [];
const sectionLabels = [];
let c26501_2 = sectionLabels;
const rowsBySection = [];
let c26501_3 = rowsBySection;
packToScrollToIndex = void 0;
const r14 = env17374[1];
if (r14 != null) {
let r48 = intl.string(t["zkoeq/"]);
if (r48 === void 0) {
r48 = "";
}
const stickersByRow = Module12.chunk(r14.filter($mk115521(r12)), rowSize);
rowsBySection.push({
type: c6382_8.STICKERS,
stickersByRow
});
sections.push(stickersByRow.length);
sectionLabels.push(r48);
} else {
let c26502_0;
env17374[3].map((item, index) => {
const r6 = env17374;
if (env17374[4] === item.id) {
packToScrollToIndex = index;
}
const r18 = item.type === StickerCategoryTypes.GUILD && shouldNSFWGateGuild(item.id);
const { stickers, name = "" } = item;
if (r18 === true) {
c26501_3.push({
type: c6382_8.NSFW,
stickersByRow: []
});
c26501_1.push(1);
} else {
const stickersByRow = Module12.chunk(stickers.filter($mk115521(r6)), c26501_0);
c26501_3.push({
type: c6382_8.STICKERS,
stickersByRow
});
c26501_1.push(stickersByRow.length);
}
c26501_2.push(name);
});
const push = sectionHeights.push;
c26502_0 = 0;
push.apply(sectionHeights, [...sections.map((section, index) => {
if (index === 0 && section === 0) {
return 0;
}
const r12 = section * ROW_HEIGHT + c6382_9 + 12 + c26502_0;
c26502_0 = r12;
return r12;
})]);
}
return {
sections,
sectionHeights,
sectionSize: c6382_9,
sectionFooterSize: 12,
sectionLabels,
rowHeight: ROW_HEIGHT,
rowSize,
rowsBySection,
packToScrollToIndex
};
}, [containerWidth, stickerCategories, stickerFormats, searchResults, r16]);
};
export { c6382_8 as StickerPickerSectionType };