aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/services/content/Services.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/services/content/Services.tsx')
-rw-r--r--src/components/services/content/Services.tsx162
1 files changed, 162 insertions, 0 deletions
diff --git a/src/components/services/content/Services.tsx b/src/components/services/content/Services.tsx
new file mode 100644
index 000000000..53cddd907
--- /dev/null
+++ b/src/components/services/content/Services.tsx
@@ -0,0 +1,162 @@
1import { Component, ReactElement } from 'react';
2import { observer } from 'mobx-react';
3import { Link } from 'react-router-dom';
4import { defineMessages, injectIntl, WrappedComponentProps } from 'react-intl';
5import Confetti from 'react-confetti';
6import ms from 'ms';
7import withStyles, { WithStylesProps } from 'react-jss';
8import ServiceView from './ServiceView';
9import Appear from '../../ui/effects/Appear';
10import Service from '../../../models/Service';
11
12const messages = defineMessages({
13 getStarted: {
14 id: 'services.getStarted',
15 defaultMessage: 'Get started',
16 },
17 login: {
18 id: 'services.login',
19 defaultMessage: 'Please login to use Ferdium.',
20 },
21 serverless: {
22 id: 'services.serverless',
23 defaultMessage: 'Use Ferdium without an Account',
24 },
25 serverInfo: {
26 id: 'services.serverInfo',
27 defaultMessage:
28 '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!',
29 },
30});
31
32const styles = {
33 confettiContainer: {
34 position: 'absolute',
35 width: '100%',
36 zIndex: 9999,
37 pointerEvents: 'none',
38 },
39};
40
41interface IProps extends WrappedComponentProps, WithStylesProps<typeof styles> {
42 services?: Service[];
43 setWebviewReference: () => void;
44 detachService: () => void;
45 handleIPCMessage: () => void;
46 openWindow: () => void;
47 reload: (options: { serviceId: string }) => void;
48 openSettings: (options: { path: string }) => void;
49 update: (options: {
50 serviceId: string;
51 serviceData: { isEnabled: boolean };
52 redirect: boolean;
53 }) => void;
54 userHasCompletedSignup: boolean;
55 isSpellcheckerEnabled: boolean;
56}
57
58interface IState {
59 showConfetti: boolean;
60}
61
62@observer
63class Services extends Component<IProps, IState> {
64 _confettiTimeout: number | null = null;
65
66 constructor(props: IProps) {
67 super(props);
68
69 this.state = {
70 showConfetti: true,
71 };
72 }
73
74 componentDidMount(): void {
75 this._confettiTimeout = window.setTimeout(() => {
76 this.setState({
77 showConfetti: false,
78 });
79 }, ms('8s'));
80 }
81
82 componentWillUnmount(): void {
83 if (this._confettiTimeout) {
84 clearTimeout(this._confettiTimeout);
85 }
86 }
87
88 render(): ReactElement {
89 const {
90 services = [],
91 handleIPCMessage,
92 setWebviewReference,
93 detachService,
94 openWindow,
95 reload,
96 openSettings,
97 update,
98 userHasCompletedSignup,
99 classes,
100 isSpellcheckerEnabled,
101 intl,
102 } = this.props;
103
104 const { showConfetti } = this.state;
105
106 return (
107 <div className="services">
108 {userHasCompletedSignup && (
109 <div className={classes.confettiContainer}>
110 <Confetti
111 width={window.innerWidth}
112 height={window.innerHeight}
113 numberOfPieces={showConfetti ? 200 : 0}
114 />
115 </div>
116 )}
117 {services.length === 0 && (
118 <Appear transitionName="slideUp">
119 <div className="services__no-service">
120 <img
121 src="./assets/images/logo-beard-only.svg"
122 alt="Logo"
123 style={{ maxHeight: '50vh' }}
124 />
125 <Appear transitionName="slideUp">
126 <Link to="/settings/recipes" className="button">
127 {intl.formatMessage(messages.getStarted)}
128 </Link>
129 </Appear>
130 </div>
131 </Appear>
132 )}
133 {services
134 .filter(service => !service.isTodosService)
135 .map(service => (
136 <ServiceView
137 key={service.id}
138 service={service}
139 handleIPCMessage={handleIPCMessage}
140 setWebviewReference={setWebviewReference}
141 detachService={detachService}
142 openWindow={openWindow}
143 reload={() => reload({ serviceId: service.id })}
144 edit={() => openSettings({ path: `services/edit/${service.id}` })}
145 enable={() =>
146 update({
147 serviceId: service.id,
148 serviceData: {
149 isEnabled: true,
150 },
151 redirect: false,
152 })
153 }
154 isSpellcheckerEnabled={isSpellcheckerEnabled}
155 />
156 ))}
157 </div>
158 );
159 }
160}
161
162export default injectIntl(withStyles(styles, { injectTheme: true })(Services));