2023-08-12 19:58:23 +02:00
< script lang = "ts" >
2023-08-13 03:25:16 +02:00
import DropDown from '$lib/components/DropDown.svelte';
2023-08-12 19:58:23 +02:00
import DropDownElement from '$lib/components/DropDownElement.svelte';
import SelectedGameGroupsStore from '$lib/stores/GameGroupFilter';
2023-08-13 03:25:16 +02:00
import SelectedGameStore from '$lib/stores/GameFilter';
import ChellarisDataStore from '$lib/stores/ChellarisData';
2023-08-24 05:04:27 +02:00
// Game Selection Code
2023-08-13 03:25:16 +02:00
SelectedGameStore.subscribe((selection) => {
2023-08-24 05:04:27 +02:00
if (typeof $SelectedGameGroupsStore[selection] === 'undefined') {
// Default to all available groups
2023-08-27 21:00:56 +02:00
$SelectedGameGroupsStore[selection] = { gameId : $SelectedGameStore , selectedGroups : Object.values ( $ChellarisDataStore . games [ $SelectedGameStore ]. groups ). map (( group ) => group . id ) } ;
2023-08-24 05:04:27 +02:00
SelectedGameGroupsStore.update(() => $SelectedGameGroupsStore);
2023-08-13 03:25:16 +02:00
}
2023-08-24 05:04:27 +02:00
})
2023-08-12 19:58:23 +02:00
2023-08-24 05:04:27 +02:00
// Game Group Selection Code
$: {
2023-08-13 03:25:16 +02:00
if (typeof localStorage !== 'undefined') {
2023-08-24 05:04:27 +02:00
localStorage.setItem('gameGroupSelection', JSON.stringify($SelectedGameGroupsStore));
2023-08-12 19:58:23 +02:00
}
2023-08-24 05:04:27 +02:00
}
$: selectedGameData = $SelectedGameGroupsStore[$SelectedGameStore];
2023-08-27 21:00:56 +02:00
$: groupJoiner = Object.values(selectedGameData.selectedGroups).length > 2 ? ', ' : ' & ';
2023-08-12 19:58:23 +02:00
2023-08-24 05:04:27 +02:00
const updateGroupStore = () => {
SelectedGameGroupsStore.update(() => $SelectedGameGroupsStore);
}
2023-08-12 19:58:23 +02:00
2023-08-13 03:25:16 +02:00
const dropdownId = crypto.randomUUID();
2023-08-12 19:58:23 +02:00
< / script >
2023-08-24 05:04:27 +02:00
< DropDown
{ dropdownId }
2023-08-27 21:00:56 +02:00
dropdownTitle={( Object . values ( selectedGameData . selectedGroups ). length > 1 ? 'Groups ' : 'Group ' ) +
Object.values(selectedGameData.selectedGroups)
2023-08-24 05:04:27 +02:00
.map((selection) => $ChellarisDataStore.games[$SelectedGameStore].groups[selection]?.name)
.join(groupJoiner)}
>
2023-08-27 21:00:56 +02:00
{ #each Object . values ( $ChellarisDataStore . games [ $SelectedGameStore ]. groups ) as group }
2023-08-24 05:04:27 +02:00
{ #if group }
< DropDownElement { dropdownId } >
< input
id={ 'checkbox' + group . id }
data-dropdown={ dropdownId }
type="checkbox"
bind:group={ selectedGameData . selectedGroups }
on:change={ updateGroupStore }
value={ group . id }
/>
< label for = { 'checkbox' + group . id } data-dropdown= { dropdownId } > { group . name } </ label >
< / DropDownElement >
{ /if }
2023-08-13 03:25:16 +02:00
{ /each }
2023-08-12 19:58:23 +02:00
< / DropDown >
< style >
2023-08-13 03:25:16 +02:00
:checked + label {
color: var(--color-active-2);
}
2023-08-12 19:58:23 +02:00
2023-08-13 03:25:16 +02:00
:hover {
color: var(--color-active-1) !important;
}
2023-08-12 19:58:23 +02:00
< / style >