@using AliasVault.RazorComponents.Tables @inject NavigationManager NavigationManager @foreach (var credential in SortedCredentials) {
@credential.Service
@credential.Username @credential.Email @credential.CreatedAt.ToString("yyyy-MM-dd")
}
@code { /// /// Gets or sets the list of credentials to show. /// [Parameter] public List Credentials { get; set; } = []; /// /// Gets or sets the default sort direction that is applied to the provided credentials list. /// [Parameter] public SortDirection SortDirection { get; set; } = SortDirection.Ascending; /// /// Gets or sets the column to sort by. /// private string SortColumn { get; set; } = "CreatedAt"; /// /// Gets or sets the columns to show in the table. /// private readonly List _tableColumns = [ new TableColumn { Title = "Service", PropertyName = "Service" }, new TableColumn { Title = "Username", PropertyName = "Username" }, new TableColumn { Title = "Email", PropertyName = "Email" }, new TableColumn { Title = "Created", PropertyName = "CreatedAt" } ]; /// /// Gets or sets the sorted credentials. /// private IEnumerable SortedCredentials => SortList(Credentials, SortColumn, SortDirection); /// /// Handles the sort changed event. /// /// The sort event. private void HandleSortChanged((string column, SortDirection direction) sort) { SortColumn = sort.column; SortDirection = sort.direction; StateHasChanged(); } /// /// Sorts the list of credentials. /// /// The list of credentials to sort. /// The column to sort by. /// The direction to sort by. private static IEnumerable SortList(List credentials, string sortColumn, SortDirection sortDirection) { return sortColumn switch { "Service" => SortableTable.SortListByProperty(credentials, c => c.Service, sortDirection), "Username" => SortableTable.SortListByProperty(credentials, c => c.Username, sortDirection), "Email" => SortableTable.SortListByProperty(credentials, c => c.Email, sortDirection), "CreatedAt" => SortableTable.SortListByProperty(credentials, c => c.CreatedAt, sortDirection), _ => credentials }; } /// /// Navigates to the credential details page. /// /// The ID of the credential to navigate to. private void NavigateToCredential(Guid credentialId) { NavigationManager.NavigateTo($"/credentials/{credentialId}"); } }