Skip to content

Commit

Permalink
Feat: improve seasons listing with ordered results
Browse files Browse the repository at this point in the history
  • Loading branch information
mateussouzaweb committed Feb 10, 2024
1 parent 3c295d6 commit fdb7141
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/scripts/serie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,16 @@ const listSerieInfo: Callback = async ({ state }) => {
const seasons = seasonsResponse.items.map((item) => {
return {
id: item.id,
name: 'S' + item.season_number + ': ' + item.title
number: item.season_number,
name: item.title
}
})

state.seasons = seasons
state.seasons = seasons.sort((a, b) => {
if(a.number < b.number) { return -1; }
if(a.number > b.number) { return 1; }
return 0;
})

if( !state.seasonId && seasons.length ){
state.seasonId = seasons[0].id
Expand Down
2 changes: 1 addition & 1 deletion src/templates/serie.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ <h1 tabindex="0">
<div class="dropdown-list">
<ul>
{{ each option in seasons }}
<li tabindex="0" data-value="{{ option.id }}">{{ option.name }}</li>
<li tabindex="0" data-value="{{ option.id }}">S{{ option.number }} - {{ option.name }}</li>
{{ end }}
</ul>
</div>
Expand Down

0 comments on commit fdb7141

Please sign in to comment.