Separate build getter

This commit is contained in:
Made Baruna 2022-07-20 23:33:38 +07:00
parent e780ab18bf
commit edc036f62f
4 changed files with 34 additions and 6 deletions

View file

@ -4,13 +4,13 @@
import { t } from 'svelte-i18n';
import { characters } from '../../data/characters';
import { builds } from '../../data/build';
import Icon from '../../components/Icon.svelte';
const dispatch = createEventDispatcher();
const promoted = ['kaedehara_kazuha', 'shikanoin_heizou'];
export let builds;
const promoted = Object.keys(builds);
let current = 0;
async function change(index) {

View file

@ -1,12 +1,11 @@
<script context="module">
import { builds as buildsJson } from '../../data/build';
import artifactData from '../../data/artifacts/en.json';
import weaponData from '../../data/weapons/en.json';
export async function load({ params }) {
export async function load({ params, fetch }) {
const { id } = params;
const data = await import(`../../data/characterData/${id}.json`);
const buildData = buildsJson[id];
const buildData = await (await fetch(`/characters/build/${id}.json`)).json();
return { props: { id, data, buildData } };
}

View file

@ -0,0 +1,11 @@
import { builds } from '../../../data/build';
/** @type {import('./__types/items').RequestHandler} */
export async function GET({ params }) {
const { id } = params;
const build = builds[id];
return {
body: build,
};
}

View file

@ -1,3 +1,19 @@
<script context="module">
export async function load({ fetch }) {
const promoted = ['kaedehara_kazuha', 'shikanoin_heizou'];
const builds = {};
for (const p of promoted) {
const response = await fetch(`/characters/build/${p}.json`);
const b = await response.json();
builds[p] = b;
}
return {
props: { builds },
};
}
</script>
<script>
import { onMount } from 'svelte';
import debounce from 'lodash.debounce';
@ -19,6 +35,8 @@
import Build from './_index/build.svelte';
import Ad from '../components/Ad.svelte';
export let builds;
let refreshLayout;
let isMobile = false;
@ -64,7 +82,7 @@
<Ad type="mobile" variant="mpu" id="1" />
</div>
{/if}
<Build on:done={onDone} />
<Build on:done={onDone} {builds} />
<Event on:done={onDone} />
<Item on:done={onDone} />
<Discord on:done={onDone} />