Removal of LocalStorage from Dropdowns, Dynamic Dropdown population
This commit is contained in:
parent
5632ab72d2
commit
a0ff62377c
2 changed files with 111 additions and 114 deletions
|
@ -3,48 +3,75 @@
|
|||
import DropDownElement from '$lib/components/DropDownElement.svelte';
|
||||
import SelectedGameGroupsStore from '$lib/stores/GameGroupFilter';
|
||||
import SelectedGameStore from '$lib/stores/GameFilter';
|
||||
import ChellarisDataStore from '$lib/stores/ChellarisData';
|
||||
import type { ChellarisGame, ChellarisGameGroup, ChellarisInfo } from '$lib/types/chellaris';
|
||||
|
||||
let selectedGame: string = "";
|
||||
let selectedGame: string = '';
|
||||
let selectedGameGroups: Array<string> = [];
|
||||
let selectedGameGroupsMap: Map<string, Array<string>> = new Map();
|
||||
|
||||
let gameGroups: Map<string, ChellarisGameGroup> = new Map();
|
||||
let chellarisData: ChellarisInfo = {
|
||||
games: new Map(),
|
||||
ethics: [],
|
||||
portraits: []
|
||||
};
|
||||
let store: string | null;
|
||||
|
||||
// Chellaris Data Code
|
||||
const updateGameGroups = () => {
|
||||
let tmpData;
|
||||
if (selectedGame == "") {
|
||||
tmpData = chellarisData.games.get(chellarisData.games.keys().next().value);
|
||||
}
|
||||
else {
|
||||
tmpData = chellarisData.games.get(selectedGame);
|
||||
}
|
||||
|
||||
if (typeof tmpData !== 'undefined') {
|
||||
console.log(tmpData.groups);
|
||||
gameGroups = tmpData.groups;
|
||||
}
|
||||
}
|
||||
|
||||
ChellarisDataStore.subscribe((data) => {
|
||||
chellarisData = data;
|
||||
|
||||
updateGameGroups();
|
||||
// TODO Update selection if Groups Differ? Does this value ever even update without a full page reload?
|
||||
});
|
||||
|
||||
// Group Selection Code
|
||||
const updateSelectedGroups = () => {
|
||||
const tmp = selectedGameGroupsMap.get(selectedGame);
|
||||
if (typeof tmp !== 'undefined') {
|
||||
selectedGameGroups = [...tmp.values()];
|
||||
} else {
|
||||
selectedGameGroups = [...gameGroups.keys()];
|
||||
selectedGameGroupsMap.set(selectedGame, selectedGameGroups);
|
||||
SelectedGameGroupsStore.set(selectedGameGroupsMap);
|
||||
}
|
||||
};
|
||||
|
||||
SelectedGameStore.subscribe((selection) => {
|
||||
selectedGame = selection;
|
||||
|
||||
updateGameGroups();
|
||||
|
||||
if (selectedGameGroupsMap.size != 0) {
|
||||
const tmp = selectedGameGroupsMap.get(selectedGame);
|
||||
if (typeof tmp !== "undefined") {
|
||||
selectedGameGroups = [...tmp.values()];
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if (typeof localStorage !== 'undefined') {
|
||||
store = localStorage.getItem('gameGroupSelection');
|
||||
|
||||
if (typeof store == 'string') {
|
||||
let selectedGameGroupsMap = new Map<string, Array<string>>(JSON.parse(store));
|
||||
const tmp = selectedGameGroupsMap.get(selectedGame);
|
||||
if (typeof tmp !== "undefined") {
|
||||
selectedGameGroups = [...tmp.values()];
|
||||
}
|
||||
SelectedGameGroupsStore.set(selectedGameGroupsMap);
|
||||
}
|
||||
updateSelectedGroups();
|
||||
}
|
||||
});
|
||||
|
||||
SelectedGameGroupsStore.subscribe((selection) => {
|
||||
selectedGameGroupsMap = selection;
|
||||
const tmp = selection.get(selectedGame);
|
||||
if (typeof tmp !== "undefined") {
|
||||
selectedGameGroups = [...tmp.values()];
|
||||
}
|
||||
updateSelectedGroups();
|
||||
|
||||
if (typeof localStorage !== 'undefined') {
|
||||
localStorage.setItem('gameGroupSelection', JSON.stringify(Array.from(selection.entries())));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
const updateGameGroupSelection = () => {
|
||||
SelectedGameGroupsStore.update((selection) => selection.set(selectedGame, selectedGameGroups));
|
||||
};
|
||||
|
@ -52,40 +79,20 @@
|
|||
const dropdownId = crypto.randomUUID();
|
||||
</script>
|
||||
|
||||
<DropDown dropdownId={dropdownId} dropdownTitle="Group Selection">
|
||||
<DropDownElement dropdownId={dropdownId}>
|
||||
<DropDown {dropdownId} dropdownTitle="Group Selection">
|
||||
{#each gameGroups as group}
|
||||
<DropDownElement {dropdownId}>
|
||||
<input
|
||||
id="checkboxGameGroupA"
|
||||
id={'checkbox' + group[0]}
|
||||
data-dropdown={dropdownId}
|
||||
type="checkbox"
|
||||
bind:group={selectedGameGroups}
|
||||
on:change={updateGameGroupSelection}
|
||||
value="A"
|
||||
value={group[0]}
|
||||
/>
|
||||
<label for="checkboxGameGroupA" data-dropdown={dropdownId}>Group A</label>
|
||||
</DropDownElement>
|
||||
<DropDownElement dropdownId={dropdownId}>
|
||||
<input
|
||||
id="checkboxGameGroupB"
|
||||
data-dropdown={dropdownId}
|
||||
type="checkbox"
|
||||
bind:group={selectedGameGroups}
|
||||
on:change={updateGameGroupSelection}
|
||||
value="B"
|
||||
/>
|
||||
<label for="checkboxGameGroupB" data-dropdown={dropdownId}>Group B</label>
|
||||
</DropDownElement>
|
||||
<DropDownElement dropdownId={dropdownId}>
|
||||
<input
|
||||
id="checkboxGameGroupNA"
|
||||
data-dropdown={dropdownId}
|
||||
type="checkbox"
|
||||
bind:group={selectedGameGroups}
|
||||
on:change={updateGameGroupSelection}
|
||||
value="N/A"
|
||||
/>
|
||||
<label for="checkboxGameGroupNA" data-dropdown={dropdownId}>Ungrouped</label>
|
||||
<label for={'checkbox' + group[0]} data-dropdown={dropdownId}>{group[1].name}</label>
|
||||
</DropDownElement>
|
||||
{/each}
|
||||
</DropDown>
|
||||
|
||||
<style>
|
||||
|
|
|
@ -2,19 +2,18 @@
|
|||
import DropDown from '$lib/components/DropDown.svelte';
|
||||
import DropDownElement from '$lib/components/DropDownElement.svelte';
|
||||
import SelectedGameStore from '$lib/stores/GameFilter';
|
||||
import ChellarisDataStore from '$lib/stores/ChellarisData';
|
||||
import type { ChellarisGame } from '$lib/types/chellaris';
|
||||
|
||||
let selectedGame: string = "";
|
||||
let store: string | null;
|
||||
let selectedGame = '';
|
||||
let gameList: Map<string, ChellarisGame> = new Map();
|
||||
|
||||
if (typeof localStorage !== 'undefined') {
|
||||
store = localStorage.getItem('gameSelection');
|
||||
|
||||
if (typeof store == 'string') {
|
||||
selectedGame = JSON.parse(store);
|
||||
SelectedGameStore.set(selectedGame);
|
||||
}
|
||||
}
|
||||
// Chellaris Data Code
|
||||
ChellarisDataStore.subscribe((data) => {
|
||||
gameList = data.games;
|
||||
});
|
||||
|
||||
// Game Selection Code
|
||||
SelectedGameStore.subscribe((selection) => {
|
||||
selectedGame = selection;
|
||||
|
||||
|
@ -27,35 +26,26 @@
|
|||
SelectedGameStore.update(() => selectedGame);
|
||||
};
|
||||
|
||||
// Dropdown UUID to make the Click Event work properly
|
||||
const dropdownId = crypto.randomUUID();
|
||||
</script>
|
||||
|
||||
<DropDown dropdownId={dropdownId} dropdownTitle="Game Selection">
|
||||
<DropDownElement dropdownId={dropdownId}>
|
||||
<DropDown {dropdownId} dropdownTitle="Game Selection">
|
||||
{#each gameList as game}
|
||||
<DropDownElement {dropdownId}>
|
||||
<input
|
||||
id="checkboxGameGroupA"
|
||||
id={'checkbox' + game[0]}
|
||||
data-dropdown={dropdownId}
|
||||
type="radio"
|
||||
bind:group={selectedGame}
|
||||
on:change={updateGameSelection}
|
||||
value="16"
|
||||
value={game[0]}
|
||||
/>
|
||||
<label for="checkboxGameGroupA" data-dropdown={dropdownId}>Game 16</label>
|
||||
</DropDownElement>
|
||||
<DropDownElement dropdownId={dropdownId}>
|
||||
<input
|
||||
id="checkboxGameGroupB"
|
||||
data-dropdown={dropdownId}
|
||||
type="radio"
|
||||
bind:group={selectedGame}
|
||||
on:change={updateGameSelection}
|
||||
value="17"
|
||||
/>
|
||||
<label for="checkboxGameGroupB" data-dropdown={dropdownId}>Game 17</label>
|
||||
<label for={'checkbox' + game[0]} data-dropdown={dropdownId}>{game[1].name}</label>
|
||||
</DropDownElement>
|
||||
{/each}
|
||||
</DropDown>
|
||||
|
||||
|
||||
<style>
|
||||
label:hover {
|
||||
color: var(--color-active-1);
|
||||
|
|
Reference in a new issue