aboutsummaryrefslogtreecommitdiff
path: root/src/components/gallery/gallery.js
diff options
context:
space:
mode:
authorlambda <pleromagit@rogerbraun.net>2019-01-30 18:58:08 +0000
committerlambda <pleromagit@rogerbraun.net>2019-01-30 18:58:08 +0000
commit5b7b1dfebc37bd5db4e839973062b452b02c898d (patch)
treea517e4942725286b173b685cbe87bc6c7878b66e /src/components/gallery/gallery.js
parentb1facdf7ad54436c2afde7c28c917cda87a5b7e3 (diff)
parentc7cffbb6c70bbb21cf787d96e82e0261427b9234 (diff)
Merge branch 'feat/media-modal' into 'develop'
modal for viewing attachments in-tab See merge request pleroma/pleroma-fe!468
Diffstat (limited to 'src/components/gallery/gallery.js')
-rw-r--r--src/components/gallery/gallery.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/components/gallery/gallery.js b/src/components/gallery/gallery.js
new file mode 100644
index 00000000..7f33a81b
--- /dev/null
+++ b/src/components/gallery/gallery.js
@@ -0,0 +1,55 @@
+import Attachment from '../attachment/attachment.vue'
+import { chunk, last, dropRight } from 'lodash'
+
+const Gallery = {
+ data: () => ({
+ width: 500
+ }),
+ props: [
+ 'attachments',
+ 'nsfw',
+ 'setMedia'
+ ],
+ components: { Attachment },
+ mounted () {
+ this.resize()
+ window.addEventListener('resize', this.resize)
+ },
+ destroyed () {
+ window.removeEventListener('resize', this.resize)
+ },
+ computed: {
+ rows () {
+ if (!this.attachments) {
+ return []
+ }
+ const rows = chunk(this.attachments, 3)
+ if (last(rows).length === 1 && rows.length > 1) {
+ // if 1 attachment on last row -> add it to the previous row instead
+ const lastAttachment = last(rows)[0]
+ const allButLastRow = dropRight(rows)
+ last(allButLastRow).push(lastAttachment)
+ return allButLastRow
+ }
+ return rows
+ },
+ rowHeight () {
+ return itemsPerRow => ({ 'height': `${(this.width / (itemsPerRow + 0.6))}px` })
+ },
+ useContainFit () {
+ return this.$store.state.config.useContainFit
+ }
+ },
+ methods: {
+ resize () {
+ // Quick optimization to make resizing not always trigger state change,
+ // only update attachment size in 10px steps
+ const width = Math.floor(this.$el.getBoundingClientRect().width / 10) * 10
+ if (this.width !== width) {
+ this.width = width
+ }
+ }
+ }
+}
+
+export default Gallery