Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Listen for page publication from websocket server #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/`;
}