diff --git a/apps/app-frontend/src/pages/Skins.vue b/apps/app-frontend/src/pages/Skins.vue index d1d5dab8b..4cb6ba333 100644 --- a/apps/app-frontend/src/pages/Skins.vue +++ b/apps/app-frontend/src/pages/Skins.vue @@ -8,7 +8,7 @@ import { Button } from '@modrinth/ui' import type { Ref} from 'vue'; -import {ref, computed, useTemplateRef, watch, onMounted, onUnmounted, inject} from 'vue' +import {ref, computed, useTemplateRef, watch, onMounted, onUnmounted, inject, nextTick} from 'vue' import EditSkinModal from '@/components/ui/skin/EditSkinModal.vue' import SelectCapeModal from '@/components/ui/skin/SelectCapeModal.vue' import { handleError } from '@/store/notifications' @@ -41,7 +41,6 @@ const loginInProgress = ref(false); const currentUser = ref(undefined) const currentUserId = ref(undefined) -// @ts-ignore const username = computed(() => currentUser.value?.profile?.name ?? undefined) const selectedSkin = ref(null) const defaultCape = ref() @@ -64,36 +63,8 @@ const capeTexture = computed(() => currentCape.value?.texture) const skinVariant = computed(() => selectedSkin.value?.variant) const skinNametag = computed(() => settings.value.hide_nametag_skins_page ? undefined : username.value) -await Promise.all([loadCapes(), loadSkins(), loadCurrentUser()]) - let userCheckInterval: number | null = null -onMounted(() => { - // TODO: Surely a better way to do this? - userCheckInterval = window.setInterval(checkUserChanges, 250) -}) - -onUnmounted(() => { - if (userCheckInterval !== null) { - window.clearInterval(userCheckInterval) - } -}) - -async function checkUserChanges() { - try { - const defaultId = await get_default_user() - if (defaultId !== currentUserId.value) { - await loadCurrentUser(); - await loadCapes(); - await loadSkins(); - } - } catch (error) { - if (currentUser.value) { - handleError(error) - } - } -} - async function loadCapes() { try { capes.value = (await get_available_capes()) ?? [] @@ -138,7 +109,6 @@ async function loadCurrentUser() { currentUserId.value = defaultId const allAccounts = await users() - // @ts-ignore currentUser.value = allAccounts.find((acc) => acc.profile.id === defaultId) } catch (e) { handleError(e) @@ -168,6 +138,33 @@ watch( () => selectedSkin.value?.cape_id, () => {} ) + +onMounted(() => { + userCheckInterval = window.setInterval(checkUserChanges, 250); +}) + +onUnmounted(() => { + if (userCheckInterval !== null) { + window.clearInterval(userCheckInterval); + } +}) + +async function checkUserChanges() { + try { + const defaultId = await get_default_user() + if (defaultId !== currentUserId.value) { + await loadCurrentUser(); + await loadCapes(); + await loadSkins(); + } + } catch (error) { + if (currentUser.value) { + handleError(error) + } + } +} + +await Promise.all([loadCapes(), loadSkins(), loadCurrentUser()])