Merge pull request #885 from rommapp/gallery-view-perf

Gallery view performance
This commit is contained in:
Georges-Antoine Assi
2024-05-26 17:57:27 -04:00
committed by GitHub
8 changed files with 119 additions and 41 deletions

View File

@@ -3,6 +3,7 @@
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<link rel="preconnect" href="https://fonts.gstatic.com" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>RomM</title>
</head>

View File

@@ -10,7 +10,7 @@ const emitter = inject<Emitter<Events>>("emitter");
<template>
<v-btn @click="emitter?.emit('toggleDrawer', null)" rounded="0" icon>
<v-avatar rounded="0">
<v-img src="/assets/isotipo.svg" />
<img src="/assets/isotipo.svg" />
</v-avatar>
</v-btn>
</template>

View File

@@ -41,23 +41,16 @@ const theme = useTheme();
)}`
: `/assets/default/cover/big_${theme.global.name.value}_missing_cover.png`
"
:lazy-src="
`${expansion.cover_url}`
? `https:${expansion.cover_url.replace(
't_thumb',
't_cover_big'
)}`
: `/assets/default/cover/big_${theme.global.name.value}_missing_cover.png`
"
:aspect-ratio="3 / 4"
><v-chip
>
<v-chip
class="px-2 position-absolute chip-type text-white translucent"
density="compact"
label
>
<span>expansion</span>
</v-chip></v-img
>
</v-chip>
</v-img>
</v-card>
</a>
</v-col>

View File

@@ -10,17 +10,11 @@ const imgSrc =
: !props.rom.has_cover
? `/assets/default/cover/big_${theme.global.name.value}_missing_cover.png`
: `/assets/romm/resources/${props.rom.path_cover_s}`;
const imgSrcLazy =
!props.rom.igdb_id && !props.rom.moby_id && !props.rom.has_cover
? `/assets/default/cover/small_${theme.global.name.value}_unmatched.png`
: !props.rom.has_cover
? `/assets/default/cover/small_${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" :lazy-src="imgSrcLazy" id="background-header" />
<v-img :src="imgSrc" id="background-header" />
</v-card>
</template>
<style scoped>

View File

@@ -82,8 +82,7 @@ function onTouchEnd() {
absolute
/>
<v-hover v-slot="{ isHovering, props }" open-delay="800">
<v-img
:value="rom.id"
<img
:key="rom.id"
v-bind="props"
:src="
@@ -93,24 +92,8 @@ function onTouchEnd() {
? `/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"
style="aspect-ratio: 3 / 4; width: 100%"
>
<template v-slot:placeholder>
<div class="d-flex align-center justify-center fill-height">
<v-progress-circular
color="romm-accent-1"
:width="2"
indeterminate
/>
</div>
</template>
<v-expand-transition>
<div
v-if="isHovering || !rom.has_cover"
@@ -118,6 +101,7 @@ function onTouchEnd() {
:class="{
'text-truncate': galleryViewStore.current == 0 && !isHovering,
}"
style="position: absolute; top: 0; width: 100%;"
>
<v-list-item>{{ rom.name }}</v-list-item>
</div>
@@ -154,7 +138,7 @@ function onTouchEnd() {
+{{ rom.siblings.length }}
</v-chip>
</v-row>
</v-img>
</img>
</v-hover>
</router-link>
</template>

View File

@@ -0,0 +1,98 @@
<script setup lang="ts">
import {
reactive,
computed,
ref,
onMounted,
onBeforeUnmount,
useAttrs,
} from "vue";
const props = defineProps<{
src: string;
placeholder: string;
srcset?: string;
intersectionOptions?: IntersectionObserverInit;
usePicture?: boolean;
}>();
const emit = defineEmits(["load", "error", "intersect"]);
const attrs = useAttrs();
const root = ref<HTMLPictureElement | HTMLImageElement | null>(null);
const state = reactive<{
observer: IntersectionObserver | null;
intersected: boolean;
loaded: boolean;
}>({
observer: null,
intersected: false,
loaded: false,
});
const srcImage = computed(() =>
state.intersected && props.src ? props.src : props.placeholder
);
const srcsetImage = computed(() =>
state.intersected && props.srcset ? props.srcset : ""
);
const load = () => {
if (root.value && root.value.getAttribute("src") !== props.placeholder) {
state.loaded = true;
emit("load", root.value);
}
};
const error = () => emit("error", root.value);
// Hooks
onMounted(() => {
if ("IntersectionObserver" in window) {
state.observer = new IntersectionObserver((entries) => {
const image = entries[0];
if (image.isIntersecting) {
state.intersected = true;
state.observer?.disconnect();
emit("intersect");
}
}, props.intersectionOptions ?? {});
if (root.value) state.observer.observe(root.value);
}
});
onBeforeUnmount(() => {
if ("IntersectionObserver" in window && state.observer) {
state.observer.disconnect();
}
});
</script>
<template>
<picture v-if="usePicture" ref="root" @load="load">
<slot v-if="state.intersected"></slot>
<img
v-else
:src="srcImage"
:srcSet="srcsetImage"
v-bind="attrs"
:class="[attrs.class, 'v-responsive v-img v-lazy-image', { 'v-lazy-image-loaded': state.loaded }]"
@load="load"
@error="error"
>
<slot />
</img>
</picture>
<img
v-else
ref="root"
:src="srcImage"
:srcSet="srcsetImage"
v-bind="attrs"
:class="[attrs.class, 'v-responsive v-img v-lazy-image', { 'v-lazy-image-loaded': state.loaded }]"
@load="load"
@error="error"
>
<slot />
</img>
</template>

View File

@@ -1,5 +1,6 @@
import { defineStore } from "pinia";
import type { PlatformSchema } from "@/__generated__";
import { uniqBy } from "lodash";
export type Platform = PlatformSchema;
@@ -15,11 +16,18 @@ export default defineStore("platforms", {
filledPlatforms: ({ value }) => value.filter((p) => p.rom_count > 0),
},
actions: {
_reorder() {
this.value = this.value.sort((a, b) => {
return a.name.localeCompare(b.name);
});
this.value = uniqBy(this.value, "id");
},
set(platforms: Platform[]) {
this.value = platforms;
},
add(platform: Platform) {
this.value.push(platform)
this._reorder()
},
exists(platform: Platform) {
return this.value.filter(p => p.fs_slug == platform.fs_slug).length > 0

View File

@@ -250,7 +250,7 @@ onBeforeRouteUpdate(async (to, _) => {
<!-- Gallery cards view -->
<v-col
class="pa-1"
v-show="galleryViewStore.current != 2"
v-if="galleryViewStore.current != 2"
:cols="views[galleryViewStore.current]['size-cols']"
:xs="views[galleryViewStore.current]['size-xs']"
:sm="views[galleryViewStore.current]['size-sm']"
@@ -270,7 +270,7 @@ onBeforeRouteUpdate(async (to, _) => {
</v-col>
<!-- Gallery list view -->
<v-col v-show="galleryViewStore.current == 2">
<v-col v-if="galleryViewStore.current == 2">
<game-data-table />
</v-col>
</v-row>