aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/services/content/Services.jsx
diff options
context:
space:
mode:
authorLibravatar Ricardo Cino <ricardo@cino.io>2022-07-07 09:31:50 +0200
committerLibravatar GitHub <noreply@github.com>2022-07-07 09:31:50 +0200
commit71c52373f81cace664047edd19d9d289f45a4dff (patch)
tree69b3f1d45a8b3f1ceab9497ea3c96e9dc18e3166 /src/components/services/content/Services.jsx
parent6.0.0-nightly.91 [skip ci] (diff)
downloadferdium-app-71c52373f81cace664047edd19d9d289f45a4dff.tar.gz
ferdium-app-71c52373f81cace664047edd19d9d289f45a4dff.tar.zst
ferdium-app-71c52373f81cace664047edd19d9d289f45a4dff.zip
chore: Mobx & React-Router upgrade (#406)
Co-authored-by: Vijay A <vraravam@users.noreply.github.com>
Diffstat (limited to 'src/components/services/content/Services.jsx')
-rw-r--r--src/components/services/content/Services.jsx165
1 files changed, 165 insertions, 0 deletions
diff --git a/src/components/services/content/Services.jsx b/src/components/services/content/Services.jsx
new file mode 100644
index 000000000..da700b5b1
--- /dev/null
+++ b/src/components/services/content/Services.jsx
@@ -0,0 +1,165 @@
1import { Component } from 'react';
2import PropTypes from 'prop-types';
3import { observer, PropTypes as MobxPropTypes, inject } from 'mobx-react';
4import { Link } from 'react-router-dom';
5import { defineMessages, injectIntl } from 'react-intl';
6import Confetti from 'react-confetti';
7import ms from 'ms';
8import injectSheet from 'react-jss';
9
10import ServiceView from './ServiceView';
11import Appear from '../../ui/effects/Appear';
12
13const messages = defineMessages({
14 getStarted: {
15 id: 'services.getStarted',
16 defaultMessage: 'Get started',
17 },
18 login: {
19 id: 'services.login',
20 defaultMessage: 'Please login to use Ferdium.',
21 },
22 serverless: {
23 id: 'services.serverless',
24 defaultMessage: 'Use Ferdium without an Account',
25 },
26 serverInfo: {
27 id: 'services.serverInfo',
28 defaultMessage:
29 'Optionally, you can change your Ferdium server by clicking the cog in the bottom left corner. If you are switching over (from one of the hosted servers) to using Ferdium without an account, please be informed that you can export your data from that server and subsequently import it using the Help menu to resurrect all your workspaces and configured services!',
30 },
31});
32
33const styles = {
34 confettiContainer: {
35 position: 'absolute',
36 width: '100%',
37 zIndex: 9999,
38 pointerEvents: 'none',
39 },
40};
41
42class Services extends Component {
43 static propTypes = {
44 services: MobxPropTypes.arrayOrObservableArray,
45 setWebviewReference: PropTypes.func.isRequired,
46 detachService: PropTypes.func.isRequired,
47 handleIPCMessage: PropTypes.func.isRequired,
48 openWindow: PropTypes.func.isRequired,
49 reload: PropTypes.func.isRequired,
50 openSettings: PropTypes.func.isRequired,
51 update: PropTypes.func.isRequired,
52 userHasCompletedSignup: PropTypes.bool.isRequired,
53 // eslint-disable-next-line react/forbid-prop-types
54 classes: PropTypes.object.isRequired,
55 isSpellcheckerEnabled: PropTypes.bool.isRequired,
56 };
57
58 static defaultProps = {
59 services: [],
60 };
61
62 _confettiTimeout = null;
63
64 constructor() {
65 super();
66
67 this.state = {
68 showConfetti: true,
69 };
70 }
71
72 componentDidMount() {
73 this._confettiTimeout = window.setTimeout(() => {
74 this.setState({
75 showConfetti: false,
76 });
77 }, ms('8s'));
78 }
79
80 componentWillUnmount() {
81 if (this._confettiTimeout) {
82 clearTimeout(this._confettiTimeout);
83 }
84 }
85
86 render() {
87 const {
88 services,
89 handleIPCMessage,
90 setWebviewReference,
91 detachService,
92 openWindow,
93 reload,
94 openSettings,
95 update,
96 userHasCompletedSignup,
97 classes,
98 isSpellcheckerEnabled,
99 } = this.props;
100
101 const { showConfetti } = this.state;
102
103 const { intl } = this.props;
104
105 return (
106 <div className="services">
107 {userHasCompletedSignup && (
108 <div className={classes.confettiContainer}>
109 <Confetti
110 width={window.width}
111 height={window.height}
112 numberOfPieces={showConfetti ? 200 : 0}
113 />
114 </div>
115 )}
116 {services.length === 0 && (
117 <Appear timeout={1500} transitionName="slideUp">
118 <div className="services__no-service">
119 <img
120 src="./assets/images/logo-beard-only.svg"
121 alt="Logo"
122 style={{ maxHeight: '50vh' }}
123 />
124 <Appear timeout={300} transitionName="slideUp">
125 <Link to="/settings/recipes" className="button">
126 {intl.formatMessage(messages.getStarted)}
127 </Link>
128 </Appear>
129 </div>
130 </Appear>
131 )}
132 {services
133 .filter(service => !service.isTodosService)
134 .map(service => (
135 <ServiceView
136 key={service.id}
137 service={service}
138 handleIPCMessage={handleIPCMessage}
139 setWebviewReference={setWebviewReference}
140 detachService={detachService}
141 openWindow={openWindow}
142 reload={() => reload({ serviceId: service.id })}
143 edit={() => openSettings({ path: `services/edit/${service.id}` })}
144 enable={() =>
145 update({
146 serviceId: service.id,
147 serviceData: {
148 isEnabled: true,
149 },
150 redirect: false,
151 })
152 }
153 isSpellcheckerEnabled={isSpellcheckerEnabled}
154 />
155 ))}
156 </div>
157 );
158 }
159}
160
161export default injectIntl(
162 injectSheet(styles, { injectTheme: true })(
163 inject('actions')(observer(Services)),
164 ),
165);