Skip to content

Commit

Permalink
Derive classifier props from URL params
Browse files Browse the repository at this point in the history
Set classify page state when URL params change. Derive classifier props from classify page state.
  • Loading branch information
eatyourgreens committed Mar 16, 2022
1 parent 9cb0b7d commit b2b6824
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/app-project/src/screens/ClassifyPage/ClassifyPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function ClassifyPage({
? ['auto']
: ['1em', 'auto', '1em']
const [classifierProps, setClassifierProps] = useState({})
const [showTutorial, setShowTutorial] = useState(false)

let subjectSetFromUrl
if (workflowFromUrl && workflowFromUrl.subjectSets) {
Expand All @@ -54,15 +55,20 @@ function ClassifyPage({
canClassify = isIndexed ? !!subjectID : canClassify

/*
Derive classifier state from the workflow in the URL, when the workflow changes.
Remember the previous classifier state if there's no workflow ID in the URL.
Derive classifier state from the URL, when the URL changes.
Use the previous classifier state if there's no workflow ID in the URL.
*/
if (canClassify && classifierProps.workflowID !== workflowID) {
const workflowChanged = classifierProps.workflowID !== workflowID
const subjectSetChanged = classifierProps.subjectSetID !== subjectSetID
const subjectChanged = classifierProps.subjectID !== subjectID
const URLChanged = workflowChanged || subjectSetChanged || subjectChanged
if (canClassify && URLChanged) {
setClassifierProps({
workflowID,
subjectSetID,
subjectID
})
setShowTutorial(true)
}

return (
Expand All @@ -88,7 +94,7 @@ function ClassifyPage({
cachePanoptesData={cachePanoptesData}
onAddToCollection={addToCollection}
onSubjectReset={onSubjectReset}
showTutorial={canClassify}
showTutorial={showTutorial}
{...classifierProps}
/>
<ThemeModeToggle />
Expand Down

0 comments on commit b2b6824

Please sign in to comment.