1
0
mirror of synced 2025-02-08 07:18:15 +01:00
GC-local-server-rewrite/MudAdmin/Pages/FavoriteDialog.razor
2022-06-21 01:49:47 +08:00

57 lines
1.8 KiB
Plaintext

@using SharedProject.models
@inject HttpClient Client
@inject ILogger<FavoriteDialog> Logger
<MudDialog>
<TitleContent>
@if (!Data.IsFavorite)
{
<MudText Typo="Typo.h6">
<MudIcon Icon="@Icons.Material.Filled.BookmarkAdd" Color="Color.Secondary"/>
Add to favorite?
</MudText>
}
else
{
<MudText Typo="Typo.h6">
<MudIcon Icon="@Icons.Material.Filled.BookmarkRemove" Color="Color.Secondary"/>
Remove from favorite?
</MudText>
}
</TitleContent>
<DialogContent>
<MudTextField Value="@Data.Title" Label="Song Title" ReadOnly="true"/>
<MudTextField Value="@Data.Artist" Label="Artist Name" ReadOnly="true"/>
</DialogContent>
<DialogActions>
<MudButton OnClick="Cancel">Cancel</MudButton>
<MudButton Color="Color.Primary" OnClick="Submit">Confirm</MudButton>
</DialogActions>
</MudDialog>
@code {
[CascadingParameter]
MudDialogInstance MudDialog { get; set; } = null!;
[Parameter]
public SongPlayData Data { get; set; } = null!;
[Parameter]
public long CardId { get; set; }
async void Submit()
{
var postData = new MusicFavoriteData
{
CardId = CardId,
IsFavorite = !Data.IsFavorite,
MusicId = Data.MusicId
};
Logger.LogInformation("Data is {cardId}, {musicId}", CardId, Data.MusicId);
var response = await Client.PostAsJsonAsync("api/UserDetail/SetMusicFavorite", postData);
var result = await response.Content.ReadFromJsonAsync<bool>();
Logger.LogInformation("Favorite result is {result}", result);
MudDialog.Close(DialogResult.Ok(result));
}
void Cancel() => MudDialog.Cancel();
}