Skip to content

Commit 4ad0936

Browse files
committed
Listen for page publication from websocket server
1 parent 411a8e5 commit 4ad0936

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

src/components/profile/cmsIntegration.js

+25-15
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Icon, Segment, Button } from 'semantic-ui-react';
55
import { toast } from 'react-semantic-toasts';
66

77
import { jsonHeaders } from '../../constants/formPostRequestHeaders'
8-
import { urlCmsIntegration, urlIITRMain, urlCms } from '../../urls';
8+
import { urlCmsIntegration, urlWebSocketServer } from '../../urls';
99

1010
import style from '../../styles.css';
1111

@@ -20,10 +20,22 @@ class CMSIntegration extends React.PureComponent {
2020
publish: false
2121
}
2222
}
23+
this.streamSocket = new WebSocket(urlWebSocketServer());
24+
}
25+
componentDidMount() {
26+
this.streamSocket.onmessage = (e) => {
27+
const data = JSON.parse(e.data)
28+
this.setState({
29+
loading: {
30+
...this.state.loading,
31+
publish: !(data.published === 'published'),
32+
}
33+
})
34+
}
2335
}
2436
onPreview = () => {
2537
this.setState({
26-
loading:{
38+
loading: {
2739
... this.state.loading,
2840
preview: true
2941
}
@@ -80,7 +92,7 @@ class CMSIntegration extends React.PureComponent {
8092

8193
onPublish = () => {
8294
this.setState({
83-
loading:{
95+
loading: {
8496
... this.state.loading,
8597
publish: true
8698
}
@@ -96,10 +108,10 @@ class CMSIntegration extends React.PureComponent {
96108
const url = data.url;
97109
const description = (
98110
<p>
99-
Your page will be published at{' '}
111+
Your page will be published at this{' '}
100112
<a href={url} target="_blank" styleName="style.toastLink">
101-
{ url }
102-
</a>
113+
link
114+
</a>.
103115
<br/>
104116
Wait some time for content to update.
105117
</p>
@@ -120,6 +132,12 @@ class CMSIntegration extends React.PureComponent {
120132
Try previewing your page after some time!
121133
</p>
122134
)
135+
this.setState({
136+
loading:{
137+
... this.state.loading,
138+
publish: false
139+
}
140+
});
123141
toast({
124142
type: 'error',
125143
title: 'Publish Error',
@@ -129,21 +147,13 @@ class CMSIntegration extends React.PureComponent {
129147
});
130148
return 'error';
131149
})
132-
.finally(code =>{
133-
this.setState({
134-
loading:{
135-
... this.state.loading,
136-
publish: false
137-
}
138-
});
139-
});
140150
}
141151

142152
render() {
143153
const { theme } = this.props;
144154
const previewLoad = this.state.loading.preview;
145155
const publishLoad = this.state.loading.publish;
146-
return (
156+
return (
147157
<div>
148158
<BrowserView>
149159
<Segment

src/urls.js

+4
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ export function urlMainApp() {
55
export function urlCmsIntegration() {
66
return `${urlMainApp()}cms/`;
77
}
8+
9+
export function urlWebSocketServer() {
10+
return `ws://localhost:60025/ws/faculty_profile/cms/`;
11+
}

0 commit comments

Comments
 (0)