Disabled button and added tooltip for already joined/owned syncshells in finder

This commit is contained in:
CakeAndBanana
2025-09-26 18:39:38 +02:00
parent fd9bd3975b
commit c6f8d6843e

View File

@@ -26,6 +26,7 @@ public class SyncshellFinderUI : WindowMediatorSubscriberBase
private readonly PairManager _pairManager;
private readonly List<GroupJoinDto> _nearbySyncshells = [];
private List<GroupFullInfoDto> _currentSyncshells = [];
private int _selectedNearbyIndex = -1;
private GroupJoinDto? _joinDto;
@@ -106,10 +107,8 @@ public class SyncshellFinderUI : WindowMediatorSubscriberBase
ImGui.TableSetupColumn("Join", ImGuiTableColumnFlags.WidthFixed, 80f * ImGuiHelpers.GlobalScale);
ImGui.TableHeadersRow();
for (int i = 0; i < _nearbySyncshells.Count; i++)
foreach (var shell in _nearbySyncshells)
{
var shell = _nearbySyncshells[i];
ImGui.TableNextRow();
ImGui.TableNextColumn();
ImGui.TextUnformatted(shell.Group.Alias ?? "(No Alias)");
@@ -122,41 +121,53 @@ public class SyncshellFinderUI : WindowMediatorSubscriberBase
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, UIColors.Get("LightlessGreen").WithAlpha(0.85f));
ImGui.PushStyleColor(ImGuiCol.ButtonActive, UIColors.Get("LightlessGreen").WithAlpha(0.75f));
if (ImGui.Button(label))
if (!_currentSyncshells.Exists(g => string.Equals(g.GID, shell.GID, StringComparison.Ordinal)))
{
_logger.LogInformation($"Join requested for Syncshell {shell.Group.GID} ({shell.Group.Alias})");
_ = Task.Run(async () =>
if (ImGui.Button(label))
{
try
{
var info = await _apiController.GroupJoinHashed(new GroupJoinHashedDto(
shell.Group,
shell.Password,
shell.GroupUserPreferredPermissions
)).ConfigureAwait(false);
_logger.LogInformation($"Join requested for Syncshell {shell.Group.GID} ({shell.Group.Alias})");
if (info != null && info.Success)
{
_joinDto = new GroupJoinDto(shell.Group, shell.Password, shell.GroupUserPreferredPermissions);
_joinInfo = info;
_ownPermissions = _apiController.DefaultPermissions.DeepClone()!;
_logger.LogInformation($"Fetched join info for {shell.Group.GID}");
}
else
{
_logger.LogWarning($"Failed to join {shell.Group.GID}: info was null or unsuccessful");
}
}
catch (Exception ex)
_ = Task.Run(async () =>
{
_logger.LogError(ex, $"Join failed for {shell.Group.GID}");
}
});
try
{
var info = await _apiController.GroupJoinHashed(new GroupJoinHashedDto(
shell.Group,
shell.Password,
shell.GroupUserPreferredPermissions
)).ConfigureAwait(false);
if (info != null && info.Success)
{
_joinDto = new GroupJoinDto(shell.Group, shell.Password, shell.GroupUserPreferredPermissions);
_joinInfo = info;
_ownPermissions = _apiController.DefaultPermissions.DeepClone()!;
_logger.LogInformation($"Fetched join info for {shell.Group.GID}");
}
else
{
_logger.LogWarning($"Failed to join {shell.Group.GID}: info was null or unsuccessful");
}
}
catch (Exception ex)
{
_logger.LogError(ex, $"Join failed for {shell.Group.GID}");
}
});
}
}
else
{
using (ImRaii.Disabled())
{
ImGui.Button(label);
}
UiSharedService.AttachToolTip("Already a member or owner of this Syncshell.");
}
ImGui.PopStyleColor(3);
}
@@ -226,7 +237,7 @@ public class SyncshellFinderUI : WindowMediatorSubscriberBase
private async Task RefreshSyncshellsAsync()
{
var syncshellBroadcasts = _broadcastScannerService.GetActiveSyncshellBroadcasts();
var currentSyncshells = _pairManager.GroupPairs.Select(g => g.Key).ToList();
_currentSyncshells = _pairManager.GroupPairs.Select(g => g.Key).ToList();
if (syncshellBroadcasts.Count == 0)
{
@@ -238,16 +249,7 @@ public class SyncshellFinderUI : WindowMediatorSubscriberBase
try
{
var groups = await _apiController.GetBroadcastedGroups(syncshellBroadcasts).ConfigureAwait(false);
if (groups != null && currentSyncshells != null)
{
foreach (var group in groups)
{
if (!currentSyncshells.Exists(g => string.Equals(g.GID, group.GID, StringComparison.Ordinal)))
{
updatedList = groups?.ToList();
}
}
}
updatedList = groups?.ToList();
}
catch (Exception ex)
{