-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate UPP store in project app (#2238)
* Create new parent store for stats and UPP. Make it child of User. * Tests for UPP * Only request for UPP if not already present. Rewrite tests to be async. * Fix spec after rebase
- Loading branch information
Showing
12 changed files
with
644 additions
and
261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { addDisposer, getRoot, types } from 'mobx-state-tree' | ||
import { autorun } from 'mobx' | ||
import UserProjectPreferences from './UserProjectPreferences' | ||
import YourStats from './YourStats' | ||
|
||
const UserPersonalization = types | ||
.model('UserPersonalization', { | ||
projectPreferences: types.optional(UserProjectPreferences, {}), | ||
stats: types.optional(YourStats, {}), | ||
totalClassificationCount: 0 | ||
}) | ||
.volatile(self => ({ | ||
sessionCount: 0 | ||
})) | ||
.views(self => ({ | ||
get counts() { | ||
const todaysDate = new Date() | ||
let today | ||
try { | ||
const todaysCount = self.stats.thisWeek.length === 7 | ||
? self.stats.thisWeek[todaysDate.getDay() - 1].count | ||
: 0 | ||
today = todaysCount + self.sessionCount | ||
} catch (error) { | ||
today = 0 | ||
} | ||
|
||
return { | ||
today, | ||
total: self.totalClassificationCount | ||
} | ||
} | ||
})) | ||
.actions(self => { | ||
function createParentObserver() { | ||
const parentDisposer = autorun(() => { | ||
const { project, user } = getRoot(self) | ||
if (project.id && user.id) { | ||
self.projectPreferences.fetchResource() | ||
self.stats.fetchDailyCounts() | ||
} | ||
}) | ||
addDisposer(self, parentDisposer) | ||
} | ||
return { | ||
afterAttach() { | ||
createParentObserver() | ||
}, | ||
|
||
increment() { | ||
self.sessionCount = self.sessionCount + 1 | ||
self.totalClassificationCount = self.totalClassificationCount + 1 | ||
}, | ||
|
||
setTotalClassificationCount(count) { | ||
self.totalClassificationCount = count | ||
} | ||
} | ||
}) | ||
|
||
export default UserPersonalization |
Oops, something went wrong.