noderaider / redux-idle-monitor

A Redux component to schedule events at stages of user idleness across multiple browser tabs.
https://noderaider.github.io/redux-idle-monitor/
MIT License
105 stars 9 forks source link

Initial state is idle on load #26

Open djbingham opened 6 years ago

djbingham commented 6 years ago

EDIT: About 5 mins after making opening this ticket, I realised I'd misinterpreted the initial state. Where I thought it was starting in the first inactive state, it turned out it was actually starting in the last inactive state. i.e. we seem to be assuming the user is already inactive at the point that monitoring is started. I've rewritten the ticket to reflect this.

Hi,

I've noticed that redux-idle-monitor seems to start with status set to the final inactive state, rather than the active state, even if the user was moving their cursor immediately before the idleMonitorActions.start() action was dispatched. I think this is a bug.

I have two inactive states (inactive and away) and expect the states to go active -> inactive -> away.

export const IDLE_STATUS_INACTIVE = 'INACTIVE';
export const IDLE_STATUS_AWAY = 'AWAY';

export const IDLE_STATUSES = [IDLE_STATUS_INACTIVE, IDLE_STATUS_AWAY];

If I never do anything after the idleMonitorActions.start() action is dispatched, the status starts as away, then updates to inactive, then goes back to away. I would expect the initial state to be active, since it seems a safe assumption that the user is active up until the point that we start monitoring. In my case, I start monitoring immediately after login.

If this isn't a bug, is there a safe way to configure the initial state before starting monitoring? (By safe, I mean something that doesn't risk interfering with the monitoring component. I'm not sure how redux-idle-monitor handles state updates and whether me changing the state directly might break things).

Expected initial state

idleStatus: "ACTIVE"
isDetectionRunning: true
isIdle: false
isRunning: true
lastActive: 1520246760457
lastEvent: {x: 501, y: 238, type: "mousemove"}

Actual initial state

idleStatus: "AWAY"
isDetectionRunning: true
isIdle: true
isRunning: true
lastActive: 1520246760457
lastEvent: {x: 501, y: 238, type: "mousemove"}

I got this initial state from my LocalStorage immediately after the idleMonitorActions.start() action has completed by putting a break point into my only component that depends on idle state changes (using createConnector from react-redux-idle-monitor.