Skip to content

Commit

Permalink
Remove practice spawnsets from front-end (#649)
Browse files Browse the repository at this point in the history
* Remove practice spawnsets from front-end

* Remove practiceOnly parameter

* Remove practice value from SpawnsetPage
  • Loading branch information
NoahStolk authored Sep 8, 2024
1 parent ce653e0 commit 5c8f0bb
Show file tree
Hide file tree
Showing 20 changed files with 11 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ public record AddSpawnset
[StringLength(2048)]
public required string? HtmlDescription { get; init; }

public required bool IsPractice { get; init; }

[MaxLength(SpawnsetConstants.MaxFileSize, ErrorMessage = SpawnsetConstants.MaxFileSizeErrorMessage)]
public required byte[] FileContents { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@ public record EditSpawnset

[StringLength(2048)]
public required string? HtmlDescription { get; init; }

public required bool IsPractice { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@ public record GetSpawnset
public required string? HtmlDescription { get; init; }

public required DateTime LastUpdated { get; init; }

public required bool IsPractice { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@ public record GetSpawnsetForOverview : IAdminOverviewGetDto
public required string? HtmlDescription { get; init; }

public required DateTime LastUpdated { get; init; }

public required bool IsPractice { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ public enum SpawnsetSorting
MaxDisplayWaves = 3,
HtmlDescription = 4,
LastUpdated = 5,
IsPractice = 6,
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ public record GetSpawnset

public required string AuthorName { get; init; }

public required bool IsPractice { get; init; }

public required int? CustomLeaderboardId { get; init; }

public required string? HtmlDescription { get; init; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,10 @@ public async Task<HttpResponseMessage> UpdateProfileByPlayerId(int id, EditPlaye
return await SendRequest(HttpMethod.Put, $"api/players/{id}/profile", JsonContent.Create(editPlayerProfile));
}

public async Task<Page<GetSpawnsetOverview>> GetSpawnsets(bool practiceOnly, bool withCustomLeaderboardOnly, string? spawnsetFilter, string? authorFilter, int pageIndex, int pageSize, SpawnsetSorting? sortBy, bool ascending)
public async Task<Page<GetSpawnsetOverview>> GetSpawnsets(bool withCustomLeaderboardOnly, string? spawnsetFilter, string? authorFilter, int pageIndex, int pageSize, SpawnsetSorting? sortBy, bool ascending)
{
Dictionary<string, object?> queryParameters = new()
{
{ nameof(practiceOnly), practiceOnly },
{ nameof(withCustomLeaderboardOnly), withCustomLeaderboardOnly },
{ nameof(spawnsetFilter), spawnsetFilter },
{ nameof(authorFilter), authorFilter },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<InputWrapper Label="Name"><InputText class="admin-input" @bind-Value="@_addSpawnsetState.Name" /></InputWrapper>
<InputWrapper Label="Max display waves"><InputNumber class="admin-input" @bind-Value="_addSpawnsetState.MaxDisplayWaves" /></InputWrapper>
<InputWrapper Label="HTML description"><InputTextArea class="admin-input w-full h-64" @bind-Value="@_addSpawnsetState.HtmlDescription" /></InputWrapper>
<InputWrapper Label="Practice"><InputCheckbox @bind-Value="@_addSpawnsetState.IsPractice" /></InputWrapper>
<InputWrapper Label="File"><InputFile OnChange="LoadFile" /></InputWrapper>
</AdminAdd>
</AdminAuthorizer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<InputWrapper Label="Name"><InputText class="admin-input" @bind-Value="@_editSpawnsetState.Name" /></InputWrapper>
<InputWrapper Label="Max display waves"><InputNumber class="admin-input" @bind-Value="_editSpawnsetState.MaxDisplayWaves" /></InputWrapper>
<InputWrapper Label="HTML description"><InputTextArea class="admin-input w-full h-64" @bind-Value="@_editSpawnsetState.HtmlDescription" /></InputWrapper>
<InputWrapper Label="Practice"><InputCheckbox @bind-Value="@_editSpawnsetState.IsPractice" /></InputWrapper>
</AdminEdit>
</AdminAuthorizer>

Expand All @@ -36,7 +35,6 @@

GetSpawnset getSpawnset = await Http.GetSpawnsetById(Id);
_editSpawnsetState.HtmlDescription = getSpawnset.HtmlDescription;
_editSpawnsetState.IsPractice = getSpawnset.IsPractice;
_editSpawnsetState.MaxDisplayWaves = getSpawnset.MaxDisplayWaves;
_editSpawnsetState.Name = getSpawnset.Name;
_editSpawnsetState.PlayerId = getSpawnset.PlayerId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@
new(SpawnsetSorting.MaxDisplayWaves, "Max display waves", d => d.MaxDisplayWaves, TextAlign.Right),
new(SpawnsetSorting.HtmlDescription, "HTML description", d => d.HtmlDescription, TextAlign.Left),
new(SpawnsetSorting.LastUpdated, "Last updated", d => d.LastUpdated.ToString(StringFormats.DateFormat), TextAlign.Left),
new(SpawnsetSorting.IsPractice, "Practice", d => d.IsPractice, TextAlign.Left),
];
}
14 changes: 2 additions & 12 deletions src/DevilDaggersInfo.Web.Client/Pages/Custom/Spawnsets/Index.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ public partial class Index : IHasNavigation
{
private readonly Dictionary<SpawnsetSorting, bool> _sortings = new();

[Parameter]
[SupplyParameterFromQuery]
public bool PracticeOnly { get; set; }

[Parameter]
[SupplyParameterFromQuery]
public bool WithCustomLeaderboardOnly { get; set; }
Expand Down Expand Up @@ -70,12 +66,6 @@ private void ChangeInputAuthorName(ChangeEventArgs e)
NavigationManager.AddOrModifyQueryParameter(nameof(AuthorFilter), AuthorFilter);
}

private void ChangeInputPracticeOnly(bool value)
{
PracticeOnly = value;
NavigationManager.AddOrModifyQueryParameter(nameof(PracticeOnly), PracticeOnly);
}

private void ChangeInputWithCustomLeaderboardOnly(bool value)
{
WithCustomLeaderboardOnly = value;
Expand Down Expand Up @@ -106,7 +96,7 @@ private void Sort(SpawnsetSorting sortBy)
_sortings[sortBy] = !_sortings[sortBy];
Ascending = _sortings[sortBy];

NavigationManager.AddOrModifyQueryParameters(new(nameof(SortBy), SortBy), new(nameof(Ascending), Ascending));
NavigationManager.AddOrModifyQueryParameters(new KeyValuePair<string, object?>(nameof(SortBy), SortBy), new KeyValuePair<string, object?>(nameof(Ascending), Ascending));
}

private async Task Fetch()
Expand All @@ -115,7 +105,7 @@ private async Task Fetch()
int pageSize = PagingUtils.GetValidPageSize(PageSize);
SpawnsetSorting sortBy = SortBy.HasValue ? (SpawnsetSorting)SortBy.Value : SpawnsetSorting.LastUpdated;

GetSpawnsets = await Http.GetSpawnsets(PracticeOnly, WithCustomLeaderboardOnly, SpawnsetFilter, AuthorFilter, pageIndex, pageSize, sortBy, Ascending);
GetSpawnsets = await Http.GetSpawnsets(WithCustomLeaderboardOnly, SpawnsetFilter, AuthorFilter, pageIndex, pageSize, sortBy, Ascending);

if (PageIndex >= TotalPages)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ else
<input class="bg-black border-gray-3 border-2 w-48" value="@SpawnsetFilter" @onchange="ChangeInputSpawnsetName" />
<span>Author name</span>
<input class="bg-black border-gray-3 border-2 w-48" value="@AuthorFilter" @onchange="ChangeInputAuthorName" />
<span>Practice only</span>
<Checkbox CurrentValue="@PracticeOnly" Selected="@ChangeInputPracticeOnly" />
<span>With leaderboard only</span>
<Checkbox CurrentValue="@WithCustomLeaderboardOnly" Selected="@ChangeInputWithCustomLeaderboardOnly" />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ else
<div class="bg-gray-1 max-w-arena-table px-1">
<DataField Name="Author"><span class="whitespace-nowrap">@GetSpawnset.AuthorName</span></DataField>
<DataField Name="Last updated">@GetSpawnset.LastUpdated.ToString(StringFormats.DateTimeFormat)</DataField>
<DataField Name="Practice">@(GetSpawnset.IsPractice ? "Yes" : "No")</DataField>
<DataField Name="File size">@FileSizeUtils.Format(GetSpawnset.FileBytes.Length)</DataField>

<div class="grid grid-cols-2 text-lg">
Expand Down Expand Up @@ -63,7 +62,7 @@ else
<DataField Name="Game version">@SpawnsetBinary.GetSupportedGameVersion().ToDisplayString()</DataField>
<DataField Name="Game mode">@SpawnsetBinary.GameMode.ToDisplayString()</DataField>
</div>

<SpawnsetArenaData SpawnsetBinary="SpawnsetBinary" />
<SpawnsetArenaWrapper SpawnsetBinary="SpawnsetBinary" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,17 @@ public class AddSpawnsetState : IStateObject<AddSpawnset>
[StringLength(2048)]
public string? HtmlDescription { get; set; }

public bool IsPractice { get; set; }

[MaxLength(SpawnsetConstants.MaxFileSize, ErrorMessage = SpawnsetConstants.MaxFileSizeErrorMessage)]
public byte[] FileContents { get; set; } = Array.Empty<byte>();
public byte[] FileContents { get; set; } = [];

public AddSpawnset ToModel()
{
return new()
return new AddSpawnset
{
PlayerId = PlayerId,
Name = Name,
MaxDisplayWaves = MaxDisplayWaves,
HtmlDescription = HtmlDescription,
IsPractice = IsPractice,
FileContents = FileContents,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@ public class EditSpawnsetState : IStateObject<EditSpawnset>
[StringLength(2048)]
public string? HtmlDescription { get; set; }

public bool IsPractice { get; set; }

public EditSpawnset ToModel()
{
return new()
return new EditSpawnset
{
PlayerId = PlayerId,
Name = Name,
MaxDisplayWaves = MaxDisplayWaves,
HtmlDescription = HtmlDescription,
IsPractice = IsPractice,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,27 @@ public static GetSpawnsetForOverview ToAdminApiOverview(this SpawnsetEntity spaw
if (spawnset.Player == null)
throw new InvalidOperationException("Player is not included.");

return new()
return new GetSpawnsetForOverview
{
Id = spawnset.Id,
Author = spawnset.Player.PlayerName,
Name = spawnset.Name,
MaxDisplayWaves = spawnset.MaxDisplayWaves,
HtmlDescription = spawnset.HtmlDescription?.TrimAfter(40, true),
LastUpdated = spawnset.LastUpdated,
IsPractice = spawnset.IsPractice,
};
}

public static GetSpawnset ToAdminApi(this SpawnsetEntity spawnset)
{
return new()
return new GetSpawnset
{
Id = spawnset.Id,
PlayerId = spawnset.PlayerId,
Name = spawnset.Name,
MaxDisplayWaves = spawnset.MaxDisplayWaves,
HtmlDescription = spawnset.HtmlDescription,
LastUpdated = spawnset.LastUpdated,
IsPractice = spawnset.IsPractice,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public async Task<Page<GetSpawnsetForOverview>> GetSpawnsetsAsync(string? filter
{
SpawnsetSorting.Author => spawnsetsQuery.OrderBy(s => s.Player!.PlayerName, ascending).ThenBy(s => s.Id),
SpawnsetSorting.HtmlDescription => spawnsetsQuery.OrderBy(s => s.HtmlDescription, ascending).ThenBy(s => s.Id),
SpawnsetSorting.IsPractice => spawnsetsQuery.OrderBy(s => s.IsPractice, ascending).ThenBy(s => s.Id),
SpawnsetSorting.LastUpdated => spawnsetsQuery.OrderBy(s => s.LastUpdated, ascending).ThenBy(s => s.Id),
SpawnsetSorting.MaxDisplayWaves => spawnsetsQuery.OrderBy(s => s.MaxDisplayWaves, ascending).ThenBy(s => s.Id),
SpawnsetSorting.Name => spawnsetsQuery.OrderBy(s => s.Name, ascending).ThenBy(s => s.Id),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public async Task AddSpawnsetAsync(AddSpawnset addSpawnset)
SpawnsetEntity spawnset = new()
{
HtmlDescription = addSpawnset.HtmlDescription,
IsPractice = addSpawnset.IsPractice,
MaxDisplayWaves = addSpawnset.MaxDisplayWaves,
Name = addSpawnset.Name,
PlayerId = addSpawnset.PlayerId,
Expand Down Expand Up @@ -84,7 +83,6 @@ public async Task EditSpawnsetAsync(int id, EditSpawnset editSpawnset)

// Do not update LastUpdated here. This value is based only on the file which cannot be edited.
spawnset.HtmlDescription = editSpawnset.HtmlDescription;
spawnset.IsPractice = editSpawnset.IsPractice;
spawnset.MaxDisplayWaves = editSpawnset.MaxDisplayWaves;
spawnset.Name = editSpawnset.Name;
spawnset.PlayerId = editSpawnset.PlayerId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public SpawnsetsController(ApplicationDbContext dbContext, ILogger<SpawnsetsCont
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<ActionResult<Page<GetSpawnsetOverview>>> GetSpawnsets(
bool practiceOnly,
bool withCustomLeaderboardOnly,
string? spawnsetFilter = null,
string? authorFilter = null,
Expand All @@ -40,9 +39,6 @@ public async Task<ActionResult<Page<GetSpawnsetOverview>>> GetSpawnsets(
{
IQueryable<SpawnsetEntity> spawnsetsQuery = _dbContext.Spawnsets.AsNoTracking().Include(s => s.Player);

if (practiceOnly)
spawnsetsQuery = spawnsetsQuery.Where(s => s.IsPractice);

if (withCustomLeaderboardOnly)
{
List<int> spawnsetsWithCustomLeaderboardIds = await _dbContext.CustomLeaderboards
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static MainApi.GetSpawnsetOverview ToMainApi(this SpawnsetEntity spawnset
if (spawnset.Player == null)
throw new InvalidOperationException("Player is not included.");

return new()
return new MainApi.GetSpawnsetOverview
{
AdditionalGems = spawnset.EffectiveGemsOrHoming,
GameMode = spawnset.GameMode.ToMainApi(),
Expand All @@ -36,12 +36,11 @@ public static MainApi.GetSpawnset ToMainApi(this SpawnsetEntity spawnset, int? c
if (spawnset.Player == null)
throw new InvalidOperationException("Player is not included.");

return new()
return new MainApi.GetSpawnset
{
AuthorName = spawnset.Player.PlayerName,
FileBytes = fileBytes,
Id = spawnset.Id,
IsPractice = spawnset.IsPractice,
LastUpdated = spawnset.LastUpdated,
Name = spawnset.Name,
CustomLeaderboardId = customLeaderboardId,
Expand Down

0 comments on commit 5c8f0bb

Please sign in to comment.