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

Boiler-plate changes #5

Open
wants to merge 2 commits 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
56 changes: 29 additions & 27 deletions src/components/includes/alerts.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
import React, { Component } from 'react';
import React, {useState, useRef, useEffect} from 'react';
import { connect } from 'react-redux';
import {isEmptyArray} from '../../helpers/helper';
import {setAlertAction, clearAlertAction} from '../../redux/actions/alertActions';

export class Alerts extends Component {
state = {
alerts:[],
}
const Alerts = (props) => {
const [alerts, setAlert] = useState([]);
const mounted = useRef();

componentDidUpdate(prevProps) {
useEffect(() => {
if(!mounted){
if(props.alerts !== props.alerts && !isEmptyArray(props.alerts)) {
setAlert([...alerts, ...props.alert]);

if (this.props.alerts !== prevProps.alerts && !isEmptyArray(this.props.alerts)) {

// Update current list of alerts in component state
this.setState({alerts:[...this.state.alerts,...this.props.alerts]});

// Clear list of alerts in reducer
this.props.clearAlertAction();

// re-render component
return true;
props.clearAlertAction();
return true;
}
}
}, [props.alerts]);

return false;
}

showAlert = (alerts)=>{
const showAlert = (alerts)=>{
if (!isEmptyArray(alerts)) {

// Display current alert messages in state
Expand All @@ -40,23 +34,31 @@ export class Alerts extends Component {
);
});
}
}
};

clearAlert = (id) => {
const unread = this.state.alerts.filter(alert => alert.id !== id);
this.setState({alerts:unread});
}

render() {
const clearAlert = (id) => {
const unread = alerts.filter((alert) => alert.id !== id);
setAlert(unread);
};



return (
<div style={{position:'fixed', marginTop:70, zIndex:10, width:'40%', padding:'0px 60px', marginLeft:'60%'}}>
{this.showAlert(this.state.alerts)}
{showAlert(alerts)}
</div>
)
}



}






const mapStateToProps = state => ({
alerts: state.alert.alerts,
});
Expand Down
19 changes: 11 additions & 8 deletions src/components/layouts/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component } from 'react';

import React, {useState, useEffect} from 'react';
import {BrowserRouter as Router, Route, Switch} from 'react-router-dom';
import { Provider } from 'react-redux';
import {storeInstance} from '../../support/reducerSupport';
Expand All @@ -12,10 +13,11 @@ import TopNavBar from '../navigation/topNavBar';
import ApplicationStatusModal from '../modals/applicationStatusModal';


export class App extends Component {
const App = () => {

constructor(){
super();




// Get last login details, if any re-login user
let user = retrievePersistedLastLogin('session');
Expand All @@ -24,9 +26,6 @@ export class App extends Component {
dispatch({type: AUTH_LOGIN_USER, payLoad: user.loginDetails});
});
}
}

render() {
return (
<Provider store={storeInstance()}>
<Router>
Expand All @@ -44,7 +43,11 @@ export class App extends Component {
</Router>
</Provider>
);
}





}

export default App;
60 changes: 37 additions & 23 deletions src/components/modals/applicationStatusModal.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,49 @@
import React, { Component } from 'react';
import React, { useState, useEffect, useRef } from 'react';
import { connect } from 'react-redux';
import DotsAnimation from '../animations/dotsAnimation';
import {PROCESSING_MUSIC} from '../music/music';

export class AppStatusModal extends Component {
const AppStatusModal = (props) => {
const [applicationStatus, setApplicationStatus] = useState([]);
const mounted = useRef ();

componentDidMount(){
this.initializeAudioPlayer();
}

componentDidUpdate(prevProps){
if (prevProps.applicationStatus !== this.props.applicationStatus) {
if (this.props.applicationStatus.isProcessing===true) {
this.toggleDisplayModal('show');
this.toggleProcessingMusic('start');
}
useEffect(() => {
if(!mounted){
if(props.applicationStatus !== props.applicationStatus) {
setApplicationStatus([...applicationStatus, ...props.applicationStatus]);

if (this.props.applicationStatus.isProcessing===false) {
this.toggleDisplayModal('hide');
this.toggleProcessingMusic('stop');
toggleDisplayModal('show');
toggleProcessingMusic('hide');

}
}
}
}, [props.applicationStatus]);



initializeAudioPlayer = () => {


// componentDidUpdate(prevProps){
// if (prevProps.applicationStatus !== this.props.applicationStatus) {
// if (this.props.applicationStatus.isProcessing===true) {
// this.toggleDisplayModal('show');
// this.toggleProcessingMusic('start');
// }

// if (this.props.applicationStatus.isProcessing===false) {
// this.toggleDisplayModal('hide');
// this.toggleProcessingMusic('stop');
// }
// }
// }

const initializeAudioPlayer = () => {
this.audioPlayer = new Audio(PROCESSING_MUSIC);
this.audioPlayer.volume = 0.3;
this.audioPlayer.loop = true;
}

toggleDisplayModal = (action) => {
const toggleDisplayModal = (action) => {
const modal = document.getElementById('app-status-modal');
const modalOpenButton = document.getElementById('app-status-modal-open');
const modalCloseButton = document.getElementById('app-status-modal-close');
Expand All @@ -40,18 +54,18 @@ export class AppStatusModal extends Component {
} else if (modal && modalOpenButton && !modal.classList.contains('show') && action==='show') {
modalOpenButton.click();
}
}
};

toggleProcessingMusic = (control) => {
const toggleProcessingMusic = (control) => {

if (control === 'start') {
this.audioPlayer.play().catch((err)=>{console.log(err);});
} else {
this.audioPlayer.pause();
}
}
};

render() {

return (
<div>
<button style={{display:'none'}} id="app-status-modal-open" type="button" data-toggle="modal" data-target="#app-status-modal">Launch</button>
Expand All @@ -68,7 +82,7 @@ export class AppStatusModal extends Component {
</div>
</div>
)
}

}

const mapStateToProps = (state) => ({
Expand Down
6 changes: 3 additions & 3 deletions src/components/navigation/topNavBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import {NAV_BAR_LOGO_ONE} from '../images/images';

export class TopNavBar extends Component {
const TopNavBar = ()=>{

render() {

return (
<nav className="navbar navbar-expand-lg navbar-dark bg-dark">
<Link to="/" className="navbar-brand pl-3">
Expand All @@ -19,7 +19,7 @@ export class TopNavBar extends Component {
</div>
</nav>
)
}

}

export default TopNavBar;
6 changes: 3 additions & 3 deletions src/components/pages/landing.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { Component } from 'react';
import DotsAnimation from '../animations/dotsAnimation';

export class Landing extends Component {
render() {
export const Landing = () => {

return (
<div style={{height:'100vh'}}>
<div style={{textAlign:'center', marginTop:'20%'}}>
Expand All @@ -11,7 +11,7 @@ export class Landing extends Component {
</div>
</div>
)
}

}

export default Landing;
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import ReactDOM from 'react-dom';
import App from './components/layouts/app';
import * as serviceWorker from './serviceWorker';


ReactDOM.render(
<React.StrictMode>
<App />

</React.StrictMode>,
document.getElementById('root')
);
Expand Down