Allow save for game edit and enable snackbar

dashboard
Pat Hartl 2023-02-05 18:03:42 -06:00
parent 74750b1dc9
commit 6c96bc5ee8
2 changed files with 26 additions and 4 deletions

View File

@ -1,11 +1,12 @@
@page "/Games/{id:guid}/Edit"
@inject GameService GameService
@inject IDialogService DialogService
@inject ISnackbar Snackbar
<MudGrid>
<MudItem xs="12">
<MudPaper Class="pa-4">
<MudForm>
<MudForm @bind-IsValid="@Success" @bind-Errors="@Errors">
<MudTextField @bind-Value="Game.Title" Label="Title" For="@(() => Game.Title)" Adornment="Adornment.End" AdornmentIcon="@Icons.Material.Filled.Search" OnAdornmentClick="LookupGameMetadata" />
<MudTextField @bind-Value="Game.SortTitle" Label="Sort Title" For="@(() => Game.SortTitle)" />
<MudTextField @bind-Value="Game.Icon" Label="Icon" Adornment="Adornment.End" AdornmentIcon="@Icons.Material.Filled.Folder" OnAdornmentClick="BrowseForIcon" />
@ -42,7 +43,7 @@
</MudChipSet>
<div class="d-flex align-center justify-space-between">
<MudButton Variant="Variant.Filled" Color="Color.Primary" Disabled="@(!Success)">Save</MudButton>
<MudButton Variant="Variant.Filled" Color="Color.Primary" Disabled="@(!Success)" OnClick="Save">Save</MudButton>
</div>
</MudForm>
</MudPaper>
@ -63,9 +64,18 @@
Game = await GameService.Get(Id);
}
private void Save()
private async Task Save()
{
try
{
Game = await GameService.Update(Game);
Snackbar.Add("Game updated!", Severity.Success);
}
catch (Exception ex)
{
Snackbar.Add("An unknown error occurred!", Severity.Error);
}
}
private async void BrowseForIcon()

View File

@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Tokens;
using MudBlazor;
using MudBlazor.Services;
using System.Text;
@ -70,7 +71,18 @@ builder.Services.AddControllersWithViews().AddJsonOptions(x =>
x.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.IgnoreCycles;
});
builder.Services.AddMudServices();
builder.Services.AddMudServices(config =>
{
config.SnackbarConfiguration.PositionClass = Defaults.Classes.Position.BottomLeft;
config.SnackbarConfiguration.PreventDuplicates = false;
config.SnackbarConfiguration.NewestOnTop = false;
config.SnackbarConfiguration.ShowCloseIcon = true;
config.SnackbarConfiguration.VisibleStateDuration = 10000;
config.SnackbarConfiguration.HideTransitionDuration = 500;
config.SnackbarConfiguration.ShowTransitionDuration = 500;
config.SnackbarConfiguration.SnackbarVariant = Variant.Filled;
});
builder.Services.AddScoped<SettingService>();
builder.Services.AddScoped<ArchiveService>();