Skip to content

Commit

Permalink
Listen for page publication from websocket server
Browse files Browse the repository at this point in the history
  • Loading branch information
algomaster99 committed Jan 7, 2020
1 parent 411a8e5 commit b5dc3da
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/components/profile/cmsIntegration.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Icon, Segment, Button } from 'semantic-ui-react';
import { toast } from 'react-semantic-toasts';

import { jsonHeaders } from '../../constants/formPostRequestHeaders'
import { urlCmsIntegration, urlIITRMain, urlCms } from '../../urls';
import { urlCmsIntegration, urlWebSocketServer } from '../../urls';

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

Expand All @@ -20,10 +20,22 @@ class CMSIntegration extends React.PureComponent {
publish: false
}
}
this.streamSocket = new WebSocket(urlWebSocketServer());
}
componentDidMount() {
this.streamSocket.onmessage = (e) => {
const data = JSON.parse(e.data)
this.setState({
loading: {
...this.state.loading,
publish: !(data.published === 'published'),
}
})
}
}
onPreview = () => {
this.setState({
loading:{
loading: {
... this.state.loading,
preview: true
}
Expand Down Expand Up @@ -80,7 +92,7 @@ class CMSIntegration extends React.PureComponent {

onPublish = () => {
this.setState({
loading:{
loading: {
... this.state.loading,
publish: true
}
Expand Down Expand Up @@ -120,6 +132,12 @@ class CMSIntegration extends React.PureComponent {
Try previewing your page after some time!
</p>
)
this.setState({
loading:{
... this.state.loading,
publish: false
}
});
toast({
type: 'error',
title: 'Publish Error',
Expand All @@ -129,21 +147,13 @@ class CMSIntegration extends React.PureComponent {
});
return 'error';
})
.finally(code =>{
this.setState({
loading:{
... this.state.loading,
publish: false
}
});
});
}

render() {
const { theme } = this.props;
const previewLoad = this.state.loading.preview;
const publishLoad = this.state.loading.publish;
return (
return (
<div>
<BrowserView>
<Segment
Expand Down
4 changes: 4 additions & 0 deletions src/urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ export function urlMainApp() {
export function urlCmsIntegration() {
return `${urlMainApp()}cms/`;
}

export function urlWebSocketServer() {
return `ws://localhost:60025/ws/faculty_profile/cms/`;
}

0 comments on commit b5dc3da

Please sign in to comment.