Skip to content

Commit

Permalink
fix: build char page based on index instead of type array (#249)
Browse files Browse the repository at this point in the history
* fix: build char page based on index instead of type array

* chore: remove unnecessary button
  • Loading branch information
maalni authored Jun 5, 2024
1 parent d4d652e commit 91b14cf
Showing 1 changed file with 15 additions and 28 deletions.
43 changes: 15 additions & 28 deletions src/routes/characters/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
<script lang="ts">
import IconButton from '$lib/components/ui/icon-button/IconButton.svelte';
import { mdiFilterOutline, mdiSort, mdiViewGrid, mdiViewList } from '@mdi/js';
import { mdiFilterOutline, mdiSort } from '@mdi/js';
import CharCard from '$lib/components/ui/card/CharCard.svelte';
import Searchbar from '$lib/components/ui/searchbar/Searchbar.svelte';
import S3Service from '$lib/services/s3';
import {
type CharacterKey,
characterKeyList,
isCharacterKey
} from '$lib/types/keys/CharacterKey';
import DefaultLayout from '$lib/components/layout/DefaultLayout.svelte';
import type { WeaponTypes } from '$lib/types/weapon';
import type { Elements } from '$lib/types/elements';
import { dataIndexStore } from '$lib/store/index_store';
import i18n from '$lib/services/i18n';
import { userProfile } from '$lib/store/user_profile';
import { get } from 'svelte/store';
let view = true;
let charData: {
link: string;
name: CharacterKey;
name: string;
element: Elements;
weapon: WeaponTypes;
img: string;
Expand All @@ -29,34 +24,26 @@
const userCharData = $userProfile.characters;
charData = characterKeyList
.filter((key) => isCharacterKey(key))
.map((key: CharacterKey) => {
const index = $dataIndexStore.character[key];
charData = Object.keys($dataIndexStore.character).map((key) => {
const index = get(dataIndexStore).character[key];
return {
obtained:
userCharData !== undefined ? Object.keys(userCharData).includes(key) : false,
link: '/characters/' + key,
name: index !== undefined ? index.name : key,
element: 'geo',
weapon: 'bow',
img: S3Service.getCharacter(key).icon,
rarity: index !== undefined ? index.rarity : 0
};
});
const toggleViewType = () => {
view = !view;
};
return {
obtained: userCharData !== undefined ? Object.keys(userCharData).includes(key) : false,
link: '/characters/' + key,
name: index.name,
element: 'geo',
weapon: 'bow',
img: S3Service.getCharacter(key).icon,
rarity: index.rarity
};
});
</script>

<DefaultLayout title={$i18n.t('characters.overview.title')}>
<svelte:fragment slot="titlebarActions">
<Searchbar searchGroup="Characters" searchableDataList={charData} />
<IconButton icon={mdiSort}>{$i18n.t('action.sort_by')}</IconButton>
<IconButton icon={mdiFilterOutline}>{$i18n.t('action.filter_by')}</IconButton>
<IconButton icon={view ? mdiViewList : mdiViewGrid} on:click={toggleViewType} />
</svelte:fragment>
<div class="flex flex-wrap gap-4 justify-center">
{#each charData as character}
Expand Down

0 comments on commit 91b14cf

Please sign in to comment.