From 4272690682e9f89344c1d512f770466939c1a52c Mon Sep 17 00:00:00 2001 From: pawcode Development Date: Fri, 16 Aug 2024 22:59:28 +0200 Subject: [PATCH] fix(generator): prevent generated palette from having duplicate color names --- src/app/shared/data-access/palette.service.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/app/shared/data-access/palette.service.ts b/src/app/shared/data-access/palette.service.ts index b0cbf40..895b607 100644 --- a/src/app/shared/data-access/palette.service.ts +++ b/src/app/shared/data-access/palette.service.ts @@ -5,6 +5,7 @@ import { Value } from '../model'; import { Color } from '../model/color.model'; import { Palette } from '../model/palette.model'; import { Shade } from '../model/shade.model'; +import { deduplicateName } from '../utils/deduplicate-name'; import { ColorNameService } from './color-name.service'; import { ColorService } from './color.service'; import { ListService } from './list.service'; @@ -120,7 +121,11 @@ export class PaletteService { for (const color of palette.colors) { // Get the color name - color.name = await this._colorNameService.getColorName(color.shades[0]); + const generatedName = await this._colorNameService.getColorName(color.shades[0]); + + // Deduplicate the name + const existingNames = palette.colors.map((c) => c.name); + color.name = deduplicateName(generatedName, existingNames); // Regenerate the shades await this._colorService.regenerateShades(color);