2018-03-08 16:10:53 +00:00
|
|
|
/* @flow */
|
2018-07-30 10:52:13 +00:00
|
|
|
|
2018-03-08 16:10:53 +00:00
|
|
|
|
2018-04-16 21:19:50 +00:00
|
|
|
import * as LOG from './constants/log';
|
|
|
|
|
2018-07-30 10:52:13 +00:00
|
|
|
import type {
|
|
|
|
Action, ThunkAction, GetState, Dispatch,
|
|
|
|
} from '~/flowtype';
|
2018-05-05 11:52:03 +00:00
|
|
|
import type { LogEntry } from '../reducers/LogReducer';
|
2018-04-16 21:19:50 +00:00
|
|
|
|
|
|
|
export type LogAction = {
|
|
|
|
type: typeof LOG.OPEN,
|
|
|
|
} | {
|
|
|
|
type: typeof LOG.CLOSE,
|
2018-05-05 11:52:03 +00:00
|
|
|
} | {
|
|
|
|
type: typeof LOG.ADD,
|
|
|
|
payload: LogEntry
|
2018-04-16 21:19:50 +00:00
|
|
|
};
|
|
|
|
|
2018-07-30 10:52:13 +00:00
|
|
|
export const toggle = (): ThunkAction => (dispatch: Dispatch, getState: GetState): void => {
|
|
|
|
if (!getState().log.opened) {
|
|
|
|
window.scrollTo(0, 0);
|
2018-03-08 16:10:53 +00:00
|
|
|
|
2018-07-30 10:52:13 +00:00
|
|
|
dispatch({
|
|
|
|
type: LOG.OPEN,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
dispatch({
|
|
|
|
type: LOG.CLOSE,
|
|
|
|
});
|
2018-03-08 16:10:53 +00:00
|
|
|
}
|
2018-07-30 10:52:13 +00:00
|
|
|
};
|
2018-05-05 11:52:03 +00:00
|
|
|
|
|
|
|
// export const add = (type: string, message: string): Action => {
|
2018-07-30 10:52:13 +00:00
|
|
|
export const add = (type: string, message: any): Action => ({
|
|
|
|
type: LOG.ADD,
|
|
|
|
payload: {
|
|
|
|
time: new Date().getTime(),
|
|
|
|
type,
|
|
|
|
message,
|
|
|
|
},
|
|
|
|
});
|