From 597e87896e740b3ad9627c650a4040218917d3e4 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Mon, 18 Sep 2017 00:46:51 +0300 Subject: [PATCH] [www] Gallery page updated --- src/core/Album.js | 23 +++++++++++++---- src/core/Image.js | 21 ++++++++++++++++ src/core/ImageArtifactType.js | 16 +++++++----- src/routes/gallery.js | 29 ++++++++++++++++------ src/style/components/album-collection.scss | 4 +-- src/style/components/gallery-item.scss | 20 ++------------- 6 files changed, 75 insertions(+), 38 deletions(-) diff --git a/src/core/Album.js b/src/core/Album.js index 3acf85bb..010811b0 100644 --- a/src/core/Album.js +++ b/src/core/Album.js @@ -4,6 +4,7 @@ const ImageArtifactType = require('./ImageArtifactType') const {find, findOne} = require('../lib/store') const previewTypes = [ + ImageArtifactType.SMALL, ImageArtifactType.MEDIUM, ImageArtifactType.BIG, ImageArtifactType.ORIGIN, @@ -31,14 +32,26 @@ const previewFromImage = (imgs = []) => imgs.length : null const processAlbum = async album => { + let preview = {} + // { + // data: [ + // { + // url: null, + // width: 0, + // height: 0, + // } + // ] + // } + const previewImageId = album.preview ? album.preview : previewFromImage(album.images) - let preview if (previewImageId) { const image = await Image.findById(previewImageId) - preview = image.findArtifact(previewTypes) - } else { - preview = { - url: null, + if (image) { + // const imageArtifacts = image.findArtifact(previewTypes) + // if (imageArtifacts) { + // preview = imageArtifacts + // } + preview = image.getPicture(ImageArtifactType.SMALL) } } diff --git a/src/core/Image.js b/src/core/Image.js index 332dcfbd..3bed05f1 100644 --- a/src/core/Image.js +++ b/src/core/Image.js @@ -1,4 +1,5 @@ const Data = require('./Data') +const ImageArtifactType = require('./ImageArtifactType') const {findOne} = require('../lib/store') const {mapOf} = require('../lib/common') @@ -32,6 +33,26 @@ class Image { return null } + + getPicture(size) { + const retinaSize = ImageArtifactType.retina(size) + + const a = this.getArtifact(size) + const a2 = this.getArtifact(retinaSize) + const pic = { + src: a.url, + width: a.width, + height: a.height, + set: [ + { + url: a2.url, + density: ImageArtifactType.RETINA_DENSITY, + } + ] + } + console.log(pic) + return pic + } } class ImageArtifact { diff --git a/src/core/ImageArtifactType.js b/src/core/ImageArtifactType.js index f731f278..2f6e75fd 100644 --- a/src/core/ImageArtifactType.js +++ b/src/core/ImageArtifactType.js @@ -1,11 +1,15 @@ -class ImageArtifact { +class ImageArtifactType { constructor() { - throw new Error('Cannot create instance of ImageArtifact') + throw new Error('Cannot create instance of ImageArtifactType') } } -ImageArtifact.MEDIUM = 'medium' -ImageArtifact.BIG = 'big' -ImageArtifact.ORIGIN = 'origin' +ImageArtifactType.SMALL = 'small' +ImageArtifactType.MEDIUM = 'medium' +ImageArtifactType.BIG = 'big' +ImageArtifactType.ORIGIN = 'origin' -module.exports = ImageArtifact +ImageArtifactType.RETINA_DENSITY = 2 +ImageArtifactType.retina = type => `${type}@${ImageArtifactType.RETINA_DENSITY}` + +module.exports = ImageArtifactType diff --git a/src/routes/gallery.js b/src/routes/gallery.js index 1b756068..9e3aad9e 100644 --- a/src/routes/gallery.js +++ b/src/routes/gallery.js @@ -6,10 +6,6 @@ const {splitBy} = require('../lib/array') const getPathWithNoTrailingSlash = require('../lib/url').getPathWithNoTrailingSlash const {get} = require('koa-route') -const previewUrl = preview => preview - ? preview.url - : null - function getMeta() { return { title: 'Галерея', @@ -17,11 +13,30 @@ function getMeta() { } } +// {data.set.map((s, i) => ( +// +// ))} +// const m = 0.5 +const m = 1 +const AlbumImage = ({data, alt}) => ( + + {alt} `${url} ${density}x`)} + /> + +) + const GItem = ({album}) => (
- -

{album.title}

- {album.title}/ +
+
) diff --git a/src/style/components/album-collection.scss b/src/style/components/album-collection.scss index bcdcedd5..f28972fc 100644 --- a/src/style/components/album-collection.scss +++ b/src/style/components/album-collection.scss @@ -5,8 +5,8 @@ display: flex; flex-wrap: wrap; position: relative; - justify-content: center; - align-items:flex-start; + justify-content: flex-start; + align-items:center; margin: 0 0 $double-margin; } diff --git a/src/style/components/gallery-item.scss b/src/style/components/gallery-item.scss index aacb524f..90f51113 100644 --- a/src/style/components/gallery-item.scss +++ b/src/style/components/gallery-item.scss @@ -8,27 +8,11 @@ $percentage: 25%; box-sizing: padding-box; padding: 0; - width: 13em; - height: 15em; margin: 0 $single-margin $double-margin; - overflow: hidden; - h3 { - text-align: center; - } - - a { - color: $dark-color; + a.invisible { border-bottom: none; - - &:hover { - border-bottom: none; - color: $blue-color; - } - } - - img { - width: 100%; + text-decoration: none; } }