Skip to content

Commit

Permalink
fix: handle state change with identical or missing currentWidgetId
Browse files Browse the repository at this point in the history
The pi exhibited an issue where a current widget could become stuck and
never continue to the next widget. It seems to be caused by clicking on
the current widget in the tab. Added some logging in case there are
other edge cases.
  • Loading branch information
cbarber committed Feb 26, 2020
1 parent 80bd084 commit f7ab65f
Showing 1 changed file with 31 additions and 16 deletions.
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,
transitionTime: null,
}
: {},
);
};

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

0 comments on commit f7ab65f

Please sign in to comment.