Compare commits

..

No commits in common. "3db0a40192eefc9a3f55016f7240c3defb0fef8d" and "71a1c95e47253825e73e73b5830c0e0e2f625b0e" have entirely different histories.

View file

@ -42,17 +42,11 @@ const Gallery = {
if (this.size === 'hide') {
return attachments.map((item) => ({ minimal: true, items: [item] }))
}
console.log('<=')
const rows = this.grid
? [{ grid: true, items: attachments }]
: attachments
.reduce(
(acc, attachment, i) => {
const peek = attachments[i+1]
const nextEnd = peek == null
const nextWide = !nextEnd && !displayTypes.has(peek?.type)
// Inserting new row
if (attachment.type === 'audio') {
return [
...acc,
@ -67,16 +61,18 @@ const Gallery = {
{ items: [] },
]
}
const maxPerRow = 3
const attachmentsRemaining = this.attachments.length - i + 1
const currentRow = acc[acc.length - 1].items
if ((nextWide || nextEnd) && currentRow.length >= maxPerRow) {
const last = currentRow.splice(-1)[0]
return [...acc, { items: [last, attachment] }]
currentRow.push(attachment)
if (
currentRow.length >= maxPerRow &&
attachmentsRemaining > maxPerRow
) {
return [...acc, { items: [] }]
} else {
currentRow.push(attachment)
return acc
}
return acc
},
[{ items: [] }],
)