2018-03-08 16:10:53 +00:00
|
|
|
/* @flow */
|
2018-07-30 10:52:13 +00:00
|
|
|
|
2018-08-14 13:18:16 +00:00
|
|
|
import * as LOG from 'actions/constants/log';
|
2019-03-04 11:52:26 +00:00
|
|
|
import copy from 'copy-to-clipboard';
|
2018-04-16 21:19:50 +00:00
|
|
|
|
2019-03-04 12:33:02 +00:00
|
|
|
import type { Action, ThunkAction, GetState, Dispatch } from 'flowtype';
|
2018-08-14 13:18:16 +00:00
|
|
|
import type { LogEntry } from 'reducers/LogReducer';
|
2018-04-16 21:19:50 +00:00
|
|
|
|
2019-03-04 12:33:02 +00:00
|
|
|
export type LogAction =
|
|
|
|
| {
|
|
|
|
type: typeof LOG.OPEN,
|
|
|
|
}
|
|
|
|
| {
|
|
|
|
type: typeof LOG.CLOSE,
|
|
|
|
}
|
2019-03-04 14:39:51 +00:00
|
|
|
| {
|
2019-03-04 14:48:35 +00:00
|
|
|
type: typeof LOG.COPY_RESET,
|
2019-03-04 14:39:51 +00:00
|
|
|
}
|
2019-03-04 13:01:25 +00:00
|
|
|
| {
|
|
|
|
type: typeof LOG.COPY_SUCCESS,
|
|
|
|
}
|
2019-03-04 12:33:02 +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
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
});
|
2019-03-04 11:52:26 +00:00
|
|
|
|
2019-03-04 13:01:25 +00:00
|
|
|
export const copyToClipboard = (): ThunkAction => (
|
|
|
|
dispatch: Dispatch,
|
|
|
|
getState: GetState
|
|
|
|
): void => {
|
2019-03-04 11:52:26 +00:00
|
|
|
const { entries } = getState().log;
|
|
|
|
try {
|
|
|
|
const res = copy(JSON.stringify(entries));
|
|
|
|
if (res) {
|
|
|
|
dispatch({
|
|
|
|
type: LOG.COPY_SUCCESS,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
}
|
|
|
|
};
|
2019-03-04 14:36:04 +00:00
|
|
|
|
|
|
|
export const resetCopyState = (): Action => ({
|
|
|
|
type: LOG.COPY_RESET,
|
|
|
|
});
|