-
Notifications
You must be signed in to change notification settings - Fork 29
/
Classifier.js
117 lines (104 loc) · 3.43 KB
/
Classifier.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import { GraphQLClient } from 'graphql-request'
import makeInspectable from 'mobx-devtools-mst'
import { Provider } from 'mobx-react'
import PropTypes from 'prop-types'
import React from 'react'
import zooTheme from '@zooniverse/grommet-theme'
import {
env,
panoptes as panoptesClient,
projects as projectsClient,
tutorials as tutorialsClient
} from '@zooniverse/panoptes-js'
// Pointer event API polyfill just for Safari 12
// Can likely be removed Sept 2020
import 'pepjs'
import { unregisterWorkers } from '../../workers'
import RootStore from '../../store'
import Layout from './components/Layout'
import ModalTutorial from './components/ModalTutorial'
// import { isBackgroundSyncAvailable } from '../../helpers/featureDetection'
function caesarClient (env) {
switch (env) {
case 'production': {
return new GraphQLClient('https://caesar.zooniverse.org/graphql')
}
default: {
return new GraphQLClient('https://caesar-staging.zooniverse.org/graphql')
}
}
}
const client = {
caesar: caesarClient(env),
panoptes: panoptesClient,
projects: projectsClient,
tutorials: tutorialsClient
}
// We don't register the queue service worker if background sync API is not available
// We might want to move this check elsewhere once we add other service workers for other tasks
// if (isBackgroundSyncAvailable()) registerWorkers()
// TODO: The workbox background sync queue isn't working as expected
// It doesn't work with superagent/XHR req for interception
// We need to migrate to fetch API, otherwise the POST will occur twice
// Once in our store, once in the worker
// So we'll unregister the worker for now.
unregisterWorkers('./queue.js')
export default class Classifier extends React.Component {
constructor (props) {
super(props)
this.classifierStore = RootStore.create({}, {
authClient: props.authClient,
client
})
makeInspectable(this.classifierStore)
}
componentDidMount () {
const { onAddToCollection, onCompleteClassification, onToggleFavourite, project, subjectSetID, workflowID } = this.props
this.setProject(project)
this.classifierStore.setOnAddToCollection(onAddToCollection)
this.classifierStore.classifications.setOnComplete(onCompleteClassification)
this.classifierStore.setOnToggleFavourite(onToggleFavourite)
this.classifierStore.workflows.selectWorkflow(workflowID, subjectSetID)
}
componentDidUpdate (prevProps) {
const { authClient, project } = this.props
if (project.id !== prevProps.project.id) {
this.setProject(project)
}
if (authClient) {
this.classifierStore.userProjectPreferences.checkForUser()
}
}
setProject (project) {
this.classifierStore.projects.setResources([project])
this.classifierStore.projects.setActive(project.id)
}
render () {
return (
<Provider classifierStore={this.classifierStore}>
<>
<Layout />
<ModalTutorial />
</>
</Provider>
)
}
}
Classifier.defaultProps = {
mode: 'light',
onAddToCollection: () => true,
onCompleteClassification: () => true,
onToggleFavourite: () => true,
theme: zooTheme
}
Classifier.propTypes = {
authClient: PropTypes.object.isRequired,
mode: PropTypes.string,
onAddToCollection: PropTypes.func,
onCompleteClassification: PropTypes.func,
onToggleFavourite: PropTypes.func,
project: PropTypes.shape({
id: PropTypes.string.isRequired
}).isRequired,
theme: PropTypes.object
}