Skip to content

Commit

Permalink
Clean up useHydratedStore
Browse files Browse the repository at this point in the history
Move store clean-up into `ClassifierContainer`. `useHydratedStore` hydrates the store but doesn't try to alter it after loading it.
  • Loading branch information
eatyourgreens committed Feb 8, 2022
1 parent 530bab8 commit 852f74f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,24 @@ export default function ClassifierContainer({
their defaults.
*/
if (loaded) {
const { classifications, subjects, workflows } = classifierStore
if (!workflows.active?.prioritized) {
/*
In this case, we delete the saved queue so that
refreshing the classifier will load a new, randomised
subject queue.
*/
console.log('randomising the subject queue.')
subjects.reset()
}
if (subjects.active) {
/*
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)
}
console.log('setting classifier event callbacks')
const { classifications, subjects } = classifierStore
classifierStore.setOnAddToCollection(onAddToCollection)
classifications.setOnComplete(onCompleteClassification)
classifierStore.setOnSubjectChange(onSubjectChange)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,6 @@ async function hydrateStore(storageKey, classifierStore) {
whitelist: ['fieldGuide', 'projects', 'subjects', 'subjectSets', 'tutorials', 'workflows', 'workflowSteps']
})
console.log('store hydrated from local storage')
const { subjects, workflows } = classifierStore
if (!workflows.active?.prioritized) {
/*
In this case, we delete the saved queue so that
refreshing the classifier will load a new, randomised
subject queue.
*/
subjects.reset()
}
if (subjects.active) {
/*
This is a hack to start a new classification from a snapshot.
*/
subjects.setActiveSubject(subjects.active.id)
}
} catch (error) {
console.log('store snapshot error.')
console.error(error)
Expand Down

0 comments on commit 852f74f

Please sign in to comment.