From ce36e62229577c5275f8c2924eb79aadee235d11 Mon Sep 17 00:00:00 2001 From: Ember Date: Mon, 3 Mar 2025 02:07:19 +1100 Subject: [PATCH] add last commit to blobfox and glitch --- .../flavours/blobfox/actions/compose.js | 4 +-- .../blobfox/components/media_gallery.jsx | 36 ++++++++++++++----- .../flavours/glitch/actions/compose.js | 4 +-- .../glitch/components/media_gallery.jsx | 36 ++++++++++++++----- 4 files changed, 58 insertions(+), 22 deletions(-) diff --git a/app/javascript/flavours/blobfox/actions/compose.js b/app/javascript/flavours/blobfox/actions/compose.js index 0c1cbdd052c800..07dce2f3ec1112 100644 --- a/app/javascript/flavours/blobfox/actions/compose.js +++ b/app/javascript/flavours/blobfox/actions/compose.js @@ -318,7 +318,7 @@ export function doodleSet(options) { export function uploadCompose(files) { return function (dispatch, getState) { - const uploadLimit = 4; + const uploadLimit = getState().getIn(['server', 'server', 'configuration', 'statuses', 'max_media_attachments']); const media = getState().getIn(['compose', 'media_attachments']); const pending = getState().getIn(['compose', 'pending_media_attachments']); const progress = new Array(files.length).fill(0); @@ -338,7 +338,7 @@ export function uploadCompose(files) { dispatch(uploadComposeRequest()); for (const [i, file] of Array.from(files).entries()) { - if (media.size + i > 3) break; + if (media.size + i > (uploadLimit - 1)) break; const data = new FormData(); data.append('file', file); diff --git a/app/javascript/flavours/blobfox/components/media_gallery.jsx b/app/javascript/flavours/blobfox/components/media_gallery.jsx index ba1817a3f328d0..026de0c2c1b0e7 100644 --- a/app/javascript/flavours/blobfox/components/media_gallery.jsx +++ b/app/javascript/flavours/blobfox/components/media_gallery.jsx @@ -39,6 +39,14 @@ const messages = defineMessages({ }, }); +const colCount = function(size) { + return Math.max(Math.ceil(Math.sqrt(size)), 2); +}; + +const rowCount = function(size) { + return Math.ceil(size / colCount(size)); +}; + class Item extends PureComponent { static propTypes = { @@ -125,14 +133,19 @@ class Item extends PureComponent { let badges = [], thumbnail; let width = 50; - let height = 100; + let height = 50; - if (size === 1) { - width = 100; - } + const cols = colCount(size); + const remaining = (-size % cols + cols) % cols; + const largeCount = Math.floor(remaining / 3); // width=2, height=2 - if (size === 4 || (size === 3 && index > 0)) { - height = 50; + const mediumCount = remaining % 3; // height=2 + + if (size === 1 || index < largeCount) { + width = 100; + height = 100; + } else if (size === 2 || index < largeCount + mediumCount) { + height = 100; } if (attachment.get('description')?.length > 0) { @@ -348,7 +361,7 @@ class MediaGallery extends PureComponent { render () { const { media, lang, intl, sensitive, letterbox, fullwidth, defaultWidth, autoplay } = this.props; const { visible } = this.state; - const size = media.take(4).size; + const size = media.size; const uncached = media.every(attachment => attachment.get('type') === 'unknown'); const width = this.state.width || defaultWidth; @@ -362,13 +375,18 @@ class MediaGallery extends PureComponent { if (this.isStandaloneEligible()) { // TODO: cropImages setting style.aspectRatio = `${this.props.media.getIn([0, 'meta', 'small', 'aspect'])}`; } else { - style.aspectRatio = '16 / 9'; + const cols = colCount(media.size); + const rows = rowCount(media.size); + style.gridTemplateColumns = `repeat(${cols}, 1fr)`; + style.gridTemplateRows = `repeat(${rows}, 1fr)`; + + style.aspectRatio = '3 / 2'; } if (this.isStandaloneEligible()) { children = ; } else { - children = media.take(4).map((attachment, i) => ); + children = media.map((attachment, i) => ); } if (uncached) { diff --git a/app/javascript/flavours/glitch/actions/compose.js b/app/javascript/flavours/glitch/actions/compose.js index e7837c87d609ef..cc57eced446fe7 100644 --- a/app/javascript/flavours/glitch/actions/compose.js +++ b/app/javascript/flavours/glitch/actions/compose.js @@ -318,7 +318,7 @@ export function doodleSet(options) { export function uploadCompose(files) { return function (dispatch, getState) { - const uploadLimit = 4; + const uploadLimit = getState().getIn(['server', 'server', 'configuration', 'statuses', 'max_media_attachments']); const media = getState().getIn(['compose', 'media_attachments']); const pending = getState().getIn(['compose', 'pending_media_attachments']); const progress = new Array(files.length).fill(0); @@ -338,7 +338,7 @@ export function uploadCompose(files) { dispatch(uploadComposeRequest()); for (const [i, file] of Array.from(files).entries()) { - if (media.size + i > 3) break; + if (media.size + i > (uploadLimit - 1)) break; const data = new FormData(); data.append('file', file); diff --git a/app/javascript/flavours/glitch/components/media_gallery.jsx b/app/javascript/flavours/glitch/components/media_gallery.jsx index f2fa39465dfae1..41d5c2a2670b52 100644 --- a/app/javascript/flavours/glitch/components/media_gallery.jsx +++ b/app/javascript/flavours/glitch/components/media_gallery.jsx @@ -40,6 +40,14 @@ const messages = defineMessages({ }, }); +const colCount = function(size) { + return Math.max(Math.ceil(Math.sqrt(size)), 2); +}; + +const rowCount = function(size) { + return Math.ceil(size / colCount(size)); +}; + class Item extends PureComponent { static propTypes = { @@ -126,14 +134,19 @@ class Item extends PureComponent { let badges = [], thumbnail; let width = 50; - let height = 100; + let height = 50; - if (size === 1) { - width = 100; - } + const cols = colCount(size); + const remaining = (-size % cols + cols) % cols; + const largeCount = Math.floor(remaining / 3); // width=2, height=2 - if (size === 4 || (size === 3 && index > 0)) { - height = 50; + const mediumCount = remaining % 3; // height=2 + + if (size === 1 || index < largeCount) { + width = 100; + height = 100; + } else if (size === 2 || index < largeCount + mediumCount) { + height = 100; } if (attachment.get('description')?.length > 0) { @@ -349,7 +362,7 @@ class MediaGallery extends PureComponent { render () { const { media, lang, intl, sensitive, letterbox, fullwidth, defaultWidth, autoplay } = this.props; const { visible } = this.state; - const size = media.take(4).size; + const size = media.size; const uncached = media.every(attachment => attachment.get('type') === 'unknown'); const width = this.state.width || defaultWidth; @@ -363,13 +376,18 @@ class MediaGallery extends PureComponent { if (this.isStandaloneEligible()) { // TODO: cropImages setting style.aspectRatio = `${this.props.media.getIn([0, 'meta', 'small', 'aspect'])}`; } else { - style.aspectRatio = '16 / 9'; + const cols = colCount(media.size); + const rows = rowCount(media.size); + style.gridTemplateColumns = `repeat(${cols}, 1fr)`; + style.gridTemplateRows = `repeat(${rows}, 1fr)`; + + style.aspectRatio = '3 / 2'; } if (this.isStandaloneEligible()) { children = ; } else { - children = media.take(4).map((attachment, i) => ); + children = media.map((attachment, i) => ); } if (uncached) {