Refactor into useLocalizedData

This commit is contained in:
BlossomiShymae
2024-10-14 19:02:06 -05:00
parent 793cd3e120
commit e956f7f6d1
15 changed files with 43 additions and 103 deletions

View File

@@ -5,14 +5,9 @@ const route = useRoute();
const id = route.params.id as unknown;
const { client } = useClient();
const { currentLocale } = useLocale();
const getChampion = async () => await client.champions.getAsync(id as number, {locale: currentLocale.value, version: "latest"});
const { currentLocale, data: champion } = await useLocalizedData(async (x) => await client.champions.getAsync(id as number, {locale: x, version: "latest"}));
const champion = ref(await getChampion());
const data = computed(() => `https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/v1/champions/${champion.value.id}.json`);
watch(currentLocale, async () => {
champion.value = await getChampion();
});
const currentSkin = ref(champion.value.skins[0]);
const swapCurrentSkin = (id: number) => {

View File

@@ -1,17 +1,11 @@
<script setup lang="ts">
const { client } = useClient();
const { currentLocale } = useLocale();
const getSummaries = async () => (await client.championSummaries.listAsync({locale: currentLocale.value, version: "latest"}))
.filter((x) => x.id != -1) // Remove placeholder champion
.sort((a, b) => a.name.localeCompare(b.name));
const getSkins = async () => await client.skins.listAsync({locale: currentLocale.value, version: "latest"});
const summaries = ref(await getSummaries());
const skins = ref(await getSkins());
watch(currentLocale, async () => {
summaries.value = await getSummaries();
skins.value = await getSkins();
});
const { data: summaries } = await useLocalizedData(async (x) => (await client.championSummaries.listAsync({locale: x, version: "latest"}))
.filter((x) => x.id != -1) // Remove placeholder champion
.sort((a, b) => a.name.localeCompare(b.name)));
const { data: skins } = await useLocalizedData(async (x) => await client.skins.listAsync({locale: x, version: "latest"}));
const { query, results } = useQueryable(summaries, (x) => x.id, (x) => x.name);
</script>