2022-08-27 23:49:54 -05:00
|
|
|
using System.Globalization;
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
using Microsoft.JSInterop;
|
2022-08-28 09:19:21 -05:00
|
|
|
using Newtonsoft.Json;
|
2022-08-27 23:49:54 -05:00
|
|
|
using NftFaucetRadzen.Components;
|
|
|
|
using NftFaucetRadzen.Components.CardList;
|
2022-08-28 09:19:21 -05:00
|
|
|
using NftFaucetRadzen.Models;
|
2022-08-27 23:49:54 -05:00
|
|
|
using NftFaucetRadzen.Plugins;
|
|
|
|
using Radzen;
|
|
|
|
|
|
|
|
namespace NftFaucetRadzen.Pages;
|
|
|
|
|
|
|
|
public partial class TokensPage : BasicComponent
|
|
|
|
{
|
|
|
|
[Inject]
|
|
|
|
protected IJSRuntime JSRuntime { get; set; }
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
protected DialogService DialogService { get; set; }
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
protected TooltipService TooltipService { get; set; }
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
protected ContextMenuService ContextMenuService { get; set; }
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
protected NotificationService NotificationService { get; set; }
|
|
|
|
|
|
|
|
protected override void OnInitialized()
|
|
|
|
{
|
|
|
|
// ToDo: Add loading from IndexedDB
|
|
|
|
RefreshData();
|
|
|
|
}
|
|
|
|
|
|
|
|
private CardListItem[] Data { get; set; }
|
|
|
|
|
|
|
|
private void RefreshData()
|
|
|
|
{
|
2022-08-28 09:19:21 -05:00
|
|
|
Data = AppState?.Storage?.Tokens?.Select(MapCardListItem).ToArray() ?? Array.Empty<CardListItem>();
|
2022-08-27 23:49:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
private CardListItem MapCardListItem(IToken token)
|
|
|
|
=> new CardListItem
|
|
|
|
{
|
|
|
|
Id = token.Id,
|
|
|
|
Properties = new[]
|
|
|
|
{
|
|
|
|
new CardListItemProperty
|
|
|
|
{
|
|
|
|
Name = "Id",
|
|
|
|
Value = token.Id.ToString(),
|
|
|
|
},
|
|
|
|
new CardListItemProperty
|
|
|
|
{
|
|
|
|
Name = "CreatedAt",
|
|
|
|
Value = token.CreatedAt.ToString(CultureInfo.InvariantCulture),
|
|
|
|
},
|
|
|
|
new CardListItemProperty
|
|
|
|
{
|
|
|
|
Name = "Name",
|
|
|
|
Value = token.Name,
|
|
|
|
},
|
|
|
|
new CardListItemProperty
|
|
|
|
{
|
|
|
|
Name = "Description",
|
|
|
|
Value = token.Description,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2022-08-28 01:04:38 -05:00
|
|
|
|
|
|
|
private async Task OpenCreateTokenDialog()
|
|
|
|
{
|
2022-08-28 09:19:21 -05:00
|
|
|
var newFileModel = (NewFileModel) await DialogService.OpenAsync<CreateTokenPage>("Create new token",
|
2022-08-28 01:04:38 -05:00
|
|
|
new Dictionary<string, object>(),
|
|
|
|
new DialogOptions() { Width = "700px", Height = "570px", Resizable = true, Draggable = true });
|
2022-08-28 09:19:21 -05:00
|
|
|
|
|
|
|
var token = new Token
|
|
|
|
{
|
|
|
|
Id = Guid.NewGuid(),
|
|
|
|
Name = newFileModel.Name,
|
|
|
|
Description = newFileModel.Description,
|
|
|
|
CreatedAt = DateTime.Now,
|
|
|
|
Image = new TokenMedia
|
|
|
|
{
|
|
|
|
FileName = newFileModel.FileName,
|
|
|
|
FileSize = newFileModel.FileSize!.Value,
|
|
|
|
FileData = newFileModel.FileData,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
AppState.Storage.Tokens ??= new List<IToken>();
|
|
|
|
AppState.Storage.Tokens.Add(token);
|
|
|
|
RefreshData();
|
|
|
|
StateHasChangedSafe();
|
2022-08-28 01:04:38 -05:00
|
|
|
}
|
2022-08-27 23:49:54 -05:00
|
|
|
}
|