From a2c7d645445683cda3e8d683d69dcde4fde74f2a Mon Sep 17 00:00:00 2001 From: tagmeh Date: Wed, 6 Aug 2025 02:16:40 -0500 Subject: [PATCH] Working 1.0. Removed duplicate api calls per image. Attempted testing, removed, unable to figure out either testing option. --- client/components/covers/DisplayCover.vue | 113 +++++++++++++++++++ client/components/covers/SortedCovers.vue | 97 ++++++++++++++++ client/components/modals/item/tabs/Cover.vue | 86 ++++---------- 3 files changed, 229 insertions(+), 67 deletions(-) create mode 100644 client/components/covers/DisplayCover.vue create mode 100644 client/components/covers/SortedCovers.vue diff --git a/client/components/covers/DisplayCover.vue b/client/components/covers/DisplayCover.vue new file mode 100644 index 000000000..c7c721a5f --- /dev/null +++ b/client/components/covers/DisplayCover.vue @@ -0,0 +1,113 @@ +// Displays a book cover, given a cover image object with url, width, and height properties. +// It supports showing the cover in a specific aspect ratio, displaying resolution, +// and providing an option to open the cover in a new tab. +// This component exists in order to avoid a second api call per image. Since the images are being queried and sorted on a parent component (Cover.vue). + + + + diff --git a/client/components/covers/SortedCovers.vue b/client/components/covers/SortedCovers.vue new file mode 100644 index 000000000..4f75df7bb --- /dev/null +++ b/client/components/covers/SortedCovers.vue @@ -0,0 +1,97 @@ +// This component sorts and displays book covers based on their aspect ratio. +// It separates covers into primary (preferred aspect ratio) and secondary (opposite aspect ratio) sections. +// Covers are displayed with options to select, view resolution, and open in a new tab. + + + + + + diff --git a/client/components/modals/item/tabs/Cover.vue b/client/components/modals/item/tabs/Cover.vue index 3cbc63a7e..c0a1c2918 100644 --- a/client/components/modals/item/tabs/Cover.vue +++ b/client/components/modals/item/tabs/Cover.vue @@ -70,63 +70,9 @@ -
-

{{ $strings.MessageNoCoversFound }}

- - - - - +
+

{{ $strings.MessageNoCoversFound }}

+
@@ -391,26 +337,32 @@ export default { }) }, async resolveImages() { + console.log(this.coversFound) const resolvedImages = await Promise.all( this.coversFound.map((cover) => { return new Promise((resolve) => { const img = new Image() img.src = cover img.onload = () => { - resolve({ src: cover, width: img.width, height: img.height }) + resolve({ + url: cover, + width: img.width, + height: img.height + }) + } + img.onerror = () => { + // Resolve with default dimensions if image fails to load + resolve({ + url: cover, + width: 400, + height: 600 + }) } }) }) ) - // Sort images: squares first, then rectangles by area - this.sortedCovers = resolvedImages.sort((a, b) => { - // Prioritize square images (-1 for square, 1 for non-square) - const squareComparison = (b.width === b.height) - (a.width === a.height) - if (squareComparison !== 0) return squareComparison - - // Sub-sort by width (ascending order) - return a.width - b.width - }) + this.sortedCovers = resolvedImages + console.log('Resolved covers:', this.sortedCovers) return this.sortedCovers } }