Skip to content

Commit

Permalink
Puzzle detail: Hide filters toggle when useless
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMikes committed Feb 3, 2025
1 parent 5e01ac2 commit f8a1d9f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 47 deletions.
8 changes: 4 additions & 4 deletions src/Component/PuzzleTimes.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ final class PuzzleTimes
/** @var array<string, array<PuzzleSolver|PuzzleSolversGroup>> */
public array $times = [];

/** @var null|array<string, int> */
private null|array $availableCountries = null;
/** @var array<string, int> */
public array $availableCountries = [];

public function __construct(
readonly private GetPuzzleSolvers $getPuzzleSolvers,
Expand Down Expand Up @@ -195,11 +195,11 @@ public function populate(): void
/**
* @return array<PlayersPerCountry>
*/
public function getAvailableCountries(): array
public function getCountries(): array
{
$availableCountries = [];

foreach ($this->availableCountries ?? [] as $countryCode => $count) {
foreach ($this->availableCountries as $countryCode => $count) {
$availableCountries[] = new PlayersPerCountry(CountryCode::fromCode($countryCode), $count);
}

Expand Down
90 changes: 47 additions & 43 deletions templates/components/PuzzleTimes.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -49,51 +49,55 @@
{% endif %}
</div>

<div class="dropdown">
<button
class="btn btn-outline-primary btn-sm dropdown-toggle"
type="button"
id="filtersDropdown"
data-bs-toggle="dropdown"
aria-expanded="false"
>
<i class="bi-filter"></i>
{{ 'filters.button'|trans }}
{% if this.activeFiltersCount > 0 %}<sup>{{ this.activeFiltersCount }}</sup>{% endif%}
</button>

<div class="dropdown-menu dropdown-menu-end filters px-3 py-0" aria-labelledby="filtersDropdown">
{% if this.category == 'solo' %}
<div class="form-check form-switch my-3">
<input
data-model="onlyFirstTries"
type="checkbox"
class="form-check-input"
role="switch"
id="only-first-attempt"
{{ this.onlyFirstTries ? 'checked' }}>
<label for="only-first-attempt" class="form-check-label" onclick="arguments[0].stopPropagation()">{{ 'only_first_tries_filter'|trans }}</label>
</div>
{% endif %}

<div class="my-3">
<select
data-model="country"
class="form-select"
data-controller="country-autocomplete symfony--ux-autocomplete--autocomplete">
<option value="" data-icon="" {{ this.country == null ? 'selected' }}>{{ 'forms.country_all'|trans }}</option>
{% for availableCountry in this.availableCountries %}
<option
value="{{ availableCountry.countryCode.name }}"
data-icon="fi fi-{{ availableCountry.countryCode.name|lower }}"
{{ this.country == availableCountry.countryCode.name ? 'selected' }}>
{{ availableCountry.countryCode.value }} ({{ availableCountry.playersCount }})
</option>
{% endfor %}
</select>
{% if this.availableCountries|length > 1 or (this.category == 'solo' and this.times|length > 1) %}
<div class="dropdown">
<button
class="btn btn-outline-primary btn-sm dropdown-toggle"
type="button"
id="filtersDropdown"
data-bs-toggle="dropdown"
aria-expanded="false"
>
<i class="bi-filter"></i>
{{ 'filters.button'|trans }}
{% if this.activeFiltersCount > 0 %}<sup>{{ this.activeFiltersCount }}</sup>{% endif%}
</button>

<div class="dropdown-menu dropdown-menu-end filters px-3 py-0" aria-labelledby="filtersDropdown">
{% if this.category == 'solo' and this.times|length > 1 %}
<div class="form-check form-switch my-3">
<input
data-model="onlyFirstTries"
type="checkbox"
class="form-check-input"
role="switch"
id="only-first-attempt"
{{ this.onlyFirstTries ? 'checked' }}>
<label for="only-first-attempt" class="form-check-label" onclick="arguments[0].stopPropagation()">{{ 'only_first_tries_filter'|trans }}</label>
</div>
{% endif %}

{% if this.availableCountries|length > 1 %}
<div class="my-3">
<select
data-model="country"
class="form-select"
data-controller="country-autocomplete symfony--ux-autocomplete--autocomplete">
<option value="" data-icon="" {{ this.country == null ? 'selected' }}>{{ 'forms.country_all'|trans }}</option>
{% for availableCountry in this.countries %}
<option
value="{{ availableCountry.countryCode.name }}"
data-icon="fi fi-{{ availableCountry.countryCode.name|lower }}"
{{ this.country == availableCountry.countryCode.name ? 'selected' }}>
{{ availableCountry.countryCode.value }} ({{ availableCountry.playersCount }})
</option>
{% endfor %}
</select>
</div>
{% endif %}
</div>
</div>
</div>
{% endif %}
</div>

<div>
Expand Down

0 comments on commit f8a1d9f

Please sign in to comment.