Skip to content

Commit

Permalink
Add store.startClassification
Browse files Browse the repository at this point in the history
`store.startClassification` allows us to start a new classification automatically, when the subject queue advances, or manually, after loading a workflow from Panoptes.
  • Loading branch information
eatyourgreens committed Feb 8, 2022
1 parent 852f74f commit d3d9b95
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default function Classifier({
workflowSnapshot.subjectSet = subjectSetID
workflows.setResources([workflowSnapshot])
// TODO: the task area crashes without the following line. Why is that?
subjects.setActiveSubject(subjects.active?.id)
classifierStore.startClassification()
}
}, [workflowVersion])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default function ClassifierContainer({
This is a hack to start a new classification from a snapshot.
*/
console.log('store hydrated with active subject', subjects.active.id)
subjects.setActiveSubject(subjects.active.id)
classifierStore.startClassification()
}
console.log('setting classifier event callbacks')
classifierStore.setOnAddToCollection(onAddToCollection)
Expand Down
33 changes: 17 additions & 16 deletions packages/lib-classifier/src/store/RootStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const RootStore = types
function _addMiddleware(call, next, abort) {
if (call.name === 'setActiveSubject') {
const res = next(call)
onSubjectAdvance()
self.startClassification()
return res
}
return next(call)
Expand All @@ -77,20 +77,6 @@ const RootStore = types
}
}

function onSubjectAdvance () {
const { classifications, feedback, projects, subjects, workflows, workflowSteps } = self
const subject = tryReference(() => subjects?.active)
const workflow = tryReference(() => workflows?.active)
const project = tryReference(() => projects?.active)
if (subject && workflow && project) {
workflowSteps.resetSteps()
classifications.reset()
classifications.createClassification(subject, workflow, project)
feedback.onNewSubject()
self.onSubjectChange(getSnapshot(subject))
}
}

// Public actions
function afterCreate () {
addMiddleware(self, _addMiddleware)
Expand All @@ -114,12 +100,27 @@ const RootStore = types
self.onToggleFavourite = callback
}

function startClassification() {
const { classifications, feedback, projects, subjects, workflows, workflowSteps } = self
const subject = tryReference(() => subjects?.active)
const workflow = tryReference(() => workflows?.active)
const project = tryReference(() => projects?.active)
if (subject && workflow && project) {
workflowSteps.resetSteps()
classifications.reset()
classifications.createClassification(subject, workflow, project)
feedback.onNewSubject()
self.onSubjectChange(getSnapshot(subject))
}
}

return {
afterCreate,
setLocale,
setOnAddToCollection,
setOnSubjectChange,
setOnToggleFavourite
setOnToggleFavourite,
startClassification
}
})

Expand Down

0 comments on commit d3d9b95

Please sign in to comment.