refactor: enhance search cover dialog to accept platform aspect ratio and update related components

This commit is contained in:
zurdi
2024-12-07 16:31:51 +00:00
parent 9c7aa77991
commit cd73bfb9c8
3 changed files with 24 additions and 8 deletions

View File

@@ -2,7 +2,9 @@
import GameCard from "@/components/common/Game/Card/Base.vue";
import RDialog from "@/components/common/RDialog.vue";
import romApi, { type UpdateRom } from "@/services/api/rom";
import storeGalleryView from "@/stores/galleryView";
import storeHeartbeat from "@/stores/heartbeat";
import storePlatforms from "@/stores/platforms";
import storeRoms, { type SimpleRom } from "@/stores/roms";
import type { Events } from "@/types/emitter";
import type { Emitter } from "mitt";
@@ -20,6 +22,8 @@ const rom = ref<UpdateRom>();
const romsStore = storeRoms();
const imagePreviewUrl = ref<string | undefined>("");
const removeCover = ref(false);
const platfotmsStore = storePlatforms();
const galleryViewStore = storeGalleryView();
const emitter = inject<Emitter<Events>>("emitter");
emitter?.on("showEditRomDialog", (romToEdit: UpdateRom | undefined) => {
show.value = true;
@@ -31,6 +35,12 @@ emitter?.on("updateUrlCover", (url_cover) => {
rom.value.url_cover = url_cover;
setArtwork(url_cover);
});
const computedAspectRatio = computed(() => {
const ratio = rom.value?.platform_id
? platfotmsStore.getAspectRatio(rom.value?.platform_id)
: galleryViewStore.defaultAspectRatioCover;
return parseFloat(ratio.toString());
});
// Functions
function triggerFileInput() {
@@ -216,10 +226,10 @@ function closeDialog() {
size="small"
class="translucent-dark"
@click="
emitter?.emit(
'showSearchCoverDialog',
rom.name as string,
)
emitter?.emit('showSearchCoverDialog', {
term: rom.name as string,
platformAspectRatio: computedAspectRatio,
})
"
>
<v-icon size="large">mdi-image-search-outline</v-icon>

View File

@@ -2,11 +2,12 @@
import type { SearchCoverSchema } from "@/__generated__";
import RDialog from "@/components/common/RDialog.vue";
import sgdbApi from "@/services/api/sgdb";
import storeGalleryView from "@/stores/galleryView";
import storePlatforms from "@/stores/platforms";
import type { Events } from "@/types/emitter";
import type { Emitter } from "mitt";
import { inject, onBeforeUnmount, ref } from "vue";
import { useDisplay } from "vuetify";
import storeGalleryView from "@/stores/galleryView";
// Props
const { lgAndUp } = useDisplay();
@@ -16,12 +17,17 @@ const searchTerm = ref("");
const coverType = ref("all");
const covers = ref<SearchCoverSchema[]>([]);
const filteredCovers = ref<SearchCoverSchema[]>();
const platfotmsStore = storePlatforms();
const galleryViewStore = storeGalleryView();
const panels = ref([0]);
const emitter = inject<Emitter<Events>>("emitter");
emitter?.on("showSearchCoverDialog", (term) => {
const aspectRatio = ref(
parseFloat(galleryViewStore.defaultAspectRatioCover.toString()),
);
emitter?.on("showSearchCoverDialog", ({ term, platformAspectRatio }) => {
searchTerm.value = term;
show.value = true;
if (platformAspectRatio) aspectRatio.value = platformAspectRatio;
if (searchTerm.value) searchCovers();
});
@@ -184,7 +190,7 @@ onBeforeUnmount(() => {
:class="{ 'on-hover': isHovering }"
class="transform-scale pointer"
@click="selectCover(resource.url)"
:aspect-ratio="galleryViewStore.defaultAspectRatioCover"
:aspect-ratio="aspectRatio"
:src="resource.thumb"
cover
>

View File

@@ -20,7 +20,7 @@ export type Events = {
showRemoveFromCollectionDialog: SimpleRom[];
showDeleteCollectionDialog: Collection;
showMatchRomDialog: SimpleRom;
showSearchCoverDialog: string;
showSearchCoverDialog: { term: string; platformAspectRatio: number };
updateUrlCover: string;
showSearchRomDialog: null;
showEditRomDialog: SimpleRom;