From 98a429da5a0c3b6c31d92bf116e32529f5c623c2 Mon Sep 17 00:00:00 2001 From: Rebecca Black Date: Thu, 16 May 2024 21:47:43 -0400 Subject: [PATCH 1/4] updated DocumentView component to handle the global state updating --- editioncrafter/src/component/DocumentView.js | 51 ++++++++++++++++---- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/editioncrafter/src/component/DocumentView.js b/editioncrafter/src/component/DocumentView.js index bb3ffa4..2268cc2 100644 --- a/editioncrafter/src/component/DocumentView.js +++ b/editioncrafter/src/component/DocumentView.js @@ -39,6 +39,37 @@ const DocumentView = (props) => { navigate(pathname + location.search); }; + useEffect(() => { + const reloadDocument = async (document) => { + if (!document.loaded) { + // handle the case where we've passed in an array of manifest URLs, in which case the `variorum` parameter should be set to `true` + if (document.variorum) { + const variorumData = {}; + for (const key of Object.keys(document.manifestURL)) { + const response = await fetch(document.manifestURL[key]).then((res) => (res.json())); + variorumData[key] = response.data; + } + const variorumManifest = { + type: 'variorum', + documentData: variorumData, + }; + return variorumManifest; + } + const singleResponse = await fetch(document.manifestURL).then((res) => (res.json())); + return singleResponse; + } + + return null; + }; + // if the top-level component props have been updated such that the document initial state has been reinitialized, dispatch the loadDocument action with the new data + if (!props.document.loaded) { + reloadDocument(props.document).then((res) => { + console.log('reload', res); + dispatchAction(props, 'DocumentActions.loadDocument', res); + }); + } + }, [props.config]); + const getViewports = () => { const { folioID, transcriptionType, folioID2, transcriptionType2, folioID3, transcriptionType3 @@ -62,19 +93,21 @@ const DocumentView = (props) => { } }; } - - const leftFolioID = folioID; + const leftFolioValid = Object.keys(document.folioIndex).includes(folioID); + const leftFolioID = leftFolioValid ? folioID : '-1'; let leftTranscriptionType; let rightFolioID; let rightTranscriptionType; let thirdFolioID; let thirdTranscriptionType; if (folioID2) { // route /ec/:folioID/:transcriptionType/:folioID2/:transcriptionType2 - leftTranscriptionType = transcriptionType; - rightFolioID = folioID2; - rightTranscriptionType = transcriptionType2 || firstTranscriptionType; + const rightFolioValid = Object.keys(document.folioIndex).includes(folioID2); + leftTranscriptionType = leftFolioValid ? transcriptionType : 'g'; + rightFolioID = rightFolioValid ? folioID2 : '-1'; + rightTranscriptionType = rightFolioValid ? transcriptionType2 ? transcriptionType2 : firstTranscriptionType : 'g'; if (folioID3) { // route /ec/:folioID/:transcriptionType/:folioID2/:transcriptionType2/:folioID3/:transcriptionType3 - thirdFolioID = folioID3; - thirdTranscriptionType = transcriptionType3 || firstTranscriptionType; + const thirdFolioValid = Object.keys(document.folioIndex).includes(folioID3); + thirdFolioID = thirdFolioValid ? folioID3 : '-1'; + thirdTranscriptionType = thirdFolioValid ? transcriptionType3 ? transcriptionType3 : firstTranscriptionType : 'g'; } else { thirdFolioID = '-1'; thirdTranscriptionType = 'g'; @@ -83,8 +116,8 @@ const DocumentView = (props) => { // route /ec/:folioID // route /ec/:folioID/:transcriptionType leftTranscriptionType = 'f'; - rightFolioID = folioID; - rightTranscriptionType = transcriptionType || firstTranscriptionType; + rightFolioID = leftFolioValid ? folioID : '-1'; + rightTranscriptionType = leftFolioValid ? transcriptionType ? transcriptionType : firstTranscriptionType : 'g'; thirdFolioID = '-1'; thirdTranscriptionType = 'g'; } From c487f0d4d4c064f271f21092095c2da6f48f0bc3 Mon Sep 17 00:00:00 2001 From: Rebecca Black Date: Thu, 16 May 2024 21:59:17 -0400 Subject: [PATCH 2/4] add glossary reload as well --- editioncrafter/src/component/DocumentView.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/editioncrafter/src/component/DocumentView.js b/editioncrafter/src/component/DocumentView.js index 2268cc2..e83294a 100644 --- a/editioncrafter/src/component/DocumentView.js +++ b/editioncrafter/src/component/DocumentView.js @@ -61,13 +61,25 @@ const DocumentView = (props) => { return null; }; + + const reloadGlossary = async (glossary) => { + if (!glossary.loaded && glossary.URL) { + const glossaryData = fetch(glossary.URL).then((res) => (res.json())); + return glossaryData; + } + } // if the top-level component props have been updated such that the document initial state has been reinitialized, dispatch the loadDocument action with the new data if (!props.document.loaded) { reloadDocument(props.document).then((res) => { - console.log('reload', res); dispatchAction(props, 'DocumentActions.loadDocument', res); }); } + // update the glossary as well if necessary + if (!props.glossary.loaded && props.glossary.URL) { + reloadGlossary(props.glossary).then((res) => { + dispatchAction(props, 'GlossaryActions.loadGlossary', res); + }) + } }, [props.config]); const getViewports = () => { @@ -535,6 +547,7 @@ const DocumentView = (props) => { function mapStateToProps(state) { return { document: state.document, + glossary: state.glossary }; } From c8da099b4f7f05c21ae436afb3a63694b746840e Mon Sep 17 00:00:00 2001 From: Rebecca Black Date: Thu, 16 May 2024 22:00:21 -0400 Subject: [PATCH 3/4] update gitignore to ignore github workflows --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 4fb48d9..0ce313e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ __tests__/integration/editioncrafter/css/ .cache/ storybook-static .DS_Store +.github From 88a560d695df9c5c423710651bfbd0b2ed90a3d0 Mon Sep 17 00:00:00 2001 From: Rebecca Black Date: Thu, 16 May 2024 22:04:20 -0400 Subject: [PATCH 4/4] added state change proof of concept story --- .../stories/EditionCrafter.stories.js | 73 +++++++++++++++---- 1 file changed, 60 insertions(+), 13 deletions(-) diff --git a/editioncrafter/stories/EditionCrafter.stories.js b/editioncrafter/stories/EditionCrafter.stories.js index d3208bb..c02c833 100644 --- a/editioncrafter/stories/EditionCrafter.stories.js +++ b/editioncrafter/stories/EditionCrafter.stories.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useEffect, useState } from 'react'; import EditionCrafter from '../src/index'; export const BowInTheCloud = () => ( @@ -57,25 +57,49 @@ export const IntervistePescatori = () => ( /> ); -export const MultiDocument = () => ( +export const OrnamentDesignTranslation = () => ( @@ -107,6 +131,29 @@ export const fullScreen = () => ( ) +export const stateChange = () => { + const [manifest, setManifest] = useState('https://cu-mkp.github.io/editioncrafter/taos-baptisms-example/iiif/manifest.json'); + const [glossary, setGlossary] = useState(undefined); + + useEffect(() => { + setTimeout(() => { + setManifest('https://cu-mkp.github.io/dyngleyfamily-editioncrafter-data/O_8_35/iiif/manifest.json'); + setGlossary('https://cu-mkp.github.io/editioncrafter-data/fr640_3r-3v-example/glossary.json'); + }, 10000); + }, []) + + return () + +} + export default { title: 'EditionCrafter', };