From edf0ddb50cbf57cefc6b8f0d1984cd3269466789 Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch
Date: Sun, 24 Dec 2023 06:22:29 +0100 Subject: Handle missing thumbnails better --- public/gallery.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'public/gallery.js') diff --git a/public/gallery.js b/public/gallery.js index c7d21a1..5df58e6 100644 --- a/public/gallery.js +++ b/public/gallery.js @@ -64,6 +64,17 @@ let Header = { }, } +let Thumbnail = { + view(vnode) { + const e = vnode.attrs.info + if (!e.thumbW || !e.thumbH) + return m('.thumbnail.missing', {...vnode.attrs, info: null}) + return m('img.thumbnail', {...vnode.attrs, info: null, + src: `/thumb/${e.sha1}`, width: e.thumbW, height: e.thumbH, + loading}) + }, +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - let BrowseModel = { @@ -144,10 +155,9 @@ let BrowseView = { return m('.browser[tabindex=0]', { // Trying to force the oncreate on path changes. key: BrowseModel.path, - }, BrowseModel.entries.map(e => { - return m(m.route.Link, {href: `/view/${e.sha1}`}, - m('img.thumbnail', {src: `/thumb/${e.sha1}`, - width: e.thumbW, height: e.thumbH, title: e.name, loading})) + }, BrowseModel.entries.map(info => { + return m(m.route.Link, {href: `/view/${info.sha1}`}, + m(Thumbnail, {info, title: info.name})) })) }, } @@ -289,8 +299,7 @@ let SimilarThumbnail = { view(vnode) { const info = vnode.attrs.info return m(m.route.Link, {href: `/view/${info.sha1}`}, - m('img.thumbnail', {src: `/thumb/${info.sha1}`, - width: info.thumbW, height: info.thumbH, loading})) + m(Thumbnail, {info})) }, } @@ -363,8 +372,7 @@ let DuplicatesThumbnail = { const info = vnode.attrs.info return [ m(m.route.Link, {href: `/similar/${info.sha1}`}, - m('img.thumbnail', {src: `/thumb/${info.sha1}`, - width: info.thumbW, height: info.thumbH, loading})), + m(Thumbnail, {info})), (info.occurences != 1) ? ` ×${info.occurences}` : [], ] }, @@ -416,8 +424,7 @@ let OrphansReplacement = { return [ ` → `, m(m.route.Link, {href: `/view/${info.sha1}`}, - m('img.thumbnail', {src: `/thumb/${info.sha1}`, - width: info.thumbW, height: info.thumbH, loading})), + m(Thumbnail, {info})), `${info.tags} tags`, ] }, @@ -429,8 +436,7 @@ let OrphansRow = { return m('.row', [ // It might not load, but still allow tag viewing. m(m.route.Link, {href: `/view/${info.sha1}`}, - m('img.thumbnail', {src: `/thumb/${info.sha1}`, - width: info.thumbW, height: info.thumbH, loading})), + m(Thumbnail, {info})), `${info.tags} tags`, m(OrphansReplacement, {info: info.replacement}), ]) -- cgit v1.2.3-70-g09d2