Sticker Creator: Use findIndex to determine cover sticker index

This commit is contained in:
automated-signal 2022-09-07 15:24:26 -07:00 committed by GitHub
parent d3e27157ef
commit 9fe1dba796
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 7 deletions

View File

@ -34,6 +34,9 @@ export const UploadStage: React.ComponentType = () => {
setComplete(i => i + 1);
};
try {
if (!cover) {
throw new Error('UploadStage: Cover was missing on upload!');
}
const packMeta = await encryptAndUpload(
{ title, author },
orderedData,

View File

@ -29,7 +29,7 @@ export type PackMetaData = { packId: string; key: string };
export type EncryptAndUploadFn = (
manifest: { title: string; author: string },
stickers: Array<StickerData>,
cover: StickerImageData | undefined,
cover: StickerImageData,
onProgress?: () => unknown
) => Promise<PackMetaData>;

View File

@ -167,11 +167,6 @@ window.encryptAndUpload = async (
useWebSocket: false,
});
const uniqueStickers = uniqBy(
[...stickers, { imageData: cover }],
'imageData'
);
const manifestProto = new Proto.StickerPack();
manifestProto.title = manifest.title;
manifestProto.author = manifest.author;
@ -185,7 +180,14 @@ window.encryptAndUpload = async (
return s;
});
const coverStickerId = 0;
const uniqueStickers = uniqBy(
[...stickers, { imageData: cover }],
'imageData'
);
const coverStickerIndex = uniqueStickers.findIndex(
item => item.imageData?.src === cover.src
);
const coverStickerId = coverStickerIndex >= 0 ? coverStickerIndex : 0;
const coverStickerData = stickers[coverStickerId];
if (!coverStickerData) {