diff options
author | Stefan Malzner <stefan@adlk.io> | 2017-10-13 12:29:40 +0200 |
---|---|---|
committer | Stefan Malzner <stefan@adlk.io> | 2017-10-13 12:29:40 +0200 |
commit | 58cda9cc7fb79ca9df6746de7f9662bc08dc156a (patch) | |
tree | 1211600c2a5d3b5f81c435c6896618111a611720 /src/containers/layout/AppLayoutContainer.js | |
download | ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.tar.gz ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.tar.zst ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.zip |
initial commit
Diffstat (limited to 'src/containers/layout/AppLayoutContainer.js')
-rw-r--r-- | src/containers/layout/AppLayoutContainer.js | 166 |
1 files changed, 166 insertions, 0 deletions
diff --git a/src/containers/layout/AppLayoutContainer.js b/src/containers/layout/AppLayoutContainer.js new file mode 100644 index 000000000..aa7f7952a --- /dev/null +++ b/src/containers/layout/AppLayoutContainer.js | |||
@@ -0,0 +1,166 @@ | |||
1 | import React, { Component } from 'react'; | ||
2 | import PropTypes from 'prop-types'; | ||
3 | import { inject, observer } from 'mobx-react'; | ||
4 | |||
5 | import AppStore from '../../stores/AppStore'; | ||
6 | import RecipesStore from '../../stores/RecipesStore'; | ||
7 | import ServicesStore from '../../stores/ServicesStore'; | ||
8 | import UIStore from '../../stores/UIStore'; | ||
9 | import NewsStore from '../../stores/NewsStore'; | ||
10 | import UserStore from '../../stores/UserStore'; | ||
11 | import RequestStore from '../../stores/RequestStore'; | ||
12 | import GlobalErrorStore from '../../stores/GlobalErrorStore'; | ||
13 | |||
14 | import { oneOrManyChildElements } from '../../prop-types'; | ||
15 | import AppLayout from '../../components/layout/AppLayout'; | ||
16 | import Sidebar from '../../components/layout/Sidebar'; | ||
17 | import Services from '../../components/services/content/Services'; | ||
18 | import AppLoader from '../../components/ui/AppLoader'; | ||
19 | |||
20 | @inject('stores', 'actions') @observer | ||
21 | export default class AppLayoutContainer extends Component { | ||
22 | static defaultProps = { | ||
23 | children: null, | ||
24 | }; | ||
25 | |||
26 | render() { | ||
27 | const { | ||
28 | app, | ||
29 | services, | ||
30 | ui, | ||
31 | news, | ||
32 | globalError, | ||
33 | user, | ||
34 | requests, | ||
35 | } = this.props.stores; | ||
36 | |||
37 | const { | ||
38 | setActive, | ||
39 | handleIPCMessage, | ||
40 | setWebviewReference, | ||
41 | openWindow, | ||
42 | reloadUpdatedServices, | ||
43 | reorder, | ||
44 | reload, | ||
45 | toggleNotifications, | ||
46 | deleteService, | ||
47 | updateService, | ||
48 | } = this.props.actions.service; | ||
49 | |||
50 | const { hide } = this.props.actions.news; | ||
51 | |||
52 | const { retryRequiredRequests } = this.props.actions.requests; | ||
53 | |||
54 | const { | ||
55 | installUpdate, | ||
56 | } = this.props.actions.app; | ||
57 | |||
58 | const { | ||
59 | openSettings, | ||
60 | closeSettings, | ||
61 | } = this.props.actions.ui; | ||
62 | |||
63 | const { children } = this.props; | ||
64 | const allServices = services.enabled; | ||
65 | |||
66 | const isLoadingServices = services.allServicesRequest.isExecuting | ||
67 | && services.allServicesRequest.isExecutingFirstTime; | ||
68 | |||
69 | // const isLoadingRecipes = recipes.allRecipesRequest.isExecuting | ||
70 | // && recipes.allRecipesRequest.isExecutingFirstTime; | ||
71 | |||
72 | if (isLoadingServices) { | ||
73 | return ( | ||
74 | <AppLoader /> | ||
75 | ); | ||
76 | } | ||
77 | |||
78 | const sidebar = ( | ||
79 | <Sidebar | ||
80 | services={allServices} | ||
81 | setActive={setActive} | ||
82 | openSettings={openSettings} | ||
83 | closeSettings={closeSettings} | ||
84 | reorder={reorder} | ||
85 | reload={reload} | ||
86 | toggleNotifications={toggleNotifications} | ||
87 | deleteService={deleteService} | ||
88 | updateService={updateService} | ||
89 | isPremiumUser={user.data.isPremium} | ||
90 | /> | ||
91 | ); | ||
92 | |||
93 | const servicesContainer = ( | ||
94 | <Services | ||
95 | // settings={allSettings} | ||
96 | services={allServices} | ||
97 | handleIPCMessage={handleIPCMessage} | ||
98 | setWebviewReference={setWebviewReference} | ||
99 | openWindow={openWindow} | ||
100 | /> | ||
101 | ); | ||
102 | |||
103 | return ( | ||
104 | <AppLayout | ||
105 | isOnline={app.isOnline} | ||
106 | showServicesUpdatedInfoBar={ui.showServicesUpdatedInfoBar} | ||
107 | appUpdateIsDownloaded={app.updateStatus === app.updateStatusTypes.DOWNLOADED} | ||
108 | sidebar={sidebar} | ||
109 | services={servicesContainer} | ||
110 | news={news.latest} | ||
111 | removeNewsItem={hide} | ||
112 | reloadServicesAfterUpdate={reloadUpdatedServices} | ||
113 | installAppUpdate={installUpdate} | ||
114 | globalError={globalError.error} | ||
115 | showRequiredRequestsError={requests.showRequiredRequestsError} | ||
116 | areRequiredRequestsSuccessful={requests.areRequiredRequestsSuccessful} | ||
117 | retryRequiredRequests={retryRequiredRequests} | ||
118 | areRequiredRequestsLoading={requests.areRequiredRequestsLoading} | ||
119 | > | ||
120 | {React.Children.count(children) > 0 ? children : null} | ||
121 | </AppLayout> | ||
122 | ); | ||
123 | } | ||
124 | } | ||
125 | |||
126 | AppLayoutContainer.wrappedComponent.propTypes = { | ||
127 | stores: PropTypes.shape({ | ||
128 | services: PropTypes.instanceOf(ServicesStore).isRequired, | ||
129 | recipes: PropTypes.instanceOf(RecipesStore).isRequired, | ||
130 | app: PropTypes.instanceOf(AppStore).isRequired, | ||
131 | ui: PropTypes.instanceOf(UIStore).isRequired, | ||
132 | news: PropTypes.instanceOf(NewsStore).isRequired, | ||
133 | user: PropTypes.instanceOf(UserStore).isRequired, | ||
134 | requests: PropTypes.instanceOf(RequestStore).isRequired, | ||
135 | globalError: PropTypes.instanceOf(GlobalErrorStore).isRequired, | ||
136 | }).isRequired, | ||
137 | actions: PropTypes.shape({ | ||
138 | service: PropTypes.shape({ | ||
139 | setActive: PropTypes.func.isRequired, | ||
140 | reload: PropTypes.func.isRequired, | ||
141 | toggleNotifications: PropTypes.func.isRequired, | ||
142 | handleIPCMessage: PropTypes.func.isRequired, | ||
143 | setWebviewReference: PropTypes.func.isRequired, | ||
144 | openWindow: PropTypes.func.isRequired, | ||
145 | reloadUpdatedServices: PropTypes.func.isRequired, | ||
146 | updateService: PropTypes.func.isRequired, | ||
147 | deleteService: PropTypes.func.isRequired, | ||
148 | reorder: PropTypes.func.isRequired, | ||
149 | }).isRequired, | ||
150 | news: PropTypes.shape({ | ||
151 | hide: PropTypes.func.isRequired, | ||
152 | }).isRequired, | ||
153 | ui: PropTypes.shape({ | ||
154 | openSettings: PropTypes.func.isRequired, | ||
155 | closeSettings: PropTypes.func.isRequired, | ||
156 | }).isRequired, | ||
157 | app: PropTypes.shape({ | ||
158 | installUpdate: PropTypes.func.isRequired, | ||
159 | healthCheck: PropTypes.func.isRequired, | ||
160 | }).isRequired, | ||
161 | requests: PropTypes.shape({ | ||
162 | retryRequiredRequests: PropTypes.func.isRequired, | ||
163 | }).isRequired, | ||
164 | }).isRequired, | ||
165 | children: oneOrManyChildElements, | ||
166 | }; | ||