feat : merge mat
CI / Verify (push) Successful in 1m31s
CI / Build immutable images and deploy (push) Successful in 4m0s

This commit is contained in:
2026-09-06 18:05:48 +07:00 Unverified
parent 770c60c4a2
commit 6dc8e3afaa
3 changed files with 60 additions and 8 deletions
+33
View File
@@ -0,0 +1,33 @@
export type PosterMaterial = {
key: string;
amount: number;
name: string;
imageUrl: string | null;
};
export function mergePosterMaterials(materials: PosterMaterial[]): PosterMaterial[] {
const merged: PosterMaterial[] = [];
const indexByImageUrl = new Map<string, number>();
for (const material of materials) {
if (!material.imageUrl) {
merged.push(material);
continue;
}
const existingIndex = indexByImageUrl.get(material.imageUrl);
if (existingIndex === undefined) {
indexByImageUrl.set(material.imageUrl, merged.length);
merged.push(material);
continue;
}
const existing = merged[existingIndex];
merged[existingIndex] = {
...existing,
amount: existing.amount + material.amount,
};
}
return merged;
}