-
Notifications
You must be signed in to change notification settings - Fork 582
/
Services.js
136 lines (119 loc) · 3.42 KB
/
Services.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { observer } from 'mobx-react';
import { Link } from 'react-router';
import { defineMessages, intlShape } from 'react-intl';
import injectSheet from 'react-jss';
import { ipcRenderer } from 'electron';
import Appear from '../../ui/effects/Appear';
import { RESIZE_SERVICE_VIEWS } from '../../../ipcChannels';
import ServiceView from './ServiceView';
const messages = defineMessages({
welcome: {
id: 'services.welcome',
defaultMessage: '!!!Welcome to Franz',
},
getStarted: {
id: 'services.getStarted',
defaultMessage: '!!!Get started',
},
});
const styles = {
container: {
display: 'flex',
'&>span': {
display: 'block',
width: '100%',
},
},
};
export default @injectSheet(styles) @observer class Services extends Component {
static propTypes = {
activeService: PropTypes.object,
serviceCount: PropTypes.number.isRequired,
reload: PropTypes.func.isRequired,
openSettings: PropTypes.func.isRequired,
update: PropTypes.func.isRequired,
classes: PropTypes.object.isRequired,
};
static defaultProps = {
activeService: undefined,
}
static contextTypes = {
intl: intlShape,
};
serviceContainerRef = React.createRef()
resizeObserver = new window.ResizeObserver(([element]) => {
const bounds = element.target.getBoundingClientRect();
ipcRenderer.send(RESIZE_SERVICE_VIEWS, {
width: bounds.width,
height: bounds.height,
x: bounds.x,
y: element.target.offsetTop,
});
});
componentDidMount() {
this.resizeObserver.observe(this.serviceContainerRef.current);
}
componentWillUnmount() {
if (this._confettiTimeout) {
clearTimeout(this._confettiTimeout);
}
}
render() {
const {
activeService,
serviceCount,
reload,
openSettings,
update,
classes,
} = this.props;
const { intl } = this.context;
return (
<>
{serviceCount === 0 ? (
<div className={classes.container}>
<Appear
timeout={1500}
transitionName="slideUp"
>
<div className="services__no-service">
<img src="./assets/images/logo.svg" alt="" />
<h1>{intl.formatMessage(messages.welcome)}</h1>
<Appear
timeout={300}
transitionName="slideUp"
>
<Link to="/settings/recipes" className="button">
{intl.formatMessage(messages.getStarted)}
</Link>
</Appear>
</div>
</Appear>
</div>
) : (
<>
{activeService && (
<ServiceView
key={activeService.id}
service={activeService}
reload={() => reload({ serviceId: activeService.id })}
edit={() => openSettings({ path: `services/edit/${activeService.id}` })}
enable={() => update({
serviceId: activeService.id,
serviceData: {
isEnabled: true,
},
redirect: false,
})}
upgrade={() => openSettings({ path: 'user' })}
/>
)}
</>
)}
<div className="services" ref={this.serviceContainerRef} />
</>
);
}
}