diff --git a/Iceshrimp.Frontend/Pages/DrivePage.razor b/Iceshrimp.Frontend/Pages/DrivePage.razor index 2c6da80c..adc8c4ea 100644 --- a/Iceshrimp.Frontend/Pages/DrivePage.razor +++ b/Iceshrimp.Frontend/Pages/DrivePage.razor @@ -1,20 +1,24 @@ @page "/drive" @page "/drive/{Id}" +@attribute [Authorize] @using Iceshrimp.Frontend.Localization @using Microsoft.AspNetCore.Components.Sections @using Microsoft.Extensions.Localization @using Iceshrimp.Assets.PhosphorIcons +@using Iceshrimp.Frontend.Core.Miscellaneous @using Iceshrimp.Frontend.Core.Services @using Iceshrimp.Shared.Schemas.Web +@using Microsoft.AspNetCore.Authorization @inject ApiService Api; @inject IStringLocalizer Loc; +@inject ILogger Logger; @Loc["Drive"] -@if (Folder != null) +@if (_state == State.Loaded && Folder != null) {
    @foreach (var el in Folder.Folders) @@ -29,7 +33,7 @@
  1. @if (el.ContentType.StartsWith("image")) { - + @el.Description } else if (el.ContentType.StartsWith("audio")) { @@ -48,13 +52,56 @@ }
} +@if (_state == State.Loading) +{ +
Loading
+} +@if (_state == State.NotFound) +{ +
This folder does not exist
+} +@if (_state == State.Error) +{ +
An error occured while loading the drive folder. Please inspect logs.
+} @code { [Parameter] public string? Id { get; set; } private DriveFolderResponse? Folder { get; set; } = null; + private State _state { get; set; } + private async Task Load() + { + Logger.LogTrace($"Opening drive folder: {Id ?? "root"}"); + _state = State.Loading; + + try + { + Folder = await Api.Drive.GetFolderAsync(Id); + } + catch (ApiException e) + { + Logger.LogWarning($"Failed to load folder '{Id ?? "root"}' due to API Exception: {e.Message}"); + _state = State.Error; + return; + } + + if (Folder == null) + { + _state = State.NotFound; + return; + } + + _state = State.Loaded; + } + + protected override async Task OnInitializedAsync() + { + await Load(); + } + protected override async Task OnParametersSetAsync() { - Folder = await Api.Drive.GetFolderAsync(Id); + await Load(); } } \ No newline at end of file