11import { createSelector } from 'reselect' ;
2- import { createCachedSelector } from 're-reselect' ;
32import { PropertyValue , Utils , Resource } from 'manifesto.js' ;
43import getThumbnail from '../../lib/ThumbnailFactory' ;
54import asArray from '../../lib/asArray' ;
@@ -24,9 +23,10 @@ export const getLocale = createSelector(
2423 [
2524 getCompanionWindowLocale ,
2625 getConfig ,
26+ ( state , { locale } ) => locale ,
2727 ] ,
28- ( companionWindowLocale , config = { } ) => (
29- companionWindowLocale || config . language
28+ ( companionWindowLocale , config = { } , locale ) => (
29+ locale || companionWindowLocale || config . language || config . fallbackLanguages
3030 ) ,
3131) ;
3232
@@ -57,17 +57,9 @@ export const getManifestError = createSelector(
5757) ;
5858
5959/** Instantiate a manifesto instance */
60- const getContextualManifestoInstance = createCachedSelector (
60+ const getContextualManifestoInstance = createSelector (
6161 getManifest ,
62- getLocale ,
63- ( manifest , locale ) => manifest
64- && createManifestoInstance ( manifest . json , locale ) ,
65- ) (
66- ( state , { companionWindowId, manifestId, windowId } ) => [
67- manifestId ,
68- windowId ,
69- getLocale ( state , { companionWindowId } ) ,
70- ] . join ( ' - ' ) , // Cache key consisting of manifestId, windowId, and locale
62+ manifest => manifest && createManifestoInstance ( manifest . json ) ,
7163) ;
7264
7365/**
@@ -80,15 +72,14 @@ const getContextualManifestoInstance = createCachedSelector(
8072export const getManifestoInstance = createSelector (
8173 getContextualManifestoInstance ,
8274 ( state , { json } ) => json ,
83- getLocale ,
84- ( manifesto , manifestJson , locale ) => (
75+ ( manifesto , manifestJson ) => (
8576 manifestJson && createManifestoInstance ( manifestJson , locale )
8677 ) || manifesto ,
8778) ;
8879
8980export const getManifestLocale = createSelector (
90- [ getManifestoInstance ] ,
91- manifest => manifest && manifest . options && manifest . options . locale && manifest . options . locale . replace ( / - .* $ / , '' ) ,
81+ [ getManifestoInstance , getLocale ] ,
82+ ( manifest , locale ) => locale ?? ( manifest && manifest . options && manifest . options . locale && manifest . options . locale . replace ( / - .* $ / , '' ) ) ,
9283) ;
9384
9485/** */
@@ -114,7 +105,7 @@ export const getManifestProviderName = createSelector(
114105 ] ,
115106 ( provider , locale ) => provider
116107 && provider [ 0 ] . label
117- && PropertyValue . parse ( provider [ 0 ] . label , locale ) . getValue ( ) ,
108+ && PropertyValue . parse ( provider [ 0 ] . label ) . getValue ( locale ) ,
118109) ;
119110
120111/**
@@ -159,8 +150,8 @@ export const getManifestHomepage = createSelector(
159150 ( homepages , locale ) => homepages
160151 && asArray ( homepages ) . map ( homepage => (
161152 {
162- label : PropertyValue . parse ( homepage . label , locale )
163- . getValue ( ) ,
153+ label : PropertyValue . parse ( homepage . label )
154+ . getValue ( locale ) ,
164155 value : homepage . id || homepage [ '@id' ] ,
165156 }
166157 ) ) ,
@@ -175,11 +166,11 @@ export const getManifestHomepage = createSelector(
175166 * @returns {string|null }
176167 */
177168export const getManifestRenderings = createSelector (
178- [ getManifestoInstance ] ,
179- manifest => manifest
169+ [ getManifestoInstance , getManifestLocale ] ,
170+ ( manifest , locale ) => manifest
180171 && manifest . getRenderings ( ) . map ( rendering => (
181172 {
182- label : rendering . getLabel ( ) . getValue ( ) ,
173+ label : rendering . getLabel ( ) . getValue ( locale ) ,
183174 value : rendering . id ,
184175 }
185176 ) ) ,
@@ -202,8 +193,8 @@ export const getManifestSeeAlso = createSelector(
202193 && asArray ( seeAlso ) . map ( related => (
203194 {
204195 format : related . format ,
205- label : PropertyValue . parse ( related . label , locale )
206- . getValue ( ) ,
196+ label : PropertyValue . parse ( related . label )
197+ . getValue ( locale ) ,
207198 value : related . id || related [ '@id' ] ,
208199 }
209200 ) ) ,
@@ -243,8 +234,8 @@ export const getManifestRelated = createSelector(
243234 }
244235 : {
245236 format : related . format ,
246- label : PropertyValue . parse ( related . label , locale )
247- . getValue ( ) ,
237+ label : PropertyValue . parse ( related . label )
238+ . getValue ( locale ) ,
248239 value : related . id || related [ '@id' ] ,
249240 }
250241 ) ) ,
@@ -259,13 +250,13 @@ export const getManifestRelated = createSelector(
259250 * @returns {string|null }
260251 */
261252export const getRequiredStatement = createSelector (
262- [ getManifestoInstance ] ,
263- manifest => manifest
253+ [ getManifestoInstance , getManifestLocale ] ,
254+ ( manifest , locale ) => manifest
264255 && asArray ( manifest . getRequiredStatement ( ) )
265256 . filter ( l => l && l . getValues ( ) . some ( v => v ) )
266257 . map ( labelValuePair => ( {
267- label : ( labelValuePair . label && labelValuePair . label . getValue ( ) ) || null ,
268- values : labelValuePair . getValues ( ) ,
258+ label : ( labelValuePair . label && labelValuePair . label . getValue ( locale ) ) || null ,
259+ values : labelValuePair . getValues ( locale ) ,
269260 } ) ) ,
270261) ;
271262
@@ -285,7 +276,7 @@ export const getRights = createSelector(
285276 ] ,
286277 ( rights , license , locale ) => {
287278 const data = rights || license ;
288- return asArray ( PropertyValue . parse ( data , locale ) . getValues ( ) ) ;
279+ return asArray ( PropertyValue . parse ( data ) . getValues ( locale ) ) ;
289280 } ,
290281) ;
291282
@@ -319,9 +310,9 @@ export function getManifestThumbnail(state, props) {
319310 * @returns {string }
320311 */
321312export const getManifestTitle = createSelector (
322- [ getManifestoInstance ] ,
323- manifest => manifest
324- && manifest . getLabel ( ) . getValue ( ) ,
313+ [ getManifestoInstance , getManifestLocale ] ,
314+ ( manifest , locale ) => manifest
315+ && manifest . getLabel ( ) . getValue ( locale ) ,
325316) ;
326317
327318/**
@@ -352,7 +343,7 @@ export const getManifestSummary = createSelector(
352343 getManifestLocale ,
353344 ] ,
354345 ( summary , locale ) => summary
355- && PropertyValue . parse ( summary , locale ) . getValue ( locale ) ,
346+ && PropertyValue . parse ( summary ) . getValue ( locale ) ,
356347) ;
357348
358349/**
@@ -377,11 +368,11 @@ export const getManifestUrl = createSelector(
377368 * @param iiifResource
378369 * @returns {Array[Object] }
379370 */
380- export function getDestructuredMetadata ( iiifResource ) {
371+ export function getDestructuredMetadata ( iiifResource , locale = undefined ) {
381372 return ( iiifResource
382373 && iiifResource . getMetadata ( ) . map ( labelValuePair => ( {
383- label : labelValuePair . getLabel ( ) ,
384- values : labelValuePair . getValues ( ) ,
374+ label : labelValuePair . getLabel ( locale ) ,
375+ values : labelValuePair . getValues ( locale ) ,
385376 } ) )
386377 ) ;
387378}
@@ -395,8 +386,8 @@ export function getDestructuredMetadata(iiifResource) {
395386 * @returns {Array[Object] }
396387 */
397388export const getManifestMetadata = createSelector (
398- [ getManifestoInstance ] ,
399- manifest => manifest && getDestructuredMetadata ( manifest ) ,
389+ [ getManifestoInstance , getManifestLocale ] ,
390+ ( manifest , locale ) => manifest && getDestructuredMetadata ( manifest , locale ) ,
400391) ;
401392
402393/** */
0 commit comments