From a38f24f1c474879afb3f75b79fd3b9506c4f3879 Mon Sep 17 00:00:00 2001 From: dananji Date: Fri, 1 Sep 2023 16:19:55 -0400 Subject: [PATCH] Fix code from rebase --- src/components/IIIFPlayerWrapper.js | 7 - src/components/MediaPlayer/MediaPlayer.js | 14 +- .../MediaPlayer/MediaPlayer.test.js | 12 +- .../StructuredNavigation.js | 4 +- .../StructuredNavigation.test.js | 6 +- src/services/iiif-parser.js | 11 -- src/services/iiif-parser.test.js | 6 +- src/services/utility-helpers.test.js | 13 -- src/test_data/playlist.js | 121 ------------------ 9 files changed, 31 insertions(+), 163 deletions(-) diff --git a/src/components/IIIFPlayerWrapper.js b/src/components/IIIFPlayerWrapper.js index 92af8171..137b18e6 100644 --- a/src/components/IIIFPlayerWrapper.js +++ b/src/components/IIIFPlayerWrapper.js @@ -12,13 +12,6 @@ export default function IIIFPlayerWrapper({ const [manifestError, setManifestError] = React.useState(''); const dispatch = useManifestDispatch(); - React.useEffect(() => { - if (manifest) { - const isPlaylist = Object.values(manifest.label)[0][0].includes('[Playlist]') - dispatch({ isPlaylist: isPlaylist, type: 'isPlaylist' }) - } - }, [manifest]); - React.useEffect(() => { if (manifest) { dispatch({ manifest: manifest, type: 'updateManifest' }); diff --git a/src/components/MediaPlayer/MediaPlayer.js b/src/components/MediaPlayer/MediaPlayer.js index f99ac803..a986b346 100644 --- a/src/components/MediaPlayer/MediaPlayer.js +++ b/src/components/MediaPlayer/MediaPlayer.js @@ -33,9 +33,17 @@ const MediaPlayer = ({ enableFileDownload = false, enablePIP = false }) => { const [isMultiCanvased, setIsMultiCanvased] = React.useState(false); const [lastCanvasIndex, setLastCanvasIndex] = React.useState(0); const [isVideo, setIsVideo] = React.useState(); - const [isEmptyCanvas, setIsEmptyCanvas] = React.useState(false); - const { canvasIndex, manifest, canvasDuration, srcIndex, targets, autoAdvance, playlist } = + const { + canvasIndex, + manifest, + canvasDuration, + canvasIsEmpty, + srcIndex, + targets, + autoAdvance, + playlist + } = manifestState; const { player } = playerState; @@ -45,7 +53,7 @@ const MediaPlayer = ({ enableFileDownload = false, enablePIP = false }) => { // flag to identify multiple canvases in the manifest // to render previous/next buttons - const canvases = canvasCount(manifest); + const canvases = canvasesInManifest(manifest).length; setIsMultiCanvased(canvases > 1 ? true : false); setLastCanvasIndex(canvases - 1); } diff --git a/src/components/MediaPlayer/MediaPlayer.test.js b/src/components/MediaPlayer/MediaPlayer.test.js index d66354eb..82f92ffd 100644 --- a/src/components/MediaPlayer/MediaPlayer.test.js +++ b/src/components/MediaPlayer/MediaPlayer.test.js @@ -114,7 +114,11 @@ describe('MediaPlayer component', () => { window.HTMLMediaElement.prototype.load = () => { }; const PlayerWithManifest = withManifestAndPlayerProvider(MediaPlayer, { - initialManifestState: { manifest: playlistManifest, canvasIndex: 0, isPlaylist: true }, + initialManifestState: { + manifest: playlistManifest, + canvasIndex: 0, + playlist: { isPlaylist: true } + }, initialPlayerState: {}, }); render(); @@ -124,7 +128,11 @@ describe('MediaPlayer component', () => { test('renders player for a accessible Canvas', () => { const PlayerWithManifest = withManifestAndPlayerProvider(MediaPlayer, { - initialManifestState: { manifest: playlistManifest, canvasIndex: 1, isPlaylist: true }, + initialManifestState: { + manifest: playlistManifest, + canvasIndex: 1, + playlist: { isPlaylist: true } + }, initialPlayerState: {}, }); render(); diff --git a/src/components/StructuredNavigation/StructuredNavigation.js b/src/components/StructuredNavigation/StructuredNavigation.js index a4e91521..5049f2ac 100644 --- a/src/components/StructuredNavigation/StructuredNavigation.js +++ b/src/components/StructuredNavigation/StructuredNavigation.js @@ -22,7 +22,7 @@ const StructuredNavigation = () => { const playerDispatch = usePlayerDispatch(); const { clickedUrl, isClicked, isPlaying, player } = usePlayerState(); - const { canvasDuration, canvasIndex, hasMultiItems, targets, manifest, isPlaylist, canvasIsEmpty } = + const { canvasDuration, canvasIndex, hasMultiItems, targets, manifest, playlist, canvasIsEmpty } = useManifestState(); const [canvasSegments, setCanvasSegments] = React.useState([]); @@ -51,7 +51,7 @@ const StructuredNavigation = () => { // Set currentNavItem when current Canvas is an inaccessible item React.useEffect(() => { - if (canvasIsEmpty && isPlaylist) { + if (canvasIsEmpty && playlist.isPlaylist) { manifestDispatch({ item: canvasSegments[canvasIndex], type: 'switchItem' }); } }, [canvasIsEmpty, canvasIndex]); diff --git a/src/components/StructuredNavigation/StructuredNavigation.test.js b/src/components/StructuredNavigation/StructuredNavigation.test.js index 91c47197..30949dac 100644 --- a/src/components/StructuredNavigation/StructuredNavigation.test.js +++ b/src/components/StructuredNavigation/StructuredNavigation.test.js @@ -105,7 +105,11 @@ describe('StructuredNavigation component', () => { describe('with a playlist manifest', () => { beforeEach(() => { const NavWithPlayerAndManifest = withManifestAndPlayerProvider(StructuredNavigation, { - initialManifestState: { manifest: playlist, isPlaylist: true, canvasIsEmpty: true }, + initialManifestState: { + manifest: playlist, + playlist: { isPlaylist: true }, + canvasIsEmpty: true + }, initialPlayerState: { playerRange: { start: null, end: null } }, }); render(); diff --git a/src/services/iiif-parser.js b/src/services/iiif-parser.js index 15aa0728..69968c11 100644 --- a/src/services/iiif-parser.js +++ b/src/services/iiif-parser.js @@ -33,17 +33,6 @@ export function canvasesInManifest(manifest) { return canvases; } -export function canvasCount(manifest) { - try { - return parseManifest(manifest) - .getSequences()[0] - .getCanvases().length; - } catch (err) { - console.error('Error reading given Manifest, ', err); - return 0; - } -} - /** * Check if item's behavior is set to a value which should hide it * @param {Object} item diff --git a/src/services/iiif-parser.test.js b/src/services/iiif-parser.test.js index 24247141..3d437869 100644 --- a/src/services/iiif-parser.test.js +++ b/src/services/iiif-parser.test.js @@ -434,7 +434,6 @@ describe('iiif-parser', () => { }); }); -<<<<<<< HEAD describe('parseAutoAdvance()', () => { describe('with manifest without auto-advance behavior', () => { it('should return true', () => { @@ -492,7 +491,9 @@ describe('iiif-parser', () => { id: 'http://example.com/manifests/playlist/canvas/2/marker/3', canvasId: 'http://example.com/manifests/playlist/canvas/2' }); -======= + }); + }); + describe('inaccessibleItemMessage()', () => { it('returns text under placeholderCanvas', () => { const itemMessage = iiifParser.inaccessibleItemMessage(manifest, 1); @@ -507,7 +508,6 @@ describe('iiif-parser', () => { if ('returns null when no placeholderCanvas is in the Canvas', () => { const itemMessage = iiifParser.inaccessibleItemMessage(singleSrcManifest, 0); expect(itemMessage).toBeNull(); ->>>>>>> 9aafd36 (Fix broken tests) }); }); }); diff --git a/src/services/utility-helpers.test.js b/src/services/utility-helpers.test.js index f03023e7..002c3e67 100644 --- a/src/services/utility-helpers.test.js +++ b/src/services/utility-helpers.test.js @@ -13,19 +13,6 @@ describe('util helper', () => { }); }); -<<<<<<< HEAD -======= - describe('createTimestamp()', () => { - test('with hours', () => { - expect(util.createTimestamp(557.65, true)).toEqual('00:09:17'); - }); - - test('without hours', () => { - expect(util.createTimestamp(557.65, false)).toEqual('09:17'); - }); - }); - ->>>>>>> 9aafd36 (Fix broken tests) describe('getCanvasTarget()', () => { const targets = [ { start: 0, end: 2455, altStart: 0, duration: 2455, sIndex: 0 }, diff --git a/src/test_data/playlist.js b/src/test_data/playlist.js index 92940d87..89f74151 100644 --- a/src/test_data/playlist.js +++ b/src/test_data/playlist.js @@ -18,40 +18,18 @@ export default { { id: 'http://example.com/manifests/playlist/canvas/1', type: 'Canvas', -<<<<<<< HEAD - duration: 572.034, - label: { - en: ["Lunchroom Manners"] -======= label: { en: ["Restricted Item"] ->>>>>>> 9aafd36 (Fix broken tests) }, placeholderCanvas: { id: 'http://example.com/manifests/playlist/canvas/1/placeholder', type: "Canvas", -<<<<<<< HEAD - width: 640, - height: 360, -======= ->>>>>>> 9aafd36 (Fix broken tests) items: [ { id: 'http://example.com/manifests/playlist/canvas/1/placeholder/1', type: "AnnotationPage", items: [ { -<<<<<<< HEAD - id: 'http://example.com/manifests/playlist/canvas/1/placeholder/1-image', - type: "Annotation", - motivation: "painting", - body: { - id: 'http://example.com/lunchroom_manners/lunchroom_manners_poster.jpg', - type: "Image", - format: "image/jpeg", - width: 640, - height: 360 -======= id: 'http://example.com/manifests/playlist/canvas/2/placeholder/1-image', type: "Annotation", motivation: "painting", @@ -59,7 +37,6 @@ export default { type: "Text", format: "text/plain", label: { en: ['You do not have permission to playback this item.'] } ->>>>>>> 9aafd36 (Fix broken tests) }, target: 'http://example.com/manifests/playlist/canvas/1/placeholder' } @@ -71,93 +48,9 @@ export default { { id: 'http://example.com/manifests/playlist/canvas/1/page', type: 'AnnotationPage', -<<<<<<< HEAD - items: [ - { - id: 'http://example.com/manifests/playlist/canvas/1/page/annotation', - type: 'Annotation', - motivation: 'painting', - body: [ - { - type: 'Choice', - choiceHint: 'user', - items: [ - { - id: 'http://example.com/lunchroom_manners/high/lunchroom_manners_1024kb.mp4#t=0,572.0', - type: 'Video', - format: 'video/mp4', - label: { - en: ['High'], - }, - height: 360, - width: 480, - duration: 572.0 - }, - { - id: 'http://example.com/lunchroom_manners/medium/lunchroom_manners_512kb.mp4#t=0,572.0', - type: 'Video', - format: 'video/mp4', - label: { - en: ['Medium'], - }, - height: 360, - width: 480, - duration: 572.0 - }, - { - id: 'http://example.com/lunchroom_manners/low/lunchroom_manners_256kb.mp4#t=0,572.0', - type: 'Video', - format: 'video/mp4', - label: { - en: ['Low'], - }, - height: 360, - width: 480, - duration: 572.0 - }, - ], - }, - ], - target: 'http://example.com/manifests/playlist/canvas/1', - }, - ], - }, - ], - annotations: [ - { - type: "AnnotationPage", - id: 'http://example.com/manifests/playlist/canvas/1/annotation_page/1', - items: [ - { - type: "Annotation", - motivation: "highlighting", - body: { - type: "TextualBody", - format: "text/html", - value: "Marker 1" - }, - id: 'http://example.com/manifests/playlist/canvas/1/marker/1', - target: 'http://example.com/manifests/playlist/canvas/1#t=2.836', - }, - { - type: "Annotation", - motivation: "highlighting", - body: { - type: "TextualBody", - format: "text/html", - value: "Marker 2" - }, - id: 'http://example.com/manifests/playlist/canvas/1/marker/2', - target: 'http://example.com/manifests/playlist/canvas/1#t=369.811' - } - ] - } - ], -======= }, ], annotations: [], ->>>>>>> 9aafd36 (Fix broken tests) }, { id: 'http://example.com/manifests/playlist/canvas/2', @@ -249,8 +142,6 @@ export default { } ], }, -<<<<<<< HEAD -======= { id: 'http://example.com/manifests/playlist/canvas/3', type: 'Canvas', @@ -371,7 +262,6 @@ export default { } ], }, ->>>>>>> 9aafd36 (Fix broken tests) ], structures: [ { @@ -383,11 +273,7 @@ export default { { id: 'http://example.com/manifests/playlist/range/1', type: 'Range', -<<<<<<< HEAD - label: { en: ['Playlist Item 1'] }, -======= label: { en: ['Restricted Item'] }, ->>>>>>> 9aafd36 (Fix broken tests) items: [ { type: "Canvas", @@ -398,11 +284,7 @@ export default { { id: 'http://example.com/manifests/playlist/range/2', type: 'Range', -<<<<<<< HEAD - label: { en: ['Playlist Item 2'] }, -======= label: { en: ['Playlist Item 1'] }, ->>>>>>> 9aafd36 (Fix broken tests) items: [ { type: "Canvas", @@ -410,8 +292,6 @@ export default { } ] }, -<<<<<<< HEAD -======= { id: 'http://example.com/manifests/playlist/range/3', type: 'Range', @@ -423,7 +303,6 @@ export default { } ] }, ->>>>>>> 9aafd36 (Fix broken tests) ] } ]