diff --git a/composables/useLocalizedData.ts b/composables/useLocalizedData.ts new file mode 100644 index 0000000..f438629 --- /dev/null +++ b/composables/useLocalizedData.ts @@ -0,0 +1,12 @@ +export default async function useLocalizedData(producer: (locale: string) => Promise) { + const { currentLocale } = useLocale(); + const data = ref(await producer(currentLocale.value)); + watch(currentLocale, async () => { + data.value = await producer(currentLocale.value); + }); + + return { + currentLocale, + data + }; +} \ No newline at end of file diff --git a/pages/champions/[id].vue b/pages/champions/[id].vue index 2f873d0..a5b577e 100644 --- a/pages/champions/[id].vue +++ b/pages/champions/[id].vue @@ -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) => { diff --git a/pages/champions/index.vue b/pages/champions/index.vue index 9f93dc3..f69a101 100644 --- a/pages/champions/index.vue +++ b/pages/champions/index.vue @@ -1,17 +1,11 @@ diff --git a/pages/cherry-augments/index.vue b/pages/cherry-augments/index.vue index cfdbd26..28b65a6 100644 --- a/pages/cherry-augments/index.vue +++ b/pages/cherry-augments/index.vue @@ -1,14 +1,9 @@ diff --git a/pages/companions/index.vue b/pages/companions/index.vue index a494140..ef1234c 100644 --- a/pages/companions/index.vue +++ b/pages/companions/index.vue @@ -1,13 +1,8 @@ diff --git a/pages/loots/index.vue b/pages/loots/index.vue index 6dc269c..34f5d12 100644 --- a/pages/loots/index.vue +++ b/pages/loots/index.vue @@ -1,25 +1,22 @@