22 **
33 */
44import * as UI from 'solid-ui'
5+ import { solidLogicSingleton } from 'solid-logic'
56
67import makeBSS from '@solid/better-simple-slideshow'
78const ns = UI . ns
9+ let slideshowId = 0
810
911export const slideshowPane = {
1012 icon : UI . icons . iconBase + 'noun_138712.svg' ,
@@ -16,13 +18,11 @@ export const slideshowPane = {
1618 // Does the subject deserve an slideshow pane?
1719 label : function ( subject , context ) {
1820 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 ] ) {
21+ if ( solidLogicSingleton . resource . isContainer ( subject ) ) {
2222 const contents = store . each ( subject , ns . ldp ( 'contains' ) )
2323 let count = 0
2424 contents . forEach ( function ( file ) {
25- if ( UI . widgets . isImage ( file ) ) count ++
25+ if ( solidLogicSingleton . resource . isImage ( file ) ) count ++
2626 } )
2727 return count > 0 ? 'Slideshow' : null
2828 }
@@ -40,18 +40,21 @@ export const slideshowPane = {
4040 const store = context . session . store
4141 const ns = UI . ns
4242 const div = dom . createElement ( 'div' )
43+ const id = `slideshow-${ ++ slideshowId } `
44+ div . id = id
4345 div . setAttribute ( 'class' , 'bss-slides' )
4446
45- const t = store . findTypeURIs ( subject )
4647 let predicate
47- if ( t [ ns . ldp ( 'BasicContainer' ) . uri ] || t [ ns . ldp ( 'Container' ) . uri ] ) {
48+ if ( solidLogicSingleton . resource . isContainer ( subject ) ) {
4849 predicate = ns . ldp ( 'contains' )
4950 }
50- const images = store . each ( subject , predicate ) // @@ random order?
51+ const images = [ ...new Map (
52+ store . each ( subject , predicate ) . map ( image => [ image . uri , image ] )
53+ ) . values ( ) ]
5154 // @@ Ideally: sort by embedded time of image
52- images . sort ( ) // Sort for now by URI
55+ images . sort ( ( left , right ) => left . uri . localeCompare ( right . uri ) )
5356 for ( let i = 0 ; i < images . length ; i ++ ) {
54- if ( ! UI . widgets . isImage ( images [ i ] ) ) continue
57+ if ( ! solidLogicSingleton . resource . isImage ( images [ i ] ) ) continue
5558 const figure = div . appendChild ( dom . createElement ( 'figure' ) )
5659 const img = figure . appendChild ( dom . createElement ( 'img' ) )
5760
@@ -69,9 +72,9 @@ export const slideshowPane = {
6972 }
7073 const options = { dom }
7174
72- setTimeout ( function ( ) {
73- makeBSS ( '.bss-slides' , options )
74- } , 1000 ) // Must run after the code which called this
75+ dom . defaultView . requestAnimationFrame ( function ( ) {
76+ makeBSS ( `# ${ id } ` , options )
77+ } )
7578
7679 return div
7780 }
0 commit comments