Skip to content

Commit 42e2c27

Browse files
committed
fix slideshow render
1 parent 3d0a89f commit 42e2c27

6 files changed

Lines changed: 37 additions & 24 deletions

File tree

‎src/navigation/chrome.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,12 @@ export function deriveExplorerHeader (input: ExplorerHeaderInput): boolean {
168168
* The header is never shown over a person's profile or friends, whatever the resource,
169169
* nor over a storage view, which has its own header or the navbar.
170170
*/
171-
export function explorerHeaderForPane (resourceHeader: boolean, paneName?: string, folderView?: FolderView): boolean {
171+
export function explorerHeaderForPane (
172+
resourceHeader: boolean,
173+
paneName?: string,
174+
folderView?: FolderView,
175+
solo = false
176+
): boolean {
172177
if (paneName === 'folder' && (folderView === 'explorer' || folderView === 'storage')) return false
173178
return resourceHeader && !isPersonPane(paneName)
174179
}

‎src/outline/manager.js‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,6 @@ export default function (context) {
259259
})
260260
}
261261

262-
function getPane (relevantPanes, subject) {
263-
return (
264-
relevantPanes.find(
265-
pane => pane.shouldGetFocus && pane.shouldGetFocus(subject)
266-
) || relevantPanes[0]
267-
)
268-
}
269-
270262
function setQueryButtonVisibility (shouldShow) {
271263
const queryButton = dom.getElementById('queryButton')
272264
if (!queryButton) return
@@ -313,7 +305,7 @@ export default function (context) {
313305
subjectUri: subject.uri,
314306
pane,
315307
relevantPanes: provider.relevantPanes || [],
316-
header: state && explorerHeaderForPane(state.showHeader, pane?.name, state.options.folderView)
308+
header: state && explorerHeaderForPane(state.showHeader, pane?.name, state.options.folderView, state.options.solo)
317309
? { paneIcon: getPaneIcon(pane, subject, context), menuItems: state.menuItems }
318310
: undefined,
319311
paneElement
@@ -403,7 +395,7 @@ export default function (context) {
403395
}
404396

405397
provider.relevantPanes = relevantPanes
406-
provider.pane = requiredPane || getPane(relevantPanes, subject)
398+
provider.pane = requiredPane || UI.getPreferredPane(subject, context, relevantPanes)
407399
const isRootResource = !!(subject && subject.uri && subject.site && subject.site().uri === subject.uri)
408400
const viewerPodOnly = !!options.headerOnlyInViewerPod
409401
const showHeader = !subject.uri.endsWith('/index.ttl#this') && deriveExplorerHeader({

‎src/registerPanes.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ export function registerPanes (register) {
9090
register(audioPane) // Audio clip player
9191

9292
register(dokieliPane) // Should be above dataContentPane
93+
register(slideshowPane) // Image containers should open in their specialized view
9394
register(folderPane) // Should be above dataContentPane
9495
register(classInstancePane) // Should be above dataContentPane
9596
// register(require('./dynamic/dynamicPanes.js')) // warp etc warp broken 2017/8
96-
register(slideshowPane)
9797

9898
register(socialPane)
9999

‎src/slideshow/slideshowPane.js‎

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@
22
**
33
*/
44
import * as UI from 'solid-ui'
5+
import { solidLogicSingleton } from 'solid-logic'
56

67
import makeBSS from '@solid/better-simple-slideshow'
78
const ns = UI.ns
9+
let slideshowId = 0
10+
11+
function isImageResource (file, store) {
12+
if (UI.widgets.isImage(file)) return true
13+
14+
const contentTypes = store.fetcher.getHeader(file, 'content-type') || []
15+
return contentTypes.some(contentType => contentType.toLowerCase().startsWith('image/'))
16+
}
817

918
export const slideshowPane = {
1019
icon: UI.icons.iconBase + 'noun_138712.svg',
@@ -16,13 +25,11 @@ export const slideshowPane = {
1625
// Does the subject deserve an slideshow pane?
1726
label: function (subject, context) {
1827
const store = context.session.store
19-
const ns = UI.ns
20-
const t = store.findTypeURIs(subject)
21-
if (t[ns.ldp('Container').uri] || t[ns.ldp('BasicContainer').uri]) {
28+
if (solidLogicSingleton.resource.isContainer(subject)) {
2229
const contents = store.each(subject, ns.ldp('contains'))
2330
let count = 0
2431
contents.forEach(function (file) {
25-
if (UI.widgets.isImage(file)) count++
32+
if (isImageResource(file, store)) count++
2633
})
2734
return count > 0 ? 'Slideshow' : null
2835
}
@@ -40,18 +47,21 @@ export const slideshowPane = {
4047
const store = context.session.store
4148
const ns = UI.ns
4249
const div = dom.createElement('div')
50+
const id = `slideshow-${++slideshowId}`
51+
div.id = id
4352
div.setAttribute('class', 'bss-slides')
4453

45-
const t = store.findTypeURIs(subject)
4654
let predicate
47-
if (t[ns.ldp('BasicContainer').uri] || t[ns.ldp('Container').uri]) {
55+
if (solidLogicSingleton.resource.isContainer(subject)) {
4856
predicate = ns.ldp('contains')
4957
}
50-
const images = store.each(subject, predicate) // @@ random order?
58+
const images = [...new Map(
59+
store.each(subject, predicate).map(image => [image.uri, image])
60+
).values()]
5161
// @@ Ideally: sort by embedded time of image
52-
images.sort() // Sort for now by URI
62+
images.sort((left, right) => left.uri.localeCompare(right.uri))
5363
for (let i = 0; i < images.length; i++) {
54-
if (!UI.widgets.isImage(images[i])) continue
64+
if (!isImageResource(images[i], store)) continue
5565
const figure = div.appendChild(dom.createElement('figure'))
5666
const img = figure.appendChild(dom.createElement('img'))
5767

@@ -69,9 +79,9 @@ export const slideshowPane = {
6979
}
7080
const options = { dom }
7181

72-
setTimeout(function () {
73-
makeBSS('.bss-slides', options)
74-
}, 1000) // Must run after the code which called this
82+
dom.defaultView.requestAnimationFrame(function () {
83+
makeBSS(`#${id}`, options)
84+
})
7585

7686
return div
7787
}

‎test/unit/navigation/chrome.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,11 @@ describe('file explorer header', () => {
223223
// A pane opened in place of the folder keeps its resource header
224224
expect(explorerHeaderForPane(true, 'source', 'explorer')).toBe(true)
225225
})
226+
227+
it('retains the header for slideshow in solo and regular views', () => {
228+
expect(explorerHeaderForPane(true, 'slideshow', undefined, true)).toBe(true)
229+
expect(explorerHeaderForPane(true, 'slideshow')).toBe(true)
230+
})
226231
})
227232

228233
describe('storage view', () => {

‎test/unit/outline/manager.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ vi.mock('solid-ui', async () => {
1616
return {
1717
...actual,
1818
getRelevantPanes: async (_subject, context) => context.session.paneRegistry.list,
19+
getPreferredPane: (subject, _context, panes) => panes.find(pane => pane.shouldGetFocus?.(subject)) || panes[0],
1920
login: {
2021
...actual.login,
2122
filterAvailablePanes: async panes => panes

0 commit comments

Comments
 (0)