Skip to content

Commit

Permalink
feat: handle saving data for research plan
Browse files Browse the repository at this point in the history
  • Loading branch information
Lan Le committed Mar 27, 2024
1 parent 2ed15a9 commit 9997a1a
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { formatTimeStampsOfElement } from 'src/utilities/timezoneHelper';
import UserStore from 'src/stores/alt/stores/UserStore';
import MatrixCheck from 'src/components/common/MatrixCheck';
import { commentActivation } from 'src/utilities/CommentHelper';
import { handleSaveDataset } from 'src/utilities/ElementUtils';

export default class ResearchPlanDetails extends Component {
constructor(props) {
Expand All @@ -53,6 +54,7 @@ export default class ResearchPlanDetails extends Component {
visible: Immutable.List(),
currentUser: (UserStore.getState() && UserStore.getState().currentUser) || {},
};
this.onUIStoreChange = this.onUIStoreChange.bind(this);
this.handleSwitchMode = this.handleSwitchMode.bind(this);
this.handleResearchPlanChange = this.handleResearchPlanChange.bind(this);
this.toggleFullScreen = this.toggleFullScreen.bind(this);
Expand All @@ -68,6 +70,8 @@ export default class ResearchPlanDetails extends Component {
const { researchPlan } = this.props;
const { currentUser } = this.state;

UIStore.listen(this.onUIStoreChange);

if (MatrixCheck(currentUser.matrix, commentActivation) && !researchPlan.isNew) {
CommentActions.fetchComments(researchPlan);
}
Expand All @@ -78,6 +82,15 @@ export default class ResearchPlanDetails extends Component {
this.setState({ researchPlan });
}

componentWillUnmount() {
UIStore.unlisten(this.onUIStoreChange)
}

onUIStoreChange(state) {
const { researchPlan } = this.state;
handleSaveDataset(researchPlan, state, this.handleSubmit);
}

handleResearchPlanChange(el) {
const researchPlan = el;
researchPlan.changed = true;
Expand All @@ -104,7 +117,7 @@ export default class ResearchPlanDetails extends Component {

handleSubmit() {
const { researchPlan } = this.state;
LoadingActions.start();
LoadingActions.start.defer();

if (researchPlan.isNew) {
ElementActions.createResearchPlan(researchPlan);
Expand Down

0 comments on commit 9997a1a

Please sign in to comment.