5c4aaf91df
This commit introduces the Note and NoteHistory entities, along with their respective configurations for Entity Framework Core. The AppDbContext has been updated to include DbSet properties for both entities. A new INotesService interface and its implementation, NotesService, have been created to handle CRUD operations for notes, including history tracking. Additionally, several Blazor components have been added for note management, including dialogs for editing notes and viewing note history. The UI has been enhanced to support markdown content rendering and improved user interaction for note creation and editing. These changes contribute to a comprehensive note-taking feature within the application.
89 lines
2.4 KiB
Plaintext
89 lines
2.4 KiB
Plaintext
@using Core.Entities
|
|
@using WebApp.Services
|
|
@using PSC.Blazor.Components.MarkdownEditor
|
|
@using MudBlazor
|
|
@inject INotesService NotesService
|
|
@inject ISnackbar Snackbar
|
|
@inject IDialogService DialogService
|
|
|
|
<MudDialog>
|
|
<DialogContent>
|
|
<MudStack Spacing="3">
|
|
<MudTextField @bind-Value="_note.Title"
|
|
Label="Title"
|
|
Variant="Variant.Outlined"
|
|
Required="true"
|
|
RequiredError="Title is required"
|
|
MaxLength="200" />
|
|
|
|
<MudText Typo="Typo.subtitle2" Class="mb-2">Content (Markdown)</MudText>
|
|
<MarkdownEditor Value="@_note.Content"
|
|
ValueChanged="@((string? value) => _note.Content = value)"
|
|
Placeholder="Enter your markdown content here..."
|
|
AutoSaveEnabled="false"
|
|
NativeSpellChecker="false" />
|
|
</MudStack>
|
|
</DialogContent>
|
|
<DialogActions>
|
|
<MudButton OnClick="Cancel">Cancel</MudButton>
|
|
<MudButton Color="Color.Primary" Variant="Variant.Filled" OnClick="Save">Save</MudButton>
|
|
</DialogActions>
|
|
</MudDialog>
|
|
|
|
@code {
|
|
[CascadingParameter]
|
|
IMudDialogInstance MudDialog { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public Note Note { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public bool IsEdit { get; set; }
|
|
|
|
private Note _note = null!;
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
_note = new Note
|
|
{
|
|
Id = Note.Id,
|
|
Title = Note.Title ?? "",
|
|
Content = Note.Content ?? ""
|
|
};
|
|
}
|
|
|
|
private async Task Save()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(_note.Title))
|
|
{
|
|
Snackbar.Add("Title is required", Severity.Warning);
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
if (IsEdit)
|
|
{
|
|
await NotesService.UpdateNoteAsync(_note);
|
|
Snackbar.Add("Note updated successfully", Severity.Success);
|
|
}
|
|
else
|
|
{
|
|
await NotesService.CreateNoteAsync(_note);
|
|
Snackbar.Add("Note created successfully", Severity.Success);
|
|
}
|
|
|
|
MudDialog.Close(DialogResult.Ok(true));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Snackbar.Add($"Error saving note: {ex.Message}", Severity.Error);
|
|
}
|
|
}
|
|
|
|
private void Cancel()
|
|
{
|
|
MudDialog.Cancel();
|
|
}
|
|
}
|