Skip to content

Commit

Permalink
add last commit to blobfox and glitch
Browse files Browse the repository at this point in the history
  • Loading branch information
Ember-ruby committed Mar 2, 2025
1 parent 9793d4e commit ce36e62
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 22 deletions.
4 changes: 2 additions & 2 deletions app/javascript/flavours/blobfox/actions/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
36 changes: 27 additions & 9 deletions app/javascript/flavours/blobfox/components/media_gallery.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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 = <Item standalone autoplay={autoplay} onClick={this.handleClick} onAltClick={this.handleAltClick} attachment={media.get(0)} lang={lang} displayWidth={width} visible={visible} />;
} else {
children = media.take(4).map((attachment, i) => <Item key={attachment.get('id')} autoplay={autoplay} onClick={this.handleClick} onAltClick={this.handleAltClick} attachment={attachment} index={i} lang={lang} size={size} letterbox={letterbox} displayWidth={width} visible={visible || uncached} />);
children = media.map((attachment, i) => <Item key={attachment.get('id')} autoplay={autoplay} onClick={this.handleClick} attachment={attachment} index={i} lang={lang} size={size} displayWidth={width} visible={visible || uncached} />);
}

if (uncached) {
Expand Down
4 changes: 2 additions & 2 deletions app/javascript/flavours/glitch/actions/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
36 changes: 27 additions & 9 deletions app/javascript/flavours/glitch/components/media_gallery.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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 = <Item standalone autoplay={autoplay} onClick={this.handleClick} onAltClick={this.handleAltClick} attachment={media.get(0)} lang={lang} displayWidth={width} visible={visible} />;
} else {
children = media.take(4).map((attachment, i) => <Item key={attachment.get('id')} autoplay={autoplay} onClick={this.handleClick} onAltClick={this.handleAltClick} attachment={attachment} index={i} lang={lang} size={size} letterbox={letterbox} displayWidth={width} visible={visible || uncached} />);
children = media.map((attachment, i) => <Item key={attachment.get('id')} autoplay={autoplay} onClick={this.handleClick} attachment={attachment} index={i} lang={lang} size={size} displayWidth={width} visible={visible || uncached} />);
}

if (uncached) {
Expand Down

0 comments on commit ce36e62

Please sign in to comment.