1 | export const init = ({
|
2 | store,
|
3 | navigate,
|
4 | fullAPI
|
5 | }) => {
|
6 | const isSettingsScreenActive = () => {
|
7 | const {
|
8 | path
|
9 | } = fullAPI.getUrlState();
|
10 | return !!(path || '').match(/^\/settings/);
|
11 | };
|
12 |
|
13 | const api = {
|
14 | closeSettings: () => {
|
15 | const {
|
16 | settings: {
|
17 | lastTrackedStoryId
|
18 | }
|
19 | } = store.getState();
|
20 |
|
21 | if (lastTrackedStoryId) {
|
22 | fullAPI.selectStory(lastTrackedStoryId);
|
23 | } else {
|
24 | fullAPI.selectFirstStory();
|
25 | }
|
26 | },
|
27 | changeSettingsTab: tab => {
|
28 | navigate(`/settings/${tab}`);
|
29 | },
|
30 | isSettingsScreenActive,
|
31 | navigateToSettingsPage: async path => {
|
32 | if (!isSettingsScreenActive()) {
|
33 | const {
|
34 | settings,
|
35 | storyId
|
36 | } = store.getState();
|
37 | await store.setState({
|
38 | settings: Object.assign({}, settings, {
|
39 | lastTrackedStoryId: storyId
|
40 | })
|
41 | });
|
42 | }
|
43 |
|
44 | navigate(path);
|
45 | }
|
46 | };
|
47 |
|
48 | const initModule = async () => {
|
49 | await store.setState({
|
50 | settings: {
|
51 | lastTrackedStoryId: null
|
52 | }
|
53 | });
|
54 | };
|
55 |
|
56 | return {
|
57 | init: initModule,
|
58 | api
|
59 | };
|
60 | }; |
\ | No newline at end of file |