Skip to content

Commit 011d05d

Browse files
committed
refactor(view): prevent duplicate color names when importing color from other palette
1 parent d36860a commit 011d05d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/app/view/view.component.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,12 +308,14 @@ export default class ViewComponent implements OnInit, UnsavedChangesComponent {
308308
// Track import event
309309
this._analyticsService.trackEvent(TrackingEventCategory.IMPORT_COLOR, TrackingEventAction.IMPORT_COLOR);
310310

311-
// TODO: Check for duplicate name
312-
// This can easily be done with the utility function implemented in:
313-
// https://github.com/pawcoding/Rainbow-Palette/pull/78
311+
// Check if color name already exists
312+
const colorNames = palette.colors.map((c) => c.name);
313+
color.name = deduplicateName(color.name, colorNames);
314314

315315
// Import color to current palette
316316
palette.addColor(color);
317+
318+
// Set unsaved changes
317319
this._hasUnsavedChanges.set(true);
318320
}
319321

0 commit comments

Comments
 (0)