Refactored archive uploader to use binding instead of Game parameter

May fix issues where game metadata is wiped after uploading an archive.
redistributables
Pat Hartl 2023-10-18 18:11:20 -05:00
parent 539ddb2f2e
commit 2287ac9922
2 changed files with 8 additions and 9 deletions

View File

@ -11,7 +11,7 @@
<Space Direction="DirectionVHType.Vertical" Style="width: 100%"> <Space Direction="DirectionVHType.Vertical" Style="width: 100%">
<SpaceItem> <SpaceItem>
<Table TItem="Archive" DataSource="@Game.Archives.OrderByDescending(a => a.CreatedOn)" HidePagination="true" Responsive> <Table TItem="Archive" DataSource="@Archives.OrderByDescending(a => a.CreatedOn)" HidePagination="true" Responsive>
<PropertyColumn Property="a => a.Version" /> <PropertyColumn Property="a => a.Version" />
<PropertyColumn Property="a => a.CompressedSize"> <PropertyColumn Property="a => a.CompressedSize">
@ByteSizeLib.ByteSize.FromBytes(context.CompressedSize) @ByteSizeLib.ByteSize.FromBytes(context.CompressedSize)
@ -49,7 +49,9 @@
<ArchiveUploader @ref="Uploader" OnArchiveUploaded="AddArchive" /> <ArchiveUploader @ref="Uploader" OnArchiveUploaded="AddArchive" />
@code { @code {
[Parameter] public Game Game { get; set; } [Parameter] public Guid GameId { get; set; }
[Parameter] public ICollection<Archive> Archives { get; set; }
[Parameter] public EventCallback<ICollection<Archive>> ArchivesChanged { get; set; }
Archive Archive; Archive Archive;
ArchiveUploader Uploader; ArchiveUploader Uploader;
@ -63,10 +65,7 @@
private async Task LoadData() private async Task LoadData()
{ {
Game.Archives = await ArchiveService.Get(a => a.GameId == Game.Id).OrderByDescending(a => a.CreatedOn).ToListAsync(); Archives = await ArchiveService.Get(a => a.GameId == GameId).OrderByDescending(a => a.CreatedOn).ToListAsync();
if (Game.Archives == null)
Game.Archives = new List<Archive>();
} }
private async Task Download(Archive archive) private async Task Download(Archive archive)
@ -80,7 +79,7 @@
{ {
Archive = new Archive() Archive = new Archive()
{ {
GameId = Game.Id, GameId = GameId,
Id = Guid.NewGuid() Id = Guid.NewGuid()
}; };
@ -89,7 +88,7 @@
private async Task AddArchive(Archive archive) private async Task AddArchive(Archive archive)
{ {
var lastArchive = Game.Archives.OrderByDescending(a => a.CreatedOn).FirstOrDefault(); var lastArchive = Archives.OrderByDescending(a => a.CreatedOn).FirstOrDefault();
Archive = await ArchiveService.Add(archive); Archive = await ArchiveService.Add(archive);

View File

@ -125,7 +125,7 @@
</div> </div>
<div data-panel="Archives"> <div data-panel="Archives">
<ArchiveEditor Game="Game" /> <ArchiveEditor @bind-Archives="Game.Archives" GameId="Game.Id" />
</div> </div>
} }