Sticker Creator: Use findIndex to determine cover sticker index

This commit is contained in:
Scott Nonnenberg 2022-09-07 15:10:15 -07:00 committed by GitHub
parent c76b6d66ca
commit 928acbaf41
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) {