Skip to content

Commit 6cca34c

Browse files
authored
Merge pull request #782 from SolidOS/fix/slideshow
images only and more than one
2 parents f044bcc + 818cb33 commit 6cca34c

3 files changed

Lines changed: 143 additions & 95 deletions

File tree

‎package-lock.json‎

Lines changed: 83 additions & 83 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/slideshow/slideshowPane.js‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ import makeBSS from '@solid/better-simple-slideshow'
88
const ns = UI.ns
99
let slideshowId = 0
1010

11+
function getImageContents (subject, store) {
12+
if (!solidLogicSingleton.resource.isContainer(subject)) return []
13+
14+
const contents = store.each(subject, ns.ldp('contains'))
15+
return contents.filter(file => solidLogicSingleton.resource.isImage(file))
16+
}
17+
1118
export const slideshowPane = {
1219
icon: UI.icons.iconBase + 'noun_138712.svg',
1320

@@ -20,11 +27,8 @@ export const slideshowPane = {
2027
const store = context.session.store
2128
if (solidLogicSingleton.resource.isContainer(subject)) {
2229
const contents = store.each(subject, ns.ldp('contains'))
23-
let count = 0
24-
contents.forEach(function (file) {
25-
if (solidLogicSingleton.resource.isImage(file)) count++
26-
})
27-
return count > 0 ? 'Slideshow' : null
30+
const images = getImageContents(subject, store)
31+
return new Set(images.map(image => image.uri)).size > 1 && images.length === contents.length ? 'Slideshow' : null
2832
}
2933
return null
3034
},
@@ -38,23 +42,17 @@ export const slideshowPane = {
3842
UI.widgets.addStyleSheet(dom, styleSheet)
3943

4044
const store = context.session.store
41-
const ns = UI.ns
4245
const div = dom.createElement('div')
4346
const id = `slideshow-${++slideshowId}`
4447
div.id = id
4548
div.setAttribute('class', 'bss-slides')
4649

47-
let predicate
48-
if (solidLogicSingleton.resource.isContainer(subject)) {
49-
predicate = ns.ldp('contains')
50-
}
5150
const images = [...new Map(
52-
store.each(subject, predicate).map(image => [image.uri, image])
51+
getImageContents(subject, store).map(image => [image.uri, image])
5352
).values()]
5453
// @@ Ideally: sort by embedded time of image
5554
images.sort((left, right) => left.uri.localeCompare(right.uri))
5655
for (let i = 0; i < images.length; i++) {
57-
if (!solidLogicSingleton.resource.isImage(images[i])) continue
5856
const figure = div.appendChild(dom.createElement('figure'))
5957
const img = figure.appendChild(dom.createElement('img'))
6058

0 commit comments

Comments
 (0)