Skip to content

Commit

Permalink
refactor(view): prevent duplicate color names when importing color fr…
Browse files Browse the repository at this point in the history
…om other palette
  • Loading branch information
pawcoding committed Aug 24, 2024
1 parent d36860a commit 011d05d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/app/view/view.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,14 @@ export default class ViewComponent implements OnInit, UnsavedChangesComponent {
// Track import event
this._analyticsService.trackEvent(TrackingEventCategory.IMPORT_COLOR, TrackingEventAction.IMPORT_COLOR);

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

// Import color to current palette
palette.addColor(color);

// Set unsaved changes
this._hasUnsavedChanges.set(true);
}

Expand Down

0 comments on commit 011d05d

Please sign in to comment.