diff --git a/src/NoteBookmark.BlazorApp/Components/Shared/NoteDialog.razor b/src/NoteBookmark.BlazorApp/Components/Shared/NoteDialog.razor
index a3821be..79526a6 100644
--- a/src/NoteBookmark.BlazorApp/Components/Shared/NoteDialog.razor
+++ b/src/NoteBookmark.BlazorApp/Components/Shared/NoteDialog.razor
@@ -35,8 +35,24 @@
-
-
+
+
+
+ @foreach (var tag in _currentTags)
+ {
+
+ @tag
+
+ }
+
+
+
+ AddTag(_newTagInput)" Appearance="Appearance.Lightweight" Size="Size.Small">Add
+
+
+
@@ -78,11 +94,14 @@
private List _categories = NoteCategories.GetCategories();
private bool _isEditMode = false;
+ private List _currentTags = new();
+ private string _newTagInput = string.Empty;
+
protected override void OnInitialized()
{
// Check if we're editing an existing note or creating a new one
_isEditMode = !string.IsNullOrEmpty(Content.RowKey) && !Content.RowKey.Equals(Guid.Empty.ToString(), StringComparison.OrdinalIgnoreCase);
-
+
if (_isEditMode)
{
// Editing mode - use the existing note data
@@ -93,6 +112,8 @@
// Create mode - create a new note with the PostId
_note = new Note { PostId = Content.PostId };
}
+
+ ParseTagsFromString();
}
private async Task SaveAsync()
@@ -118,5 +139,52 @@
await Dialog.CloseAsync(new NoteDialogResult { Action = "Delete", Note = _note });
}
+ private void ParseTagsFromString()
+ {
+ _currentTags = string.IsNullOrWhiteSpace(_note.Tags)
+ ? new List()
+ : _note.Tags.Split(',')
+ .Select(t => t.Trim().ToLower())
+ .Where(t => !string.IsNullOrWhiteSpace(t))
+ .Distinct()
+ .ToList();
+ }
+
+ private void SerializeTagsToString()
+ {
+ _note.Tags = _currentTags.Any() ? string.Join(", ", _currentTags) : null;
+ }
+
+ private void AddTag(string tag)
+ {
+ if (string.IsNullOrWhiteSpace(tag)) return;
+
+ var normalizedTag = tag.Trim().ToLower();
+ if (!_currentTags.Contains(normalizedTag))
+ {
+ _currentTags.Add(normalizedTag);
+ SerializeTagsToString();
+ _newTagInput = string.Empty;
+ StateHasChanged();
+ }
+ }
+
+ private void RemoveTag(string tag)
+ {
+ _currentTags.Remove(tag);
+ SerializeTagsToString();
+ StateHasChanged();
+ }
+
+ private void HandleKeyDown(KeyboardEventArgs e)
+ {
+ if (e.Key == "Enter")
+ {
+ if (!string.IsNullOrWhiteSpace(_newTagInput))
+ {
+ AddTag(_newTagInput);
+ }
+ }
+ }
}