Sticker Creator: Use findIndex to determine cover sticker index
This commit is contained in:
parent
c76b6d66ca
commit
928acbaf41
3 changed files with 12 additions and 7 deletions
|
@ -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,
|
||||
|
|
|
@ -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>;
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue