Skip to content

New nav component and a new hook #2350

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

Merged

Conversation

dewanshDT
Copy link
Collaborator

@dewanshDT dewanshDT commented Aug 4, 2023

Changes:
added the new nav component, which was broken into several smaller components and a new hook useSketchActions

I have verified that this pull request:

  • has no linting errors (npm run lint)
  • has no test errors (npm run test)
  • is from a uniquely-named feature branch and is up to date with the develop branch.

@dewanshDT dewanshDT requested a review from lindapaiste August 4, 2023 20:36
Copy link
Collaborator

@lindapaiste lindapaiste left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work! There is only one thing which needs to change, and it's my fault 🤦‍♀️ because I told you that none of my Redux changes mattered...but I forgot about changing the toast from two actions to one. I will come up with a patch for that which just changes the actions and doesn't involve Redux Toolkit.

<NavMenuItem onClick={newSketch}>{t('Nav.File.New')}</NavMenuItem>
<NavMenuItem
hideIf={
!getConfig('LOGIN_ENABLED') || (project?.owner && !isUserOwner)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI that second condition is the negative of canEditProjectName/selectCanEditSketch.

@lindapaiste
Copy link
Collaborator

Ok here's the fix I came up with for the Redux actions which will allow you to use dispatch(showToast('Toast.SketchSaved')); here without refactoring other components and actions which still use two separate actions. Replace the existing showToast function:

export function showToast(time) {
return (dispatch) => {
dispatch({
type: ActionTypes.SHOW_TOAST
});
setTimeout(() => dispatch(hideToast()), time);
};
}

with this:

/**
 * Temporary fix until #2206 is merged.
 * Supports legacy two-action syntax:
 *    dispatch(setToastText('Toast.SketchFailedSave'));
 *    dispatch(showToast(1500));
 * And also supports proposed single-action syntax with message and optional timeout.
 *    dispatch(showToast('Toast.SketchFailedSave'));
 *    dispatch(showToast('Toast.SketchSaved', 5500));
 */
export function showToast(textOrTime, timeout = 1500) {
  return (dispatch) => {
    let time = timeout;
    if (typeof textOrTime === 'string') {
      // eslint-disable-next-line no-use-before-define
      dispatch(setToastText(textOrTime));
    } else {
      time = textOrTime;
    }
    dispatch({
      type: ActionTypes.SHOW_TOAST
    });
    setTimeout(() => dispatch(hideToast()), time);
  };
}

@dewanshDT
Copy link
Collaborator Author

Ok here's the fix I came up with for the Redux actions which will allow you to use dispatch(showToast('Toast.SketchSaved')); here without refactoring other components and actions which still use two separate actions. Replace the existing showToast function:

export function showToast(time) {
return (dispatch) => {
dispatch({
type: ActionTypes.SHOW_TOAST
});
setTimeout(() => dispatch(hideToast()), time);
};
}

with this:

/**
 * Temporary fix until #2206 is merged.
 * Supports legacy two-action syntax:
 *    dispatch(setToastText('Toast.SketchFailedSave'));
 *    dispatch(showToast(1500));
 * And also supports proposed single-action syntax with message and optional timeout.
 *    dispatch(showToast('Toast.SketchFailedSave'));
 *    dispatch(showToast('Toast.SketchSaved', 5500));
 */
export function showToast(textOrTime, timeout = 1500) {
  return (dispatch) => {
    let time = timeout;
    if (typeof textOrTime === 'string') {
      // eslint-disable-next-line no-use-before-define
      dispatch(setToastText(textOrTime));
    } else {
      time = textOrTime;
    }
    dispatch({
      type: ActionTypes.SHOW_TOAST
    });
    setTimeout(() => dispatch(hideToast()), time);
  };
}

Okay 👍

@dewanshDT
Copy link
Collaborator Author

dewanshDT commented Aug 5, 2023

hey @lindapaiste! just made all the suggested changes to the PR please check it out.

@dewanshDT dewanshDT requested a review from lindapaiste August 5, 2023 18:46
@lindapaiste lindapaiste merged commit 9703e10 into processing:develop Aug 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants