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

Move ProgressBar to useSnackbar and convert to react functional component #11159

Merged
merged 1 commit into from
Jun 12, 2024
Merged
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
38 changes: 14 additions & 24 deletions ui/components/MesheryProgressBar.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,29 @@
import { Component } from 'react';
import { withSnackbar } from 'notistack';
import { connect } from 'react-redux';
import { LinearProgress } from '@material-ui/core';
import React, { useEffect, useRef } from 'react';
import { useSnackbar } from 'notistack';

class MesheryProgressBar extends Component {
key = '';
const MesheryProgressBar = ({ showProgress }) => {
const { enqueueSnackbar, closeSnackbar } = useSnackbar();
const snackbarKey = useRef(null);

shouldComponentUpdate(nextProps) {
const { showProgress } = this.props;
// if ((this.key !== '' && !showProgress) || (this.key === '' && showProgress)){
// return true;
// }
return showProgress !== nextProps.showProgress;
}

componentDidUpdate() {
const { showProgress } = this.props;
useEffect(() => {
if (showProgress) {
// const notify = this.props.enqueueSnackbar;
this.key = this.props.enqueueSnackbar(
snackbarKey.current = enqueueSnackbar(
<div style={{ width: 250 }}>
<LinearProgress />
</div>,
{ variant: 'default', persist: true },
);
} else {
this.props.closeSnackbar(this.key);
} else if (snackbarKey.current) {
closeSnackbar(snackbarKey.current);
snackbarKey.current = null;
}
}
}, [showProgress, enqueueSnackbar, closeSnackbar]);

render() {
return null;
}
}
return null;
};

const mapStateToProps = (state) => ({ showProgress: state.get('showProgress') });

export default connect(mapStateToProps)(withSnackbar(MesheryProgressBar));
export default connect(mapStateToProps)(MesheryProgressBar);
Loading