Add PageNoteButton to various components for enhanced note management

This commit is contained in:
2026-01-17 10:25:38 -05:00
parent 947d95893f
commit e6eb35ee67
15 changed files with 69 additions and 19 deletions
@@ -4,7 +4,7 @@
@* Reuse dialog options pattern - could be extracted if used in more places *@
<MudItem xs="12" sm="6" md="4">
<MudCard Elevation="4" Class="pa-4" Style="cursor: pointer; height: 100%;" @onclick="OpenNoteDialog">
<MudCard Elevation="4" Class="@($"pa-4 {MarkdownHelper.GetNoteColorClass(Note.Id)}".Trim())" Style="cursor: pointer; height: 100%;" @onclick="OpenNoteDialog">
<MudCardContent>
<div class="d-flex align-center mb-2">
<MudIcon Icon="@Icons.Material.Filled.Note" Size="Size.Medium" Class="mr-2" />
@@ -4,7 +4,7 @@
@inject NavigationManager NavigationManager
@implements IAsyncDisposable
<MudDialog>
<MudDialog Class="@MarkdownHelper.GetNoteColorClass(NoteId)">
<DialogContent>
@if (_isLoading)
{
@@ -8,7 +8,8 @@
Variant="@Variant"
Size="@Size"
Color="@ButtonColor"
Tooltip="@TooltipText">
Tooltip="@TooltipText"
Class="@MarkdownHelper.GetNoteColorClass(_noteId)">
@if (!string.IsNullOrEmpty(ButtonText))
{
@ButtonText
@@ -37,6 +38,7 @@
private string IconValue => Icon ?? Icons.Material.Filled.Note;
private string TooltipText => Tooltip ?? $"Page notes for {PageIdentifier}";
private bool _hasContent = false;
private int _noteId = 0;
private Color ButtonColor => _hasContent ? Color.Success : (Variant == Variant.Filled ? Color.Primary : Color.Default);
private CancellationTokenSource? _cancellationTokenSource;
private bool _isDisposed = false;
@@ -59,6 +61,7 @@
{
var note = await NotesService.GetPageNoteAsync(PageIdentifier);
_hasContent = note != null && !string.IsNullOrWhiteSpace(note.Content);
_noteId = note?.Id ?? 0;
if (!_isDisposed)
{
@@ -100,8 +103,9 @@
var dialog = await DialogService.ShowAsync<PageNoteDialog>($"Page Notes: {PageIdentifier}", parameters, options);
var result = await dialog.Result;
// Refresh content indicator after dialog closes
if (!result.Canceled && !_isDisposed)
// Always refresh content indicator after dialog closes
// (content may have been saved even if dialog was closed with Cancel)
if (!_isDisposed)
{
await CheckNoteContent();
}
@@ -3,7 +3,7 @@
@inject ISnackbar Snackbar
@implements IAsyncDisposable
<MudDialog>
<MudDialog Class="@MarkdownHelper.GetNoteColorClass(_note.Id)">
<DialogContent>
@if (_isLoading)
{
@@ -167,15 +167,21 @@
}
else
{
await NotesService.CreateNoteAsync(_note);
// CreateNoteAsync returns the note with the ID populated
var createdNote = await NotesService.CreateNoteAsync(_note);
// Update _note with the returned note to get the ID immediately
_note = createdNote;
_isEdit = true; // Mark as existing note now
Snackbar.Add("Page note created successfully", Severity.Success);
}
if (!_isDisposed)
{
// After saving, switch back to view mode and reload the note
// After saving, switch back to view mode and reload the note to ensure we have latest data
_isEditMode = false;
await LoadPageNote();
// Ensure dialog re-renders with updated color class after note ID is set
StateHasChanged();
}
}
catch (TaskCanceledException)