Skip to content

Commit

Permalink
(#433) wasm: add frined service dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintAngeLs committed Oct 14, 2024
1 parent 9ade62d commit 1554329
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<MudDialog MaxWidth="MaxWidth.Small">
<TitleContent>Confirm Friend Removal</TitleContent>

<DialogContent>
<MudText Typo="Typo.subtitle1">@ContentText</MudText>
</DialogContent>

<DialogActions>
<MudSpacer />
<MudButton Color="Color.Error" Variant="Variant.Filled" OnClick="ConfirmRemove">Yes, Remove</MudButton>
<MudButton Color="Color.Secondary" Variant="Variant.Outlined" OnClick="CancelRemove">Cancel</MudButton>
</DialogActions>
</MudDialog>

@code {
[CascadingParameter] MudDialogInstance MudDialog { get; set; }
[Parameter] public string ContentText { get; set; } = "Are you sure you want to remove this friend?";

private async Task ConfirmRemove()
{
MudDialog.Close(DialogResult.Ok(true));
}

private async Task CancelRemove()
{
MudDialog.Cancel();
}
}
29 changes: 23 additions & 6 deletions MiniSpace.Web/src/Astravent.Web.Wasm/Pages/Friends/Friends.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
@using Astravent.Web.Wasm.HttpClients
@using Astravent.Web.Wasm.Areas.Friends
@using Astravent.Web.Wasm.DTO
@using Astravent.Web.Wasm.Pages.Friends.Dialogs
@inject IIdentityService IdentityService
@inject IFriendsService FriendsService
@inject NavigationManager NavigationManager
@inject Radzen.NotificationService NotificationService
@inject Radzen.DialogService DialogService
@inject ISnackbar Snackbar
@inject IDialogService DialogService
@using MudBlazor


Expand Down Expand Up @@ -227,19 +228,35 @@
{
await FriendsService.RemoveFriendAsync(friendId);
friends = friends.Where(f => f.FriendId != friendId).ToList();
NotificationService.Notify(Radzen.NotificationSeverity.Warning, "Friend Removed", "You have removed a friend.", 5000);
Snackbar.Add("Friend removed successfully.", Severity.Warning);
StateHasChanged();
}

private async Task ConfirmRemoveFriend(Guid friendId)
{
var confirm = await DialogService.Confirm("Are you sure you want to remove this friend?", "Confirm Removal", new Radzen.ConfirmOptions() { OkButtonText = "Yes", CancelButtonText = "No" });
if (confirm.HasValue && confirm.Value)
var parameters = new DialogParameters
{
{ "ContentText", "Are you sure you want to remove this friend?" }
};

var options = new DialogOptions
{
CloseButton = true,
MaxWidth = MaxWidth.Small
};

// Show the confirmation dialog
var dialog = DialogService.Show<ConfirmRemoveFriendDialog>("Confirm Friend Removal", parameters, options);
var result = await dialog.Result;

// Proceed with removal if confirmed
if (!result.Cancelled)
{
await RemoveFriend(friendId);
}
}


private void SearchFriends()
{
if (!string.IsNullOrWhiteSpace(searchTerm))
Expand Down Expand Up @@ -275,7 +292,7 @@
}
catch (Exception ex)
{
NotificationService.Notify(Radzen.NotificationSeverity.Error, "Failed to Load Friends", $"An error occurred: {ex.Message}", 5000);
Snackbar.Add($"Failed to load friends: {ex.Message}", Severity.Error);
}
}

Expand Down

0 comments on commit 1554329

Please sign in to comment.