1
0
mirror of synced 2024-09-24 02:58:24 +02: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 MudAdmin.Utils
@using SharedProject.enums
@inject HttpClient Client
<PageTitle>User</PageTitle>
@ -143,9 +144,9 @@ else
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 =
{
@ -159,18 +160,15 @@ else
new(990000, "S++"),
};
protected override void OnInitialized()
protected override async Task OnInitializedAsync()
{
var details = MockDataRepo.GetMockDataRepo().UserDetails;
userDetail = details.First(detail => detail.CardId == CardId);
if (userDetail != null)
{
feverTranceShow = userDetail.PlayOption.FeverTrance;
fastSlowIndicator = userDetail.PlayOption.FastSlowIndicator;
}
songPlayDataList = MockDataRepo.GetMockDataRepo().SongPlayDataList;
await base.OnInitializedAsync();
userDetail = await Client.GetFromJsonAsync<UserDetail>($"api/UserDetail/{CardId}") ?? new();
songPlayDataList = userDetail.SongPlayDataList ?? new List<SongPlayData>();
feverTranceShow = userDetail.PlayOption.FeverTrance;
fastSlowIndicator = userDetail.PlayOption.FastSlowIndicator;
}
private void OnShowDetailsClick(SongPlayData data)
{
data.ShowDetails = !data.ShowDetails;

View File

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

View File

@ -48,7 +48,7 @@ public class MockDataRepo
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"
}