8b0451c2ec
This commit enhances the Note entity by introducing two new properties: IsPinned and IsDeleted, allowing for better management of note visibility and status. The NoteConfiguration class has been updated to include indexes for these properties, improving query performance. Additionally, new migrations have been created to reflect these changes in the database schema. The UI components have been updated to support pinning and restoring notes, enhancing user interaction and functionality within the note management system.
145 lines
4.0 KiB
Plaintext
145 lines
4.0 KiB
Plaintext
@namespace WebApp.Components.Shared.Components
|
|
@inject INotesService NotesService
|
|
@inject ISnackbar Snackbar
|
|
@inject NavigationManager NavigationManager
|
|
@implements IAsyncDisposable
|
|
|
|
<MudDialog>
|
|
<DialogContent>
|
|
@if (_isLoading)
|
|
{
|
|
<MudProgressLinear Color="Color.Primary" Indeterminate="true" Class="my-4" />
|
|
}
|
|
else
|
|
{
|
|
<MudStack Spacing="3">
|
|
<MudText Typo="Typo.h6">@_note.Title</MudText>
|
|
@if (!string.IsNullOrWhiteSpace(_note.Content))
|
|
{
|
|
<MudPaper Elevation="0" Class="pa-3" Style="background-color: var(--mud-palette-background-grey);">
|
|
<div class="markdown-content">
|
|
@((MarkupString)MarkdownHelper.ToHtml(_note.Content))
|
|
</div>
|
|
</MudPaper>
|
|
}
|
|
else
|
|
{
|
|
<MudText Typo="Typo.body2" Color="Color.Secondary" Align="Align.Center" Class="my-4">
|
|
No content yet. Click Edit to add content.
|
|
</MudText>
|
|
}
|
|
</MudStack>
|
|
}
|
|
</DialogContent>
|
|
<DialogActions>
|
|
<MudSpacer />
|
|
<MudButton StartIcon="@Icons.Material.Filled.Edit"
|
|
Color="Color.Primary"
|
|
Variant="Variant.Filled"
|
|
OnClick="NavigateToNotes"
|
|
Disabled="@_isLoading">
|
|
Edit in Notes
|
|
</MudButton>
|
|
<MudButton OnClick="Cancel">Close</MudButton>
|
|
</DialogActions>
|
|
</MudDialog>
|
|
|
|
@code {
|
|
[CascadingParameter]
|
|
IMudDialogInstance MudDialog { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public int NoteId { get; set; }
|
|
|
|
private Note _note = null!;
|
|
private bool _isLoading = true;
|
|
private CancellationTokenSource? _cancellationTokenSource;
|
|
private bool _isDisposed = false;
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
_cancellationTokenSource = new CancellationTokenSource();
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await LoadNote();
|
|
}
|
|
|
|
private async Task LoadNote()
|
|
{
|
|
if (_isDisposed) return;
|
|
|
|
try
|
|
{
|
|
var cancellationToken = _cancellationTokenSource?.Token ?? CancellationToken.None;
|
|
var note = await NotesService.GetNoteAsync(NoteId);
|
|
|
|
if (note != null)
|
|
{
|
|
_note = new Note
|
|
{
|
|
Id = note.Id,
|
|
Title = note.Title,
|
|
Content = note.Content ?? "",
|
|
IsPinned = note.IsPinned
|
|
};
|
|
}
|
|
else
|
|
{
|
|
if (_isDisposed) return;
|
|
Snackbar.Add("Note not found", Severity.Error);
|
|
MudDialog.Cancel();
|
|
}
|
|
}
|
|
catch (TaskCanceledException)
|
|
{
|
|
// Component was disposed, ignore
|
|
}
|
|
catch (JSDisconnectedException)
|
|
{
|
|
// JS connection lost, ignore
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (!_isDisposed)
|
|
{
|
|
Snackbar.Add($"Error loading note: {ex.Message}", Severity.Error);
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
if (!_isDisposed)
|
|
{
|
|
_isLoading = false;
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void NavigateToNotes()
|
|
{
|
|
if (_isDisposed) return;
|
|
MudDialog.Close();
|
|
NavigationManager.NavigateTo($"/notes?id={_note.Id}");
|
|
}
|
|
|
|
private void Cancel()
|
|
{
|
|
if (_isDisposed) return;
|
|
MudDialog.Cancel();
|
|
}
|
|
|
|
public async ValueTask DisposeAsync()
|
|
{
|
|
if (!_isDisposed)
|
|
{
|
|
_isDisposed = true;
|
|
_cancellationTokenSource?.Cancel();
|
|
_cancellationTokenSource?.Dispose();
|
|
_cancellationTokenSource = null;
|
|
}
|
|
await ValueTask.CompletedTask;
|
|
}
|
|
}
|