Merge pull request #905 from rommapp/refactor/img-load

Refactor images load
This commit is contained in:
Zurdi
2024-05-31 16:32:31 +02:00
committed by GitHub
11 changed files with 115 additions and 102 deletions

View File

@@ -87,12 +87,8 @@ const theme = useTheme();
? `https:${dlc.cover_url.replace('t_thumb', 't_cover_big')}`
: `/assets/default/cover/big_${theme.global.name.value}_missing_cover.png`
"
:lazy-src="
`${dlc.cover_url}`
? `https:${dlc.cover_url.replace('t_thumb', 't_cover_small')}`
: `/assets/default/cover/small_${theme.global.name.value}_missing_cover.png`
"
:aspect-ratio="3 / 4"
lazy
><v-chip
class="px-2 position-absolute chip-type text-white translucent"
density="compact"

View File

@@ -4,17 +4,36 @@ import { useTheme } from "vuetify";
const theme = useTheme();
const props = defineProps<{ rom: DetailedRom }>();
const imgSrc =
!props.rom.igdb_id && !props.rom.moby_id && !props.rom.has_cover
? `/assets/default/cover/big_${theme.global.name.value}_unmatched.png`
: !props.rom.has_cover
? `/assets/default/cover/big_${theme.global.name.value}_missing_cover.png`
: `/assets/romm/resources/${props.rom.path_cover_s}`;
</script>
<template>
<v-card rounded="0">
<v-img :src="imgSrc" id="background-header" />
<v-img
:src="
!rom.igdb_id && !rom.moby_id
? `/assets/default/cover/big_${theme.global.name.value}_unmatched.png`
: `/assets/romm/resources/${rom.path_cover_l}`
"
id="background-header"
lazy
>
<template v-slot:error>
<v-img
:src="`/assets/default/cover/big_${theme.global.name.value}_missing_cover.png`"
:aspect-ratio="3 / 4"
></v-img>
</template>
<template v-slot:placeholder>
<div class="d-flex align-center justify-center fill-height">
<v-progress-circular
:width="2"
:size="40"
color="romm-accent-1"
indeterminate
/>
</div>
</template>
</v-img>
</v-card>
</template>
<style scoped>

View File

@@ -1,28 +1,41 @@
<script setup lang="ts">
import storeDownload from "@/stores/download";
import { type SimpleRom } from "@/stores/roms";
defineProps<{ romId: number; src: string; lazySrc: string }>();
defineProps<{ rom: SimpleRom }>();
const downloadStore = storeDownload();
import { useTheme } from "vuetify";
const theme = useTheme();
</script>
<template>
<v-card
elevation="2"
:loading="downloadStore.value.includes(romId) ? 'romm-accent-1' : false"
:loading="downloadStore.value.includes(rom.id) ? 'romm-accent-1' : false"
>
<v-img
:value="romId"
:key="romId"
:src="src"
:lazy-src="lazySrc"
:value="rom.id"
:key="rom.id"
:src="
!rom.igdb_id && !rom.moby_id
? `/assets/default/cover/big_${theme.global.name.value}_unmatched.png`
: `/assets/romm/resources/${rom.path_cover_l}`
"
:aspect-ratio="3 / 4"
lazy
>
<slot name="editable"></slot>
<template v-slot:error>
<v-img
:src="`/assets/default/cover/big_${theme.global.name.value}_missing_cover.png`"
:aspect-ratio="3 / 4"
></v-img>
</template>
<template v-slot:placeholder>
<div class="d-flex align-center justify-center fill-height">
<v-progress-circular
color="romm-accent-1"
:width="2"
:size="20"
:size="40"
color="romm-accent-1"
indeterminate
/>
</div>

View File

@@ -39,12 +39,8 @@ const theme = useTheme();
? `https:${game.cover_url.replace('t_thumb', 't_cover_big')}`
: `/assets/default/cover/big_${theme.global.name.value}_missing_cover.png`
"
:lazy-src="
`${game.cover_url}`
? `https:${game.cover_url.replace('t_thumb', 't_cover_small')}`
: `/assets/default/cover/small_${theme.global.name.value}_missing_cover.png`
"
:aspect-ratio="3 / 4"
lazy
><v-chip
class="px-2 position-absolute chip-type text-white translucent"
density="compact"

View File

@@ -179,25 +179,7 @@ function closeDialog() {
<v-col cols="12" md="4" lg="3">
<cover
:class="{ 'mx-16': smAndDown, 'ml-2': md, 'my-4': smAndDown }"
:romId="rom.id"
:src="
imagePreviewUrl
? imagePreviewUrl
: !rom.igdb_id && !rom.moby_id && !rom.has_cover
? `/assets/default/cover/big_${theme.global.name.value}_unmatched.png`
: !rom.has_cover
? `/assets/default/cover/big_${theme.global.name.value}_missing_cover.png`
: `/assets/romm/resources/${rom.path_cover_l}`
"
:lazy-src="
imagePreviewUrl
? imagePreviewUrl
: !rom.igdb_id && !rom.moby_id && !rom.has_cover
? `/assets/default/cover/small_${theme.global.name.value}_unmatched.png`
: !rom.has_cover
? `/assets/default/cover/small_${theme.global.name.value}_missing_cover.png`
: `/assets/romm/resources/${rom.path_cover_s}`
"
:rom="rom"
>
<template v-slot:editable>
<v-chip-group class="position-absolute edit-cover pa-0">

View File

@@ -358,13 +358,6 @@ onBeforeUnmount(() => {
? matchedRom.igdb_url_cover
: matchedRom.moby_url_cover
"
:lazy-src="
!matchedRom.igdb_url_cover && !matchedRom.moby_url_cover
? `/assets/default/cover/small_${theme.global.name.value}_missing_cover.png`
: matchedRom.igdb_url_cover
? matchedRom.igdb_url_cover
: matchedRom.moby_url_cover
"
:aspect-ratio="3 / 4"
>
<template v-slot:placeholder>

View File

@@ -1,5 +1,4 @@
<script setup lang="ts">
import type { SearchRomSchema } from "@/__generated__";
import type { Events } from "@/types/emitter";
import type { Emitter } from "mitt";
@@ -59,7 +58,7 @@ function closeDialog() {
<v-row class="justify-center" no-gutters>
<v-col
class="pa-2"
:class="{'cover':!xs, 'cover-xs': xs}"
:class="{ cover: !xs, 'cover-xs': xs }"
v-for="source in sources"
>
<v-hover v-slot="{ isHovering, props }">
@@ -76,12 +75,8 @@ function closeDialog() {
? `/assets/default/cover/big_${theme.global.name.value}_missing_cover.png`
: source.url_cover
"
:lazy-src="
!source.url_cover
? `/assets/default/cover/small_${theme.global.name.value}_missing_cover.png`
: source.url_cover
"
:aspect-ratio="3 / 4"
lazy
>
<template v-slot:placeholder>
<div class="d-flex align-center justify-center fill-height">

View File

@@ -249,28 +249,27 @@ onBeforeUnmount(() => {
<v-img
v-bind="props"
:src="
!rom.igdb_id && !rom.moby_id && !rom.has_cover
!rom.igdb_id && !rom.moby_id
? `/assets/default/cover/big_${theme.global.name.value}_unmatched.png`
: !rom.has_cover
? `/assets/default/cover/big_${theme.global.name.value}_missing_cover.png`
: `/assets/romm/resources/${rom.path_cover_l}`
"
:lazy-src="
!rom.igdb_id && !rom.moby_id && !rom.has_cover
? `/assets/default/cover/small_${theme.global.name.value}_unmatched.png`
: !rom.has_cover
? `/assets/default/cover/small_${theme.global.name.value}_missing_cover.png`
: `/assets/romm/resources/${rom.path_cover_s}`
"
:aspect-ratio="3 / 4"
lazy
>
<template v-slot:error>
<v-img
:src="`/assets/default/cover/big_${theme.global.name.value}_missing_cover.png`"
:aspect-ratio="3 / 4"
></v-img>
</template>
<template v-slot:placeholder>
<div
class="d-flex align-center justify-center fill-height"
>
<v-progress-circular
color="romm-accent-1"
:width="2"
:size="40"
color="romm-accent-1"
indeterminate
/>
</div>

View File

@@ -95,18 +95,22 @@ onUnmounted(() => {
absolute
/>
<v-hover v-slot="{ isHovering, props }" open-delay="800">
<lazy-image
<v-img
:value="rom.id"
:key="rom.id"
v-bind="props"
:placeholder="`/assets/default/cover/big_${theme.global.name.value}_missing_cover.png`"
:src="
!rom.igdb_id && !rom.moby_id && !rom.has_cover
!rom.igdb_id && !rom.moby_id
? `/assets/default/cover/big_${theme.global.name.value}_unmatched.png`
: !rom.has_cover
? `/assets/default/cover/big_${theme.global.name.value}_missing_cover.png`
: `/assets/romm/resources/${rom.path_cover_l}`
"
style="aspect-ratio: 3 / 4; width: 100%"
:lazy-src="
!rom.igdb_id && !rom.moby_id
? `/assets/default/cover/big_${theme.global.name.value}_unmatched.png`
: `/assets/romm/resources/${rom.path_cover_s}`
"
:aspect-ratio="3 / 4"
>
<div v-bind="props" style="position: absolute; top: 0; width: 100%">
<v-expand-transition>
@@ -153,7 +157,23 @@ onUnmounted(() => {
</v-chip>
</v-row>
</div>
</lazy-image>
<template v-slot:error>
<v-img
:src="`/assets/default/cover/big_${theme.global.name.value}_missing_cover.png`"
:aspect-ratio="3 / 4"
></v-img>
</template>
<template v-slot:placeholder>
<div class="d-flex align-center justify-center fill-height">
<v-progress-circular
:width="2"
:size="40"
color="romm-accent-1"
indeterminate
/>
</div>
</template>
</v-img>
</v-hover>
</router-link>
</template>

View File

@@ -121,16 +121,34 @@ onMounted(() => {
:indeterminate="true"
absolute
/>
<img
<v-img
:src="
!item.igdb_id && !item.has_cover
? `/assets/default/cover/small_${theme.global.name.value}_unmatched.png`
: !item.has_cover
? `/assets/default/cover/small_${theme.global.name.value}_missing_cover.png`
!item.igdb_id && !item.moby_id
? `/assets/default/cover/big_${theme.global.name.value}_unmatched.png`
: `/assets/romm/resources/${item.path_cover_l}`
"
:lazy-src="
!item.igdb_id && !item.moby_id
? `/assets/default/cover/big_${theme.global.name.value}_unmatched.png`
: `/assets/romm/resources/${item.path_cover_s}`
"
min-height="150"
/>
>
<template v-slot:error>
<v-img
:src="`/assets/default/cover/big_${theme.global.name.value}_missing_cover.png`"
></v-img>
</template>
<template v-slot:placeholder>
<div class="d-flex align-center justify-center fill-height">
<v-progress-circular
:width="2"
:size="20"
color="romm-accent-1"
indeterminate
/>
</div>
</template>
</v-img>
</v-avatar>
</template>
<template v-slot:item.name="{ item }">

View File

@@ -19,7 +19,7 @@ import type { Events } from "@/types/emitter";
import type { Emitter } from "mitt";
import { inject, onBeforeMount, ref, watch } from "vue";
import { useRoute } from "vue-router";
import { useDisplay, useTheme } from "vuetify";
import { useDisplay } from "vuetify";
const route = useRoute();
const rom = ref<DetailedRom>();
@@ -34,7 +34,6 @@ const tab = ref<
| "relatedgames"
| "emulation"
>("details");
const theme = useTheme();
const { smAndDown, mdAndDown, mdAndUp, lgAndUp } = useDisplay();
const emitter = inject<Emitter<Events>>("emitter");
const showEmulation = ref(false);
@@ -53,7 +52,6 @@ async function fetchDetails() {
rom.value = response.data;
})
.catch((error) => {
console.log(error);
emitter?.emit("snackbarShow", {
msg: error.response.data.detail,
@@ -121,23 +119,7 @@ watch(
'cover-xs': smAndDown,
}"
>
<cover
:romId="rom.id"
:src="
!rom.igdb_id && !rom.moby_id && !rom.has_cover
? `/assets/default/cover/big_${theme.global.name.value}_unmatched.png`
: !rom.has_cover
? `/assets/default/cover/big_${theme.global.name.value}_missing_cover.png`
: `/assets/romm/resources/${rom.path_cover_l}`
"
:lazy-src="
!rom.igdb_id && !rom.moby_id && !rom.has_cover
? `/assets/default/cover/small_${theme.global.name.value}_unmatched.png`
: !rom.has_cover
? `/assets/default/cover/small_${theme.global.name.value}_missing_cover.png`
: `/assets/romm/resources/${rom.path_cover_s}`
"
/>
<cover :rom="rom" />
<action-bar class="mt-2" :rom="rom" />
<related-games class="mt-3 px-2" v-if="mdAndUp" :rom="rom" />
</v-col>