1
0
mirror of synced 2024-11-23 22:41:01 +01:00

Separate page and code

This commit is contained in:
asesidaa 2022-09-12 00:33:58 +08:00
parent a147b82ecc
commit a6df13a498
8 changed files with 107 additions and 111 deletions

View File

@ -2,16 +2,12 @@
global using System.Net.Http;
global using System.Net.Http.Json;
global using Microsoft.AspNetCore.Components;
global using Microsoft.AspNetCore.Components.Forms;
global using Microsoft.AspNetCore.Components.Routing;
global using Microsoft.AspNetCore.Components.Web;
global using Microsoft.AspNetCore.Components.Web.Virtualization;
global using Microsoft.AspNetCore.Components.WebAssembly.Http;
global using MudBlazor;
global using TaikoWebUI;
global using TaikoWebUI.Shared;
global using TaikoWebUI.Services;
global using SharedProject.Models;
global using SharedProject.Models.Requests;
global using SharedProject.Models.Responses;
global using SharedProject.Enums;
global using Throw;

View File

@ -1,6 +1,4 @@
@using TaikoWebUI.Pages.Dialogs
@using SharedProject.Models.Responses
@inject HttpClient Client
@inject HttpClient Client
@inject IDialogService DialogService
@page "/Cards"
@ -88,34 +86,4 @@
</MudText>
</MudItem>
}
</MudGrid>
@code {
private DashboardResponse? response;
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
response = await Client.GetFromJsonAsync<DashboardResponse>("api/Dashboard");
}
private async Task DeleteCard(User user)
{
var parameters = new DialogParameters
{
["user"] = user
};
var dialog = DialogService.Show<CardDeleteConfirmDialog>("Delete Card", parameters);
var result = await dialog.Result;
if (result.Cancelled)
{
return;
}
response = await Client.GetFromJsonAsync<DashboardResponse>("api/Dashboard");
}
}
</MudGrid>

View File

@ -0,0 +1,33 @@
using TaikoWebUI.Pages.Dialogs;
namespace TaikoWebUI.Pages;
public partial class Cards
{
private DashboardResponse? response;
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
response = await Client.GetFromJsonAsync<DashboardResponse>("api/Dashboard");
}
private async Task DeleteCard(User user)
{
var parameters = new DialogParameters
{
["user"] = user
};
var dialog = DialogService.Show<CardDeleteConfirmDialog>("Delete Card", parameters);
var result = await dialog.Result;
if (result.Cancelled)
{
return;
}
response = await Client.GetFromJsonAsync<DashboardResponse>("api/Dashboard");
}
}

View File

@ -59,44 +59,4 @@
</MudTabPanel>
}
</MudTabs>
</MudContainer>
@code {
[Parameter]
public int Baid { get; set; }
private DanBestDataResponse? response;
private Dictionary<uint, DanBestData> bestDataMap = new();
private readonly List<BreadcrumbItem> breadcrumbs = new()
{
new BreadcrumbItem("Cards", href: "/Cards"),
};
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
response = await Client.GetFromJsonAsync<DanBestDataResponse>($"api/DanBestData/{Baid}");
response.ThrowIfNull();
bestDataMap = response.DanBestDataList.ToDictionary(data => data.DanId);
breadcrumbs.Add(new BreadcrumbItem($"Card: {Baid}", href: null, disabled: true));
breadcrumbs.Add(new BreadcrumbItem("Dani Dojo", href: $"/Cards/{Baid}/DaniDojo", disabled: false));
}
private static string DanRequirementToString(DanData.OdaiBorder data)
{
var danConditionType = (DanConditionType)data.OdaiType;
return (DanBorderType)data.BorderType switch
{
DanBorderType.All => $"{danConditionType}, Pass: {data.RedBorderTotal}, Gold: {data.GoldBorderTotal} ",
DanBorderType.PerSong => $"{danConditionType}, " +
$"Pass 1: {data.RedBorder1}, Pass 2: {data.RedBorder2}, Pass 3: {data.RedBorder3}" +
$"Gold 1: {data.GoldBorder1}, Gold 2: {data.GoldBorder1}, Pass 3: {data.GoldBorder1}",
_ => throw new ArgumentOutOfRangeException()
};
}
}
</MudContainer>

View File

@ -0,0 +1,40 @@
namespace TaikoWebUI.Pages;
public partial class DaniDojo
{
[Parameter]
public int Baid { get; set; }
private DanBestDataResponse? response;
private Dictionary<uint, DanBestData> bestDataMap = new();
private readonly List<BreadcrumbItem> breadcrumbs = new()
{
new BreadcrumbItem("Cards", href: "/Cards"),
};
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
response = await Client.GetFromJsonAsync<DanBestDataResponse>($"api/DanBestData/{Baid}");
response.ThrowIfNull();
bestDataMap = response.DanBestDataList.ToDictionary(data => data.DanId);
breadcrumbs.Add(new BreadcrumbItem($"Card: {Baid}", href: null, disabled: true));
breadcrumbs.Add(new BreadcrumbItem("Dani Dojo", href: $"/Cards/{Baid}/DaniDojo", disabled: false));
}
private static string DanRequirementToString(DanData.OdaiBorder data)
{
var danConditionType = (DanConditionType)data.OdaiType;
return (DanBorderType)data.BorderType switch
{
DanBorderType.All => $"{danConditionType}, Pass: {data.RedBorderTotal}, Gold: {data.GoldBorderTotal} ",
DanBorderType.PerSong => $"{danConditionType}, " +
$"Pass 1: {data.RedBorder1}, Pass 2: {data.RedBorder2}, Pass 3: {data.RedBorder3}" +
$"Gold 1: {data.GoldBorder1}, Gold 2: {data.GoldBorder1}, Pass 3: {data.GoldBorder1}",
_ => throw new ArgumentOutOfRangeException()
};
}
}

View File

@ -20,31 +20,4 @@
<MudText>Delete Card</MudText>
</MudButton>
</DialogActions>
</MudDialog>
@code {
[CascadingParameter]
MudDialogInstance MudDialog { get; set; } = null!;
[Parameter]
public User User { get; set; } = new();
private void Cancel() => MudDialog.Cancel();
private async Task DeleteCard()
{
var responseMessage = await Client.DeleteAsync($"api/Cards/{User.AccessCode}");
if (!responseMessage.IsSuccessStatusCode)
{
Snackbar.Add("Something went wrong when deleting card!", Severity.Error);
MudDialog.Close(DialogResult.Ok(false));
return;
}
Snackbar.Add("Delete success!", Severity.Success);
MudDialog.Close(DialogResult.Ok(true));
}
}
</MudDialog>

View File

@ -0,0 +1,28 @@
namespace TaikoWebUI.Pages.Dialogs;
public partial class CardDeleteConfirmDialog
{
[CascadingParameter]
MudDialogInstance MudDialog { get; set; } = null!;
[Parameter]
public User User { get; set; } = new();
private void Cancel() => MudDialog.Cancel();
private async Task DeleteCard()
{
var responseMessage = await Client.DeleteAsync($"api/Cards/{User.AccessCode}");
if (!responseMessage.IsSuccessStatusCode)
{
Snackbar.Add("Something went wrong when deleting card!", Severity.Error);
MudDialog.Close(DialogResult.Ok(false));
return;
}
Snackbar.Add("Delete success!", Severity.Success);
MudDialog.Close(DialogResult.Ok(true));
}
}

View File

@ -1,6 +1,4 @@
using SharedProject.Models.Responses;
namespace TaikoWebUI.Pages;
namespace TaikoWebUI.Pages;
public partial class TaikoMode
{