1
0
mirror of synced 2025-02-25 22:28:01 +01:00

Update to use server data instead of mock data

This commit is contained in:
Yuchen Ji 2022-06-20 02:10:34 +08:00
parent 003f655585
commit 4871c0bf6f
5 changed files with 30 additions and 19 deletions

View File

@ -2,6 +2,7 @@
@using SharedProject.models @using SharedProject.models
@using MudAdmin.Utils @using MudAdmin.Utils
@using SharedProject.enums @using SharedProject.enums
@inject HttpClient Client
<PageTitle>User</PageTitle> <PageTitle>User</PageTitle>
@ -143,9 +144,9 @@ else
private UserDetail? userDetail; private UserDetail? userDetail;
private List<SongPlayData> songPlayDataList = null!; private List<SongPlayData> songPlayDataList = new();
private bool isSavingOptions = false; private bool isSavingOptions;
private static readonly ScoreGradeMap[] GRADES = private static readonly ScoreGradeMap[] GRADES =
{ {
@ -159,18 +160,15 @@ else
new(990000, "S++"), new(990000, "S++"),
}; };
protected override void OnInitialized() protected override async Task OnInitializedAsync()
{ {
var details = MockDataRepo.GetMockDataRepo().UserDetails; await base.OnInitializedAsync();
userDetail = details.First(detail => detail.CardId == CardId); userDetail = await Client.GetFromJsonAsync<UserDetail>($"api/UserDetail/{CardId}") ?? new();
if (userDetail != null) songPlayDataList = userDetail.SongPlayDataList ?? new List<SongPlayData>();
{ feverTranceShow = userDetail.PlayOption.FeverTrance;
feverTranceShow = userDetail.PlayOption.FeverTrance; fastSlowIndicator = userDetail.PlayOption.FastSlowIndicator;
fastSlowIndicator = userDetail.PlayOption.FastSlowIndicator;
}
songPlayDataList = MockDataRepo.GetMockDataRepo().SongPlayDataList;
} }
private void OnShowDetailsClick(SongPlayData data) private void OnShowDetailsClick(SongPlayData data)
{ {
data.ShowDetails = !data.ShowDetails; data.ShowDetails = !data.ShowDetails;

View File

@ -1,8 +1,7 @@
@page "/users" @page "/users"
@using models = SharedProject.models @using models = SharedProject.models
@using GenFu
@using MudAdmin.Utils
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@inject HttpClient Client
<PageTitle>Users</PageTitle> <PageTitle>Users</PageTitle>
@ -30,11 +29,12 @@
@code { @code {
private List<models.User> users = new(); private List<models.User> users = new();
protected override void OnInitialized() protected override async Task OnInitializedAsync()
{ {
base.OnInitialized(); await base.OnInitializedAsync();
users = MockDataRepo.GetMockDataRepo().Users; users = await Client.GetFromJsonAsync<List<models.User>>("api/Users") ?? new List<models.User>();
} }
private void OnClick(models.User user) private void OnClick(models.User user)

View File

@ -7,7 +7,10 @@ var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app"); builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after"); builder.RootComponents.Add<HeadOutlet>("head::after");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); builder.Services.AddScoped(sp => new HttpClient
{
BaseAddress = new Uri(builder.Configuration.GetValue<string>("BaseUrl"))
});
builder.Services.AddMudServices(); builder.Services.AddMudServices();
await builder.Build().RunAsync(); await builder.Build().RunAsync();

View File

@ -48,7 +48,7 @@ public class MockDataRepo
subDataList.Add(subData); subDataList.Add(subData);
} }
songPlayData.SongPlaySubDataList = subDataList; songPlayData.SongPlaySubDataList = subDataList.ToArray();
} }
} }

View File

@ -0,0 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"BaseUrl": "http://127.0.0.1"
}