57 lines
1.8 KiB
Plaintext
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();
|
|
} |