fix: lint issues

This commit is contained in:
Calum H. authored and Alejandro González committed 2025-06-14 17:45:05 +02:00
1 parent b3bc3a8731
commit 187e892c18
12 files changed
+319 -213

No files matched your search

@@ -44,7 +44,13 @@
</div>
<div v-else class="logged-out account">
<h4>Not signed in</h4>
<Button v-tooltip="'Log in'" :disabled="loginDisabled" icon-only color="primary" @click="login()">
<Button
v-tooltip="'Log in'"
:disabled="loginDisabled"
icon-only
color="primary"
@click="login()"
>
<LogInIcon v-if="!loginDisabled" />
<SpinnerIcon v-else class="animate-spin" />
</Button>
@@ -95,7 +101,7 @@ defineProps({
const emit = defineEmits(['change'])
const accounts = ref({})
const loginDisabled = ref(false);
const loginDisabled = ref(false)
const defaultUser = ref()
async function refreshValues() {
@@ -104,13 +110,13 @@ async function refreshValues() {
}
function setLoginDisabled(value) {
loginDisabled.value = value;
loginDisabled.value = value
}
defineExpose({
refreshValues,
setLoginDisabled,
loginDisabled
loginDisabled,
})
await refreshValues()
@@ -129,7 +135,7 @@ async function setAccount(account) {
}
async function login() {
loginDisabled.value = true;
loginDisabled.value = true
const loggedIn = await login_flow().catch(handleSevereError)
if (loggedIn) {
@@ -138,7 +144,7 @@ async function login() {
}
trackEvent('AccountLogIn')
loginDisabled.value = false;
loginDisabled.value = false
}
const logout = async (id) => {
@@ -16,7 +16,8 @@
:variant="variant"
:texture-src="previewSkin"
:cape-src="selectedCapeTexture"
:scale="1.4" :fov="50"
:scale="1.4"
:fov="50"
:initial-rotation="Math.PI / 8"
class="h-full w-full"
/>
@@ -26,14 +27,12 @@
<div class="flex flex-col gap-4 w-full min-h-[20rem]">
<section>
<h2 class="text-base font-semibold mb-2">Texture</h2>
<Button @click="openUploadSkinModal">
<UploadIcon /> Replace texture
</Button>
<Button @click="openUploadSkinModal"> <UploadIcon /> Replace texture </Button>
</section>
<section>
<h2 class="text-base font-semibold mb-2">Arm style</h2>
<RadioButtons v-model="variant" :items="['CLASSIC','SLIM']">
<RadioButtons v-model="variant" :items="['CLASSIC', 'SLIM']">
<template #default="{ item }">
{{ item === 'CLASSIC' ? 'Wide' : 'Slim' }}
</template>
@@ -69,7 +68,7 @@
tooltip="View more capes"
@mouseup="openSelectCapeModal"
>
<template #icon><ChevronRightIcon/></template>
<template #icon><ChevronRightIcon /></template>
<span>More</span>
</CapeLikeTextButton>
</div>
@@ -84,41 +83,49 @@
{{ mode === 'new' ? 'Add skin' : 'Save skin' }}
</Button>
</ButtonStyled>
<Button @click="hide"><XIcon/>Cancel</Button>
<Button @click="hide"><XIcon />Cancel</Button>
</div>
</NewModal>
<SelectCapeModal ref="selectCapeModal" :capes="capes || []" @select="handleCapeSelected" @cancel="handleCapeCancel" />
<SelectCapeModal
ref="selectCapeModal"
:capes="capes || []"
@select="handleCapeSelected"
@cancel="handleCapeCancel"
/>
</template>
<script setup lang="ts">
import { ref, computed, watch, useTemplateRef } from 'vue'
import SelectCapeModal from '@/components/ui/skin/SelectCapeModal.vue'
import {
Card, FileInput, SkinPreviewRenderer,
Button, RadioButtons, CapeButton, CapeLikeTextButton, ButtonStyled,
NewModal
SkinPreviewRenderer,
Button,
RadioButtons,
CapeButton,
CapeLikeTextButton,
ButtonStyled,
NewModal,
} from '@modrinth/ui'
import {
add_and_equip_custom_skin,
remove_custom_skin,
unequip_skin,
type Skin, type Cape, type SkinModel
type Skin,
type Cape,
type SkinModel,
} from '@/helpers/skins.ts'
import { handleError } from '@/store/notifications'
import {
UploadIcon,
CheckIcon, SaveIcon, XIcon, TrashIcon, ChevronRightIcon
} from '@modrinth/assets'
import { UploadIcon, CheckIcon, SaveIcon, XIcon, ChevronRightIcon } from '@modrinth/assets'
const modal = useTemplateRef('modal')
const selectCapeModal = useTemplateRef('selectCapeModal')
const mode = ref<'new'|'edit'>('new')
const currentSkin = ref<Skin|null>(null)
const mode = ref<'new' | 'edit'>('new')
const currentSkin = ref<Skin | null>(null)
const shouldRestoreModal = ref(false)
const fileUploadTextureBlob = ref<Uint8Array|null>(null)
const fileName = ref<string|null>(null)
const fileUploadTextureBlob = ref<Uint8Array | null>(null)
const fileName = ref<string | null>(null)
watch(fileUploadTextureBlob, () => {
if (fileName.value === null && fileUploadTextureBlob.value) {
fileName.value = 'New upload'
@@ -126,7 +133,7 @@ watch(fileUploadTextureBlob, () => {
})
const variant = ref<SkinModel>('CLASSIC')
const selectedCape = ref<Cape|undefined>(undefined)
const selectedCape = ref<Cape | undefined>(undefined)
const props = defineProps<{ capes?: Cape[] }>()
const selectedCapeTexture = computed(() => selectedCape.value?.texture)
@@ -134,11 +141,11 @@ const visibleCapeList = ref<Cape[]>([])
const sortedCapes = computed(() => {
return [...(props.capes || [])].sort((a, b) => {
const nameA = (a.name || '').toLowerCase();
const nameB = (b.name || '').toLowerCase();
return nameA.localeCompare(nameB);
});
});
const nameA = (a.name || '').toLowerCase()
const nameB = (b.name || '').toLowerCase()
return nameA.localeCompare(nameB)
})
})
function initVisibleCapeList() {
if (!props.capes || props.capes.length === 0) {
@@ -163,10 +170,10 @@ function getSortedCapes(count: number): Cape[] {
function getSortedCapeExcluding(excludeId: string): Cape | undefined {
if (!sortedCapes.value || sortedCapes.value.length <= 1) return undefined
return sortedCapes.value.find(cape => cape.id !== excludeId)
return sortedCapes.value.find((cape) => cape.id !== excludeId)
}
const localPreviewUrl = ref<string|null>(null)
const localPreviewUrl = ref<string | null>(null)
watch(fileUploadTextureBlob, (blob, prev) => {
if (prev && localPreviewUrl.value) URL.revokeObjectURL(localPreviewUrl.value)
if (blob) localPreviewUrl.value = URL.createObjectURL(new Blob([blob]))
@@ -179,24 +186,25 @@ const previewSkin = computed(() => {
})
const hasEdits = computed(() => {
if (mode.value !== 'edit') return true;
if (fileUploadTextureBlob.value) return true;
if (!currentSkin.value) return false;
if (variant.value !== currentSkin.value.variant) return true;
if ((selectedCape.value?.id || null) !== (currentSkin.value.cape_id || null)) return true;
return false;
});
if (mode.value !== 'edit') return true
if (fileUploadTextureBlob.value) return true
if (!currentSkin.value) return false
if (variant.value !== currentSkin.value.variant) return true
if ((selectedCape.value?.id || null) !== (currentSkin.value.cape_id || null)) return true
return false
})
const disableSave = computed(() =>
(mode.value === 'new' && !fileUploadTextureBlob.value) ||
(mode.value === 'edit' && !hasEdits.value)
);
const disableSave = computed(
() =>
(mode.value === 'new' && !fileUploadTextureBlob.value) ||
(mode.value === 'edit' && !hasEdits.value),
)
const saveTooltip = computed(() => {
if (mode.value === 'new' && !fileUploadTextureBlob.value) return 'Upload a skin first!';
if (mode.value === 'edit' && !hasEdits.value) return 'Make an edit to the skin first!';
return undefined;
});
if (mode.value === 'new' && !fileUploadTextureBlob.value) return 'Upload a skin first!'
if (mode.value === 'edit' && !hasEdits.value) return 'Make an edit to the skin first!'
return undefined
})
function resetState() {
mode.value = 'new'
@@ -218,7 +226,7 @@ function show(e: MouseEvent, skin?: Skin) {
currentSkin.value = skin ?? null
if (skin) {
variant.value = skin.variant
selectedCape.value = props.capes?.find(c=>c.id===skin.cape_id)
selectedCape.value = props.capes?.find((c) => c.id === skin.cape_id)
} else {
variant.value = 'CLASSIC'
selectedCape.value = undefined
@@ -243,7 +251,7 @@ function showNew(e: MouseEvent, skinTexture: Uint8Array, filename: string) {
function restoreWithNewTexture(skinTexture: Uint8Array, filename: string) {
fileUploadTextureBlob.value = skinTexture
fileName.value = filename
if (shouldRestoreModal.value) {
setTimeout(() => {
modal.value?.show()
@@ -257,12 +265,12 @@ function hide() {
setTimeout(() => resetState(), 250)
}
function selectCape(cape: Cape|undefined) {
function selectCape(cape: Cape | undefined) {
if (cape && selectedCape.value?.id !== cape.id) {
const isInVisibleList = visibleCapeList.value.some(c => c.id === cape.id)
const isInVisibleList = visibleCapeList.value.some((c) => c.id === cape.id)
if (!isInVisibleList && visibleCapeList.value.length > 0) {
visibleCapeList.value.splice(0, 1, cape)
if (visibleCapeList.value.length > 1 && visibleCapeList.value[1].id === cape.id) {
const otherCape = getSortedCapeExcluding(cape.id)
if (otherCape) {
@@ -306,7 +314,7 @@ function openSelectCapeModal(e: MouseEvent) {
currentSkin.value?.texture_key,
selectedCape.value,
previewSkin.value,
variant.value
variant.value,
)
}, 0)
}
@@ -329,7 +337,7 @@ async function save() {
blob = new Uint8Array(buf)
}
await unequip_skin();
await unequip_skin()
if (mode.value === 'new') {
await add_and_equip_custom_skin(blob, variant.value, selectedCape.value)
@@ -346,9 +354,13 @@ async function save() {
}
}
watch(() => props.capes, () => {
initVisibleCapeList()
}, { immediate: true })
watch(
() => props.capes,
() => {
initVisibleCapeList()
},
{ immediate: true },
)
const emit = defineEmits<{
(event: 'saved'): void
@@ -361,6 +373,6 @@ defineExpose({
showNew,
restoreWithNewTexture,
hide,
shouldRestoreModal
shouldRestoreModal,
})
</script>
@@ -7,7 +7,7 @@ import {
CapeButton,
CapeLikeTextButton,
SkinPreviewRenderer,
NewModal
NewModal,
} from '@modrinth/ui'
import { CheckIcon, XIcon } from '@modrinth/assets'
@@ -24,11 +24,11 @@ const props = defineProps<{
const sortedCapes = computed(() => {
return [...props.capes].sort((a, b) => {
const nameA = (a.name || '').toLowerCase();
const nameB = (b.name || '').toLowerCase();
return nameA.localeCompare(nameB);
});
});
const nameA = (a.name || '').toLowerCase()
const nameB = (b.name || '').toLowerCase()
return nameA.localeCompare(nameB)
})
})
const currentSkinId = ref<string | undefined>()
const currentSkinTexture = ref<string | undefined>()
@@ -93,7 +93,7 @@ defineExpose({
:variant="currentSkinVariant"
:scale="1.4"
:fov="50"
:initial-rotation="Math.PI + (Math.PI / 8)"
:initial-rotation="Math.PI + Math.PI / 8"
class="h-full w-full"
/>
</div>
@@ -1,9 +1,7 @@
<template>
<NewModal ref="modal" @on-hide="hide(true)">
<template #title>
<span class="text-lg font-extrabold text-contrast">
Upload skin texture
</span>
<span class="text-lg font-extrabold text-contrast"> Upload skin texture </span>
</template>
<div class="relative">
<div
@@ -12,10 +10,22 @@
@drop.prevent="handleFileOperation"
@dragover.prevent
>
<p class="mx-auto mb-0 text-primary text-xl text-center flex items-center gap-2"><UploadIcon /> Select skin texture file</p>
<p class="mx-auto mt-0 text-secondary text-sm text-center">Drag and drop or click here to browse</p>
<p class="mx-auto mt-0 text-secondary text-xs text-center">Only 64x64 PNG files are accepted</p>
<input ref="fileInput" type="file" accept="image/png" class="hidden" @change="handleFileOperation" />
<p class="mx-auto mb-0 text-primary text-xl text-center flex items-center gap-2">
<UploadIcon /> Select skin texture file
</p>
<p class="mx-auto mt-0 text-secondary text-sm text-center">
Drag and drop or click here to browse
</p>
<p class="mx-auto mt-0 text-secondary text-xs text-center">
Only 64x64 PNG files are accepted
</p>
<input
ref="fileInput"
type="file"
accept="image/png"
class="hidden"
@change="handleFileOperation"
/>
</div>
</div>
</NewModal>
@@ -24,7 +34,7 @@
<script setup lang="ts">
import { ref } from 'vue'
import { UploadIcon } from '@modrinth/assets'
import { useNotifications } from "@/store/state"
import { useNotifications } from '@/store/state'
import { NewModal } from '@modrinth/ui'
const notifications = useNotifications()
@@ -71,30 +81,30 @@ async function validateImageDimensions(file: File): Promise<boolean> {
async function handleFileOperation(e: Event | DragEvent) {
// Get files from either drag event or file input
const files = (e as DragEvent).dataTransfer?.files || (e.target as HTMLInputElement).files;
const files = (e as DragEvent).dataTransfer?.files || (e.target as HTMLInputElement).files
if (!files || files.length === 0) {
return;
return
}
const file = files[0];
const file = files[0]
if (file.type !== 'image/png') {
notifications.addNotification({
title: 'Invalid file type.',
text: 'Only PNG files are accepted.',
type: 'error',
});
return;
})
return
}
const isValidDimensions = await validateImageDimensions(file);
const isValidDimensions = await validateImageDimensions(file)
if (!isValidDimensions) {
notifications.addNotification({
title: 'Invalid dimensions.',
text: 'Only 64x64 PNG files are accepted.',
type: 'error',
});
return;
})
return
}
emit('uploaded', file);
hide();
emit('uploaded', file)
hide()
}
defineExpose({ show, hide })