@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 @using Iceshrimp.Frontend.Components @inject ApiService Api; @inject IJSRuntime Js; @inject IStringLocalizer Loc; @inject ILogger Logger; @inject NavigationManager Nav; @if (_state == State.Loaded && Folder is { Id: not null, Name: not null }) { @Folder.Name } else { @Loc["Drive"] } @if (_state == State.Loaded && Folder is not null) { }
Upload!
@if (_state == State.Loaded && Folder != null) {
    @foreach (var el in Folder.Folders) {
  1. } @foreach (var el in Folder.Files) {
  2. }
} @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 InputFile UploadInput { get; set; } = null!; private IJSObjectReference _module = null!; 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(); _module = await Js.InvokeAsync("import", "./Pages/DrivePage.razor.js"); } protected override async Task OnParametersSetAsync() { await Load(); } private void NavigateToParent() { Nav.NavigateTo(Folder?.ParentId != null ? $"/drive/{Folder.ParentId}" : "/drive"); } // The Component is hidden, and triggered by a sepperate button. // That way we get it's functionality, without the styling limitations of the InputFile component private async Task OpenUpload() { await _module.InvokeVoidAsync("openUpload", UploadInput.Element); } private async Task Upload(InputFileChangeEventArgs e) { var res = await Api.Drive.UploadFileAsync(e.File); Folder!.Files.Add(res); StateHasChanged(); } }