Skip to content

Commit

Permalink
refactor: simplify state and type mapping functions
Browse files Browse the repository at this point in the history
* refactor: simplify state and type mapping functions

* fix: add error handling to state and type mapping functions

---------

Co-authored-by: Davide Marcoli <69892203+davidemarcoli@users.noreply.github.com>
  • Loading branch information
ronaldland and davidemarcoli authored Nov 25, 2024
1 parent bf69c12 commit 693d3f1
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/routes/browse/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,20 @@
}
function mapSelectedStates(selectedStates: Selected<string>[]) {
return selectedStates.map((selectedState) => selectedState.value as keyof typeof states);
try {
return [...(selectedStates?.values() ?? [])].map((v) => v?.value as keyof typeof states);
} catch (error) {
console.error('Error mapping selected states:', error);
return [];
}
}
function mapSelectedTypes(selectedTypes: Selected<string>[]) {
return selectedTypes.map((selectedType) => selectedType.value as keyof typeof types);
try {
return [...(selectedTypes?.values() ?? [])].map((v) => v?.value as keyof typeof types);
} catch (error) {
console.error('Error mapping selected types:', error);
return [];
}
}
</script>

Expand Down

0 comments on commit 693d3f1

Please sign in to comment.