@inject ILibraryDiscoveryService LibraryDiscovery @inject TranslationSource T @* Library name field with a picker: type a title, or click Browse to load and choose from the libraries on the selected site. *@
@if (!string.IsNullOrEmpty(_error)) {
@_error
} @if (_open) {
@foreach (var lib in _libraries) { } @if (_libraries.Count == 0) {
@T["librarypicker.noLibraries"]
}
}
@code { [Parameter, EditorRequired] public TenantProfile Profile { get; set; } = default!; [Parameter] public string? SiteUrl { get; set; } [Parameter] public string Library { get; set; } = string.Empty; [Parameter] public EventCallback LibraryChanged { get; set; } [Parameter] public string Label { get; set; } = "Library"; [Parameter] public string Placeholder { get; set; } = "Shared Documents"; [Parameter] public bool Disabled { get; set; } private List _libraries = new(); private bool _loading, _open; private string _error = string.Empty; private string? _loadedForSite; private async Task OnTextInput(ChangeEventArgs e) { Library = e.Value?.ToString() ?? string.Empty; await LibraryChanged.InvokeAsync(Library); } private async Task Browse() { _error = string.Empty; if (string.IsNullOrWhiteSpace(SiteUrl)) { _error = T["librarypicker.selectSiteFirst"]; return; } // Toggle closed if already showing the list for this site. if (_open && _loadedForSite == SiteUrl) { _open = false; return; } // Reload when the site changed since the last load. if (_libraries.Count == 0 || _loadedForSite != SiteUrl) { _loading = true; try { _libraries = (await LibraryDiscovery.ListLibrariesAsync(Profile, SiteUrl!)).ToList(); _loadedForSite = SiteUrl; } catch (Exception ex) { _error = ex.Message; return; } finally { _loading = false; } } _open = true; } private async Task Pick(string lib) { Library = lib; _open = false; await LibraryChanged.InvokeAsync(Library); } }