Skip to content

Commit

Permalink
Code(WEB::Drawer): Implement chat deletion from history
Browse files Browse the repository at this point in the history
  • Loading branch information
ktutak1337 committed May 4, 2024
1 parent a8d5bf3 commit 15900c2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
14 changes: 10 additions & 4 deletions src/Client/StellarChat.Client.Web/Components/ChatHistoryItem.razor
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
@inject NavigationManager NavigationManager
@inject IChatService _chatService
@inject IDialogService _dialogService

<div Class="d-flex flex-row flex-grow-1 gap-1 pa-2" Elevation="0">
<MudAvatar Class="my-auto">
<MudImage Size="Size.Medium" Src="https://avatars.githubusercontent.com/u/49451143?v=4"></MudImage>
</MudAvatar>
<MudListItem OnClick="@NavigateToChat">
@ChatSessionIteam?.Title
@ChatSessionItem?.Title
</MudListItem>
<MudMenu Class="" Icon="@Icons.Material.Filled.MoreVert">
<MudMenuItem>Rename</MudMenuItem>
<MudMenuItem>Delete</MudMenuItem>
<MudMenuItem OnClick="DeleteChat">Delete</MudMenuItem>
</MudMenu>
</div>
<MudDivider />

@code
{
[Parameter] public ChatSessionResponse? ChatSessionIteam { get; set; }
[Parameter] public ChatSessionResponse? ChatSessionItem { get; set; }
[Parameter] public EventCallback<ChatSessionResponse> OnDeleteChat { get; set; }

private void NavigateToChat()
{

}

private async Task DeleteChat()
=> await OnDeleteChat.InvokeAsync(ChatSessionItem);
}
9 changes: 7 additions & 2 deletions src/Client/StellarChat.Client.Web/Components/Drawer.razor
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<MudList Clickable="true">
@foreach (var chatSession in ChatSessions)
{
<ChatHistoryItem ChatSessionItem="@chatSession" />
<ChatHistoryItem ChatSessionItem="@chatSession" OnDeleteChat="DeleteChatSession" />
}
</MudList>
</div>
Expand All @@ -45,7 +45,6 @@
</MudContainer>
</MudDrawer>


@code
{
[Parameter]
Expand All @@ -58,6 +57,12 @@
protected override async Task OnInitializedAsync()
=> await LoadChatSessions();

private async Task DeleteChatSession(ChatSessionResponse chatSession)
{
await _chatService.DeleteChatSession(chatSession.Id);
ChatSessions.Remove(chatSession);
}

private async Task LoadChatSessions()
{
var response = await _chatService.BrowseChatSessions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,11 @@ public async ValueTask<Paged<ChatSessionResponse>> BrowseChatSessions(int page =

return result!;
}

public async ValueTask DeleteChatSession(Guid id)
{
var httpClient = _httpClientFactory.CreateClient("WebAPI");

await httpClient.DeleteAsync($"/chat-history/sessions/{id}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ namespace StellarChat.Client.Web.Services.Chat;
public interface IChatService
{
ValueTask<Paged<ChatSessionResponse>> BrowseChatSessions(int page = 0, int pageSize = 0);
ValueTask DeleteChatSession(Guid id);
}

0 comments on commit 15900c2

Please sign in to comment.