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

fix: handle state change with identical or missing currentWidgetId #181

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
47 changes: 31 additions & 16 deletions app/javascript/components/widget-controller.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,27 @@ export class WidgetController extends React.Component {
};

nextWidget = () => {
this.setState(({ nextWidgetId }) =>
nextWidgetId
? {
currentWidgetId: nextWidgetId,
nextWidgetId: null,
prevWidgetId: null,
transitionTime: null,
}
: {},
);
this.setState(state => {
const { nextWidgetId } = state;
if (!nextWidgetId) {
// eslint-disable-next-line
console.error(
`FATAL: nextWidgetId is undefined for nextWidget call. state: ${state}`,
);
return {
currentWidgetId: null,
nextWidgetId: null,
prevWidgetId: null,
transitionTime: null,
};
}
return {
currentWidgetId: nextWidgetId,
nextWidgetId: null,
prevWidgetId: null,
transitionTime: null,
};
});
};

prevWidget = () => {
Expand All @@ -139,12 +150,16 @@ export class WidgetController extends React.Component {
};

switchToPage = id => {
this.setState({
currentWidgetId: id,
nextWidgetId: null,
prevWidgetId: null,
transitionTime: null,
});
this.setState(({ currentWidgetId }) =>
currentWidgetId !== id
? {
currentWidgetId: id,
nextWidgetId: null,
prevWidgetId: null,
Comment on lines +157 to +158
Copy link
Contributor

Choose a reason for hiding this comment

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

are these all calculated values?

transitionTime: null,
}
: {},
);
};

handleClicks = ({ target }) => {
Expand Down