@using Lumina.Presentation.Web.Common.Models.Common @using Lumina.Presentation.Web.Common.Api @using Lumina.Presentation.Web.Common.Enums.FileSystem @using Lumina.Presentation.Web.Common.Enums.Notifications @using Lumina.Presentation.Web.Common.Exceptions @using Lumina.Presentation.Web.Common.Models.FileManagement @using Lumina.Presentation.Web.Common.Models.UI @using Lumina.Presentation.Web.Common.Services @using Microsoft.AspNetCore.Components @using System.Text.Json @using System.Text @implements IDisposable @inject IJSRuntime JSRuntime @inject IApiHttpClient _apiHttpClient @inject INotificationService _notificationService
@foreach (FileSystemTreeNodeModel node in treeViewRootNodes) { }
Name
@foreach (FileSystemItemModel fileSystemItem in fileSystemItems) { string iconSizeClass = "list-icons"; if (viewMode == FileSystemViewMode.Details) iconSizeClass = "details-icons"; else if (viewMode == FileSystemViewMode.Icons) { if (iconSize == FileSystemIconSize.Small) iconSizeClass = "small-icons"; else if (iconSize == FileSystemIconSize.Medium) iconSizeClass = "medium-icons"; else if (iconSize == FileSystemIconSize.Large) iconSizeClass = "large-icons"; else if (iconSize == FileSystemIconSize.ExtraLarge) iconSizeClass = "extra-large-icons"; } string itemType = fileSystemItem is FileModel ? "file" : "directory";
@fileSystemItem.Name
}
Cancel Open
@*
Cancel Confirm *@
@if (showPathSegmentDowpDown && expandedPathSegmentIndex.HasValue && pathSegmentsSubdirectoriesCache.ContainsKey(expandedPathSegmentIndex.Value)) { } @code { [Parameter] public string? Path { get; set; } [Parameter] public bool IncludeFiles { get; set; } public EventCallback OnNodeSelected { get; set; } private List treeViewRootNodes = []; private List fileSystemItems = []; private FileSystemTypeModel fileSystemType = null!; private ComboboxItem? selectedValue; private PathSegmentModel[]? pathSegments; private string pathSeparator = "/"; private string? selectedNodePath; private string? _path; private bool isSelectionMode; private bool showThumbnails = true; // TODO: take from config private bool showHiddenElements; // TODO: take from config private bool showFileSystemTreeView = true; // TODO: take from config private bool showPathSegmentDowpDown; private bool isNavigationPathEditMode; private int? expandedPathSegmentIndex; private FileSystemViewMode viewMode = FileSystemViewMode.List; // TODO: take from config private FileSystemIconSize iconSize; private Dictionary> pathSegmentsSubdirectoriesCache = []; private DotNetObjectReference? reference; private readonly Stack undoStack = []; private readonly Stack redoStack = []; private readonly Dictionary _fileIcons = new() { { "ai", "application-postscript.svg" }, { "apk", "android-package-archive.svg" }, { "appimage", "application-vnd.appimage.svg" }, { "atom", "application-atom+xml.svg" }, { "avif", "application-image.svg" }, { "bmp", "application-image.svg" }, { "bz", "application-x-7z-ace.svg" }, { "chm", "application-vnd.ms-htmlhelp.svg" }, { "dicom", "application-dicom.svg" }, { "dll", "application-octet-stream.svg" }, { "dot", "application-msword-template.svg" }, { "doc", "application-msword-template.svg" }, { "docx", "application-msword-template.svg" }, { "eps", "application-postscript.svg" }, { "epub", "application-epub+zip.svg" }, { "exe", "application-octet-stream.svg" }, { "flac", "application-ogg.svg" }, { "gif", "application-image.svg" }, { "gz", "application-x-7z-ace.svg" }, { "ico", "application-image.svg" }, { "infopath", "application-vnd.ms-infopath.svg" }, { "jpeg", "application-image.svg" }, { "jpg", "application-image.svg" }, { "json", "application-json.svg" }, { "mdb", "application-vnd.ms-access.svg" }, { "mp3", "application-ogg.svg" }, { "ogg", "application-ogg.svg" }, { "otp", "application-vnd.oasis.opendocument.presentation-template.svg" }, { "ods", "application-vnd.oasis.opendocument.spreadsheet-template.svg" }, { "ots", "application-vnd.oasis.opendocument.spreadsheet-template.svg" }, { "ott", "application-vnd.oasis.opendocument.text-template.svg" }, { "otw", "application-vnd.oasis.opendocument.web-template.svg" }, { "p7s", "application-pgp-signature.svg" }, { "pdf", "application-pdf.svg" }, { "pict", "application-image.svg" }, { "pgp", "application-pgp.svg" }, { "png", "application-image.svg" }, { "ppt", "application-vnd.ms-powerpoint.svg" }, { "ps", "application-postscript.svg" }, { "psd", "application-photoshop.svg" }, { "pub", "application-vnd.ms-publisher.svg" }, { "rar", "application-x-7z-ace.svg" }, { "ref", "application-vnd.flatpak.ref.svg" }, { "sendfile", "application-vnd.kde.bluedevil-sendfile.svg" }, { "snap", "application-vnd.snap.svg" }, { "stream", "application-octet-stream.svg" }, { "svg", "application-image.svg" }, { "sql", "application-sql.svg" }, { "sqlite", "application-sql.svg" }, { "tar", "application-x-7z-ace.svg" }, { "tga", "application-image.svg" }, { "tiff", "application-image.svg" }, { "txt", "application-pgp-signature.svg" }, { "wav", "application-ogg.svg" }, { "webp", "application-image.svg" }, { "xdgapp", "application-vnd.xdgapp.svg" }, { "xls", "application-vnd.ms-excel.svg" }, { "xlsx", "application-vnd.ms-excel.svg" }, { "xml", "application-atom+xml.svg" }, { "zip", "application-x-7z-ace.svg" } }; /// /// Initializes the component. /// protected override async Task OnInitializedAsync() { await GetFileSystemPropertiesAsync().ConfigureAwait(false); if (Path is not null) { if (!Path.EndsWith(pathSeparator)) Path += pathSeparator; await NavigateToPathAsync(Path, isForwardNavigation: false, isBackwardNavigation: false).ConfigureAwait(false); } await ChangeViewModeAsync(viewMode).ConfigureAwait(false); } /// /// Handles the event risen after the component was rendered. /// /// Indicates whether this is the first render or not. protected override async Task OnAfterRenderAsync(bool firstRender) { // on first render, subscribe this component to the javascript function that handles window clicks if (firstRender) { reference = DotNetObjectReference.Create(this); // assign the elements of this component instance to javascript variables, for memoization await JSRuntime.InvokeVoidAsync("initializeFileSystemBrowser", reference).ConfigureAwait(false); // make the navigator path segments horizontally scrollable await JSRuntime.InvokeVoidAsync("addHorizontalScrolling", "navigator-address-bar").ConfigureAwait(false); // subscribe to window clicks await JSRuntime.InvokeVoidAsync("windowClickHandler", reference).ConfigureAwait(false); } await base.OnAfterRenderAsync(firstRender); } /// /// Handles the window click event. /// /// The event arguments. [JSInvokable] public async Task OnWindowClickAsync(dynamic e) { // parse the event args and get the initiator of the event var jsonElement = (JsonElement)e; string? sender = jsonElement.GetProperty("sender").GetString(); // ignore the event if it was initiated by a path segment (don't collapse an element that was just expanded) if (showPathSegmentDowpDown && sender is not null && !sender.Contains("segment-toggle-")) { // otherwise, collapse all path segments showPathSegmentDowpDown = false; expandedPathSegmentIndex = null; } // exit navigator path edit mode when clicking anywhere outside of it, or on elements that should not exit it if (sender is null || (sender is not null && !sender.Contains("navigator-path-segments") && !sender.Contains("navigator-edit-icon") && !sender.Contains("navigator-address-bar-input"))) isNavigationPathEditMode = false; await InvokeAsync(StateHasChanged).ConfigureAwait(false); } /// /// Expands or collapses a node in the tree view. /// /// The node to expand or collapse. private async Task ToggleTreeViewNode(FileSystemTreeNodeModel node) { if (!node.IsExpanded && !node.ChildrenLoaded) { node.Children = new List(); node.IsExpanded = true; await InvokeAsync(StateHasChanged).ConfigureAwait(false); if (await CheckPathAsync(node.Path).ConfigureAwait(false)) { try { await foreach (FileSystemTreeNodeModel? childNode in _apiHttpClient.GetAsyncEnumerable($"directories/get-tree-directories?path={Uri.EscapeDataString(node.Path)}&includeHiddenElements={showHiddenElements}").ConfigureAwait(false)) { if (childNode is not null) { node.Children.Add(childNode); await InvokeAsync(StateHasChanged).ConfigureAwait(false); } } if (IncludeFiles) { await foreach (FileSystemTreeNodeModel? childNode in _apiHttpClient.GetAsyncEnumerable($"files/get-tree-files?path={Uri.EscapeDataString(node.Path)}&includeHiddenElements={showHiddenElements}").ConfigureAwait(false)) { if (childNode is not null) { node.Children.Add(childNode); await InvokeAsync(StateHasChanged).ConfigureAwait(false); } } } } catch (ApiException ex) { HandleApiException(ex); } finally { node.ChildrenLoaded = true; } } } else node.IsExpanded = !node.IsExpanded; await InvokeAsync(StateHasChanged).ConfigureAwait(false); } /// /// Handles the change event. /// /// The event arguments. private async Task ToggleNavigatorPathSegment(ChangeEventArgs e, int toggledIndex) { // uncheck all other path segment checkboxes await JSRuntime.InvokeVoidAsync("uncheckAllExcept", $"segment-toggle-{toggledIndex}").ConfigureAwait(false); // check if the checkbox is checked bool isChecked = (bool)e.Value!; // if it's checked, get the subdirectories for the toggled path segment if (isChecked && pathSegments?.Length > 0) { // initialize the path with the first segment string concatenatedPath = pathSegments[0].Path; // concatenate only up to the toggled index for (int i = 1; i <= toggledIndex; i++) concatenatedPath = $"{(concatenatedPath != pathSeparator ? concatenatedPath : string.Empty)}{pathSeparator}{pathSegments[i].Path}"; string parentConcatenatedPath = concatenatedPath; // fetch directories for the expanded path segment try { if (concatenatedPath != pathSeparator) // on UNIX, dont get the parent, if we are at root path { PathSegmentModel[] parentLocationResponse = await _apiHttpClient.GetAsync($"path/get-path-parent?path={Uri.EscapeDataString(concatenatedPath)}").ConfigureAwait(false); parentConcatenatedPath = parentLocationResponse[0].Path; for (int i = 1; i < parentLocationResponse.Length; i++) parentConcatenatedPath = $"{(parentConcatenatedPath != pathSeparator ? parentConcatenatedPath : string.Empty)}{pathSeparator}{pathSegments[i].Path}"; } } catch (ApiException ex) { HandleApiException(ex); } if (!concatenatedPath.EndsWith(pathSeparator)) concatenatedPath += pathSeparator; // add current and parent directories too List directories = [new() { Path = concatenatedPath, Name = ".", }, new() { Path = parentConcatenatedPath, Name = ".." }]; // add the rest of the subdirectories of the expanded path node await foreach (FileSystemTreeNodeModel? directory in _apiHttpClient.GetAsyncEnumerable($"directories/get-tree-directories?path={Uri.EscapeDataString(concatenatedPath)}&includeHiddenElements={showHiddenElements}").ConfigureAwait(false)) if (directory is not null) directories.Add(directory); // store the directories for this segment pathSegmentsSubdirectoriesCache[toggledIndex] = directories; expandedPathSegmentIndex = toggledIndex; showPathSegmentDowpDown = true; await InvokeAsync(StateHasChanged).ConfigureAwait(false); // invoke the javascript function that positions the dropdown underneath the toggled path segment await JSRuntime.InvokeVoidAsync("updateDropdownPosition", $"path-segment-{toggledIndex}").ConfigureAwait(false); } else { expandedPathSegmentIndex = null; showPathSegmentDowpDown = false; await InvokeAsync(StateHasChanged).ConfigureAwait(false); } } /// /// Handles the selection of a node in the tree view. /// /// The path of the selected node. /// Indicates whether the navigation is towards a location in the redo stack or not. /// Indicates whether the navigation is towards a location in the undo stack or not. private async Task NavigateToPathAsync(string path, bool isForwardNavigation, bool isBackwardNavigation) { if (await CheckPathAsync(path).ConfigureAwait(false)) { // check if backward navigation is possible if (isBackwardNavigation) { if (undoStack.Count > 0) { // get the first path in the backward navigation list string backwardPath = undoStack.Pop(); // put the current path in the forward navigationlist, before navigating to the backward path if (Path is not null) { if (!Path.EndsWith(pathSeparator)) Path += pathSeparator; redoStack.Push(Path); } path = backwardPath; } else return; } else if (isForwardNavigation) // check if forward navigation is possible { if (redoStack.Count > 0) { // get the first path in the forward navigation list string forwardPath = redoStack.Pop(); // put the current path in the backward navigation list, before navigating to the forward path if (Path is not null) { if (!Path.EndsWith(pathSeparator)) Path += pathSeparator; if (undoStack.Count == 0 || (undoStack.Count > 0 && undoStack.Peek() != Path)) undoStack.Push(Path); } path = forwardPath; } else return; } else // navigation to a brand new location (up, directory browse, manual path edit, etc) { redoStack.Clear(); if (Path is not null && Path != path) // when navigating up, Path will be set after navigation { if (undoStack.Count == 0 || (undoStack.Count > 0 && undoStack.Peek() != Path)) undoStack.Push(Path); } else if (_path is not null && _path != path) // when editing the address, Path already comes set, check against control value { if (undoStack.Count == 0 || (undoStack.Count > 0 && undoStack.Peek() != _path)) undoStack.Push(_path); } } _path = path; // we are about to navigate to the new path, store its value in the control variable try { await GetNavigatorPathAsync(path).ConfigureAwait(false); if (showFileSystemTreeView) await GetFileSystemTreeAsync(path).ConfigureAwait(false); await GetFileSystemItemsAsync(path).ConfigureAwait(false); } catch (ApiException ex) { HandleApiException(ex); } } selectedNodePath = _path; Path = _path; // also update the navigation input address if (Path is not null && !Path.EndsWith(pathSeparator)) Path += pathSeparator; await OnNodeSelected.InvokeAsync(path).ConfigureAwait(false); await InvokeAsync(StateHasChanged).ConfigureAwait(false); } /// /// Provides backwards navigation. /// private async Task NavigateBackAsync() { if (Path is not null) await NavigateToPathAsync(Path, isForwardNavigation: false, isBackwardNavigation: true).ConfigureAwait(false); } /// /// Provides forwards navigation. /// private async Task NavigateForwardAsync() { if (Path is not null) await NavigateToPathAsync(Path, isForwardNavigation: true, isBackwardNavigation: false).ConfigureAwait(false); } /// /// Provides upwards navigation. /// private async Task NavigateUpAsync() { try { if (Path is not null) { // ask the API for the parent path PathSegmentModel[] parentLocationResponse = await _apiHttpClient.GetAsync($"path/get-path-parent?path={Uri.EscapeDataString(Path)}").ConfigureAwait(false); // if the answer was valid, and we can navigate up, reconstruct the provided path from its segments, and navigate to it if (parentLocationResponse is not null) { string parentConcatenatedPath = parentLocationResponse[0].Path; for (int i = 1; i < parentLocationResponse.Length; i++) parentConcatenatedPath = $"{(parentConcatenatedPath != pathSeparator ? parentConcatenatedPath : string.Empty)}{pathSeparator}{parentLocationResponse[i].Path}"; if (!parentConcatenatedPath.EndsWith(pathSeparator)) parentConcatenatedPath += pathSeparator; await NavigateToPathAsync(parentConcatenatedPath, isForwardNavigation: false, isBackwardNavigation: false).ConfigureAwait(false); } } } catch (ApiException ex) { HandleApiException(ex); } } /// /// Handles the file system directories double click event. /// /// The path of the double clicked directory. [JSInvokable()] public async Task OnDirectoryDoubleClickAsync(string path) { await NavigateToPathAsync(path, isForwardNavigation: false, isBackwardNavigation: false).ConfigureAwait(false); } /// /// Gets the properties of the file system. /// private async Task GetFileSystemPropertiesAsync() { fileSystemType = await _apiHttpClient.GetAsync("file-system/get-type").ConfigureAwait(false); // ask the API server for the system path separator PathSeparatorModel apiPathSeparator = await _apiHttpClient.GetAsync("path/get-path-separator").ConfigureAwait(false); pathSeparator = apiPathSeparator.Separator; // TODO: handle error } /// /// Checks if the specified path is a valid file system path. /// /// The path to check. /// if the specified path is valid, otherwise. private async Task CheckPathAsync(string path) { try { var isPathValidResponse = await _apiHttpClient.GetAsync($"path/validate?path={Uri.EscapeDataString(path)}").ConfigureAwait(false); if (!isPathValidResponse.IsValid) { _notificationService.Show("Specified path is not valid!", NotificationType.Error); // TODO: should ask error message from server when translation is implemented Path = _path; if (Path is not null && !Path.EndsWith(pathSeparator)) Path += pathSeparator; } PathExistsModel pathExistsResponse = await _apiHttpClient.GetAsync($"path/check-path-exists?path={Uri.EscapeDataString(path)}").ConfigureAwait(false); if (!pathExistsResponse.Exists) { _notificationService.Show("Specified path does not exist!", NotificationType.Error); // TODO: should ask error message from server when translation is implemented return false; } return isPathValidResponse.IsValid; } catch (ApiException ex) { HandleApiException(ex); return false; } } /// /// Gets the navigator path segments. /// /// The path for which to get the navigator path segments. private async Task GetNavigatorPathAsync(string path) { pathSegments = await _apiHttpClient.GetAsync($"path/split?path={Uri.EscapeDataString(path!)}").ConfigureAwait(false); await InvokeAsync(StateHasChanged).ConfigureAwait(false); } /// /// Gets the file system items that are displayed in the file system tree view pane. /// /// The path for which to get the file system items. private async Task GetFileSystemTreeAsync(string path) { treeViewRootNodes = []; // on Windows, ask the list of drives if (fileSystemType?.PlatformType == PlatformType.Windows) { List drives = await _apiHttpClient.GetAsync>("drives/get-drives").ConfigureAwait(false); treeViewRootNodes.AddRange(drives); } else { // on UNIX, just add the root "/" treeViewRootNodes.Add(new FileSystemTreeNodeModel() { Path = pathSeparator!, IsExpanded = true, ItemType = FileSystemItemType.Root, Name = pathSeparator! }); } // if there was an initial path saved from a previous session, load the full tree up to that initial path List initialTree = await _apiHttpClient.GetAsync>($"directories/get-directory-tree?path={Uri.EscapeDataString(path!)}&includeFiles={IncludeFiles}&includeHiddenElements={showHiddenElements}").ConfigureAwait(false); if (initialTree is not null && initialTree.Count > 0) { // take the root of the retrieved tree, and try to match it against a drive in the retrieved list of drives, on Windows; on Unix, add it as the unique root path PathSegmentModel pathRoot = await _apiHttpClient.GetAsync($"path/get-path-root?path={Uri.EscapeDataString(path!)}").ConfigureAwait(false); if (fileSystemType?.PlatformType == PlatformType.Windows) { FileSystemTreeNodeModel? driveNode = treeViewRootNodes.FirstOrDefault(drive => drive.Path.Equals(pathRoot.Path, StringComparison.OrdinalIgnoreCase)); // if a drive was matched, make the retrieved tree a child of it if (driveNode is not null) { int index = treeViewRootNodes.IndexOf(driveNode); treeViewRootNodes[index] = initialTree[0]; } } else treeViewRootNodes[0] = initialTree[0]; } } /// /// Retrieves the files and directories for the specified path. /// /// The path for which to get the files and directories. private async Task GetFileSystemItemsAsync(string path) { fileSystemItems.Clear(); try { await foreach (DirectoryModel? directory in _apiHttpClient.GetAsyncEnumerable($"directories/get-directories?path={Uri.EscapeDataString(path)}&includeHiddenElements={showHiddenElements}").ConfigureAwait(false)) { if (directory is not null) { fileSystemItems.Add(directory); await InvokeAsync(StateHasChanged).ConfigureAwait(false); } } if (IncludeFiles) { await foreach (FileModel? file in _apiHttpClient.GetAsyncEnumerable($"files/get-files?path={Uri.EscapeDataString(path)}&includeHiddenElements={showHiddenElements}").ConfigureAwait(false)) { if (file is not null) { fileSystemItems.Add(file); await InvokeAsync(StateHasChanged).ConfigureAwait(false); } } } } catch (ApiException ex) { HandleApiException(ex); } } /// /// Changes the current file system explorer view. /// /// The new explorer view to change to. private async Task ChangeViewModeAsync(FileSystemViewMode newViewMode) { viewMode = newViewMode; if (viewMode == FileSystemViewMode.List) await JSRuntime.InvokeVoidAsync("addHorizontalScrolling", "file-system-browser-file-system-explorer").ConfigureAwait(false); else await JSRuntime.InvokeVoidAsync("removeHorizontalScrolling", "file-system-browser-file-system-explorer").ConfigureAwait(false); await JSRuntime.InvokeVoidAsync("switchViewMode").ConfigureAwait(false); await InvokeAsync(StateHasChanged).ConfigureAwait(false); } /// /// Changes the icon size for the file system items. /// /// Thew new icon size to change to. private async Task ChangeIconSizeAsync(FileSystemIconSize newIconSize) { viewMode = FileSystemViewMode.Icons; iconSize = newIconSize; await InvokeAsync(StateHasChanged).ConfigureAwait(false); } /// /// Returns the path to an SVG icon based on the file extension. /// /// The full name of the file including its extension. /// The type of the file system item for which to get the item path. /// The path to the appropriate SVG icon or a default one if not found. private string GetFileSystemItemIconPath(string? filename, string type) { if (filename is not null) { // extract file extension from filename manually var fileExtension = filename.Contains(".") ? filename.Split('.').Last().ToLower() : string.Empty; // return the appropriate SVG image path or a default one if not found return _fileIcons.ContainsKey(fileExtension) ? _fileIcons[fileExtension] : type + ".svg"; } else return type + ".svg"; } /// /// Enters the edit mode where the navigator path can be edited freely. /// private async Task EnterNavigationPathEditModeAsync() { isNavigationPathEditMode = true; await InvokeAsync(StateHasChanged).ConfigureAwait(false); await InvokeAsync(async () => { await Task.Delay(50); // a small delay is necessary to ensure the DOM has updated await SetFocusOnNavigatorAddressInputAsync().ConfigureAwait(false); }); } /// /// Exits the edit mode where the navigator path can be edited freely. /// private async Task ExitNavigationPathEditModeAsync() { isNavigationPathEditMode = false; await InvokeAsync(StateHasChanged).ConfigureAwait(false); if (Path is not null) { if (!Path.EndsWith(pathSeparator)) Path += pathSeparator; await NavigateToPathAsync(Path, isForwardNavigation: false, isBackwardNavigation: false).ConfigureAwait(false); } } /// /// Handles the selection of a node in the file system tree view. /// /// The path of the newly selected node. private async Task HandleFileSystemTreeViewNodeSelectedAsync(string path) { await InvokeAsync(StateHasChanged).ConfigureAwait(false); if (selectedNodePath is not null) { Path = path; if (!Path.EndsWith(pathSeparator)) Path += pathSeparator; await NavigateToPathAsync(Path, isForwardNavigation: false, isBackwardNavigation: false).ConfigureAwait(false); } } /// /// Handles the Escape key being pressed in the navigator address input. /// private async Task HandleNavigatorInputEscapePressedAsync() { Path = _path; isNavigationPathEditMode = false; await InvokeAsync(StateHasChanged).ConfigureAwait(false); } /// /// Sets the focus to the navigator address input. /// public async Task SetFocusOnNavigatorAddressInputAsync() { await JSRuntime.InvokeVoidAsync("focusNavigatorInputElement").ConfigureAwait(false); } /// /// Enables or disables selection mode. /// private async Task ToggleSelectionModeAsync() { isSelectionMode = !isSelectionMode; await JSRuntime.InvokeVoidAsync("toggleSelectionMode").ConfigureAwait(false); } /// /// Enables or disables the display of the file system tree view. /// private async Task ToggleFileSystemTreeViewAsync() { showFileSystemTreeView = !showFileSystemTreeView; // if file system treeview needs to be displayed, get its file system tree structure from the API if (showFileSystemTreeView && Path is not null) { if (!Path.EndsWith(pathSeparator)) Path += pathSeparator; await NavigateToPathAsync(Path, isForwardNavigation: false, isBackwardNavigation: false).ConfigureAwait(false); } } /// /// Enables or disables the display of hidden file system files and directories. /// private async Task ToggleHiddenElementsModeAsync() { showHiddenElements = !showHiddenElements; if (Path is not null) { if (!Path.EndsWith(pathSeparator)) Path += pathSeparator; await NavigateToPathAsync(Path, isForwardNavigation: false, isBackwardNavigation: false).ConfigureAwait(false); } } /// /// Enables or disables selection mode. /// private async Task ToggleThumbnailsAsync() { showThumbnails = !showThumbnails; await Task.CompletedTask; //await JSRuntime.InvokeVoidAsync("toggleSelectionMode").ConfigureAwait(false); } /// /// Handles API exceptions, presenting standard problem details in a user friendly way. /// /// The exception to handle private void HandleApiException(ApiException ex) { StringBuilder errorMessage = new StringBuilder(); if (ex.ProblemDetails is not null) { errorMessage.AppendLine($"HTTP {ex.ProblemDetails.Status} {ex.HttpStatusCode}
"); if (!string.IsNullOrEmpty(ex.ProblemDetails.Detail)) errorMessage.AppendLine($"{ex.ProblemDetails.Detail}"); if (ex.ProblemDetails.Extensions is not null && ex.ProblemDetails.Extensions.TryGetValue("errors", out var errorsObj)) { if (errorsObj is JsonElement jsonElement && jsonElement.ValueKind == JsonValueKind.Object) { errorMessage.AppendLine("Validation Errors:"); foreach (var error in jsonElement.EnumerateObject()) { string fieldName = error.Name; if (error.Value.ValueKind == JsonValueKind.Array) foreach (var errorValue in error.Value.EnumerateArray()) errorMessage.AppendLine($"- {fieldName}: {errorValue}
"); } } } if (ex.ProblemDetails.Extensions is not null) foreach (var extension in ex.ProblemDetails.Extensions) if (extension.Key != "errors") errorMessage.AppendLine($"{extension.Key}: {extension.Value}
"); } else { errorMessage.AppendLine($"HTTP {ex.HttpStatusCode}
"); errorMessage.AppendLine($"{ex.Message}
"); } _notificationService.Show(errorMessage.ToString(), NotificationType.Error); } /// /// Disposes this component. /// public void Dispose() { reference?.Dispose(); } }