mirror of
https://github.com/lantean-code/qbtmud.git
synced 2025-11-03 05:23:17 +00:00
Add context menu to block table
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
@page "/blocks"
|
||||
@layout OtherLayout
|
||||
|
||||
<MudMenu @ref="ContextMenu" Dense="true" PositionAtCursor="true" ListClass="unselectable" PopoverClass="unselectable">
|
||||
<MudMenuItem Icon="@Icons.Material.Filled.ContentCopy" IconColor="Color.Info" Disabled="@(ContextMenuItem is null)" OnClick="CopyContextMenuItem">Copy address</MudMenuItem>
|
||||
<MudDivider />
|
||||
<MudMenuItem Icon="@Icons.Material.Filled.Clear" IconColor="Color.Error" Disabled="@(!HasResults)" OnClick="ClearResults">Clear view</MudMenuItem>
|
||||
</MudMenu>
|
||||
|
||||
<div class="content-panel">
|
||||
<div class="content-panel__toolbar">
|
||||
<MudToolBar Gutters="false" Dense="true">
|
||||
@@ -36,6 +42,8 @@
|
||||
MultiSelection="false"
|
||||
SelectOnRowClick="false"
|
||||
RowClassFunc="RowClass"
|
||||
OnTableDataContextMenu="TableDataContextMenu"
|
||||
OnTableDataLongPress="TableDataLongPress"
|
||||
Class="search-list content-panel__table" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -4,9 +4,12 @@ using Lantean.QBitTorrentClient.Models;
|
||||
using Lantean.QBTMud.Components.UI;
|
||||
using Lantean.QBTMud.Helpers;
|
||||
using Lantean.QBTMud.Models;
|
||||
using Lantean.QBTMud.Services;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Forms;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
using MudBlazor;
|
||||
using System;
|
||||
using System.Net;
|
||||
|
||||
namespace Lantean.QBTMud.Pages
|
||||
@@ -31,6 +34,12 @@ namespace Lantean.QBTMud.Pages
|
||||
[Inject]
|
||||
protected ILocalStorageService LocalStorage { get; set; } = default!;
|
||||
|
||||
[Inject]
|
||||
protected IClipboardService ClipboardService { get; set; } = default!;
|
||||
|
||||
[Inject]
|
||||
protected ISnackbar Snackbar { get; set; } = default!;
|
||||
|
||||
[CascadingParameter(Name = "DrawerOpen")]
|
||||
public bool DrawerOpen { get; set; }
|
||||
|
||||
@@ -42,6 +51,12 @@ namespace Lantean.QBTMud.Pages
|
||||
|
||||
protected DynamicTable<PeerLog>? Table { get; set; }
|
||||
|
||||
protected PeerLog? ContextMenuItem { get; set; }
|
||||
|
||||
protected MudMenu? ContextMenu { get; set; }
|
||||
|
||||
protected bool HasResults => Results is not null && Results.Count > 0;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var selectedTypes = await LocalStorage.GetItemAsync<IEnumerable<string>>(_selectedTypesStorageKey);
|
||||
@@ -100,6 +115,55 @@ namespace Lantean.QBTMud.Pages
|
||||
return $"log-{(log.Blocked ? "critical" : "normal")}";
|
||||
}
|
||||
|
||||
protected Task TableDataContextMenu(TableDataContextMenuEventArgs<PeerLog> eventArgs)
|
||||
{
|
||||
return ShowContextMenu(eventArgs.Item, eventArgs.MouseEventArgs);
|
||||
}
|
||||
|
||||
protected Task TableDataLongPress(TableDataLongPressEventArgs<PeerLog> eventArgs)
|
||||
{
|
||||
return ShowContextMenu(eventArgs.Item, eventArgs.LongPressEventArgs);
|
||||
}
|
||||
|
||||
private async Task ShowContextMenu(PeerLog? item, EventArgs eventArgs)
|
||||
{
|
||||
ContextMenuItem = item;
|
||||
|
||||
if (ContextMenu is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var normalizedEventArgs = eventArgs.NormalizeForContextMenu();
|
||||
|
||||
await ContextMenu.OpenMenuAsync(normalizedEventArgs);
|
||||
}
|
||||
|
||||
protected async Task CopyContextMenuItem()
|
||||
{
|
||||
var address = ContextMenuItem?.IPAddress;
|
||||
if (string.IsNullOrWhiteSpace(address))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await ClipboardService.WriteToClipboard(address);
|
||||
Snackbar?.Add("Address copied to clipboard.", Severity.Info);
|
||||
}
|
||||
|
||||
protected async Task ClearResults()
|
||||
{
|
||||
if (!HasResults)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Results!.Clear();
|
||||
ContextMenuItem = null;
|
||||
Snackbar?.Add("Blocked IP list cleared.", Severity.Info);
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
@@ -165,4 +229,4 @@ namespace Lantean.QBTMud.Pages
|
||||
new ColumnDefinition<PeerLog>("Reason", l => l.Reason),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user