2023-02-08 17:48:11 +00:00
|
|
|
import ReducerRegistry from '../base/redux/ReducerRegistry';
|
|
|
|
|
|
|
|
import {
|
2023-02-23 18:43:16 +00:00
|
|
|
I_AM_VISITOR_MODE,
|
|
|
|
UPDATE_VISITORS_COUNT
|
2023-02-08 17:48:11 +00:00
|
|
|
} from './actionTypes';
|
|
|
|
|
|
|
|
const DEFAULT_STATE = {
|
2023-02-23 18:43:16 +00:00
|
|
|
iAmVisitor: false
|
2023-02-08 17:48:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export interface IVisitorsState {
|
|
|
|
count?: number;
|
2023-02-23 18:43:16 +00:00
|
|
|
iAmVisitor: boolean;
|
2023-02-08 17:48:11 +00:00
|
|
|
}
|
|
|
|
ReducerRegistry.register<IVisitorsState>('features/visitors', (state = DEFAULT_STATE, action): IVisitorsState => {
|
|
|
|
switch (action.type) {
|
|
|
|
case UPDATE_VISITORS_COUNT: {
|
|
|
|
if (state.count === action.count) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
count: action.count
|
|
|
|
};
|
|
|
|
}
|
2023-02-23 18:43:16 +00:00
|
|
|
case I_AM_VISITOR_MODE: {
|
2023-02-08 17:48:11 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2023-02-23 18:43:16 +00:00
|
|
|
iAmVisitor: action.enabled
|
2023-02-08 17:48:11 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
});
|