ligo/tools/webide/packages/client/src/redux/loading.ts
Jev Björsell c119c44c13
Import webide into main ligo monorepo
When this is merged https://gitlab.com/ligolang/ligo-web-ide/ will be
marked as deprecated.

This MR does not hook up the webide build to the main CI. The CI
integration will come in a subsequent MR for the sake of making review
easier.
2020-02-06 19:04:18 -08:00

43 lines
908 B
TypeScript

export enum ActionType {
UpdateLoading = 'loading-update-loading',
DoneLoading = 'loading-done-loading'
}
export interface LoadingState {
loading: boolean;
message: string;
}
export class UpdateLoadingAction {
public readonly type = ActionType.UpdateLoading;
constructor(public payload: LoadingState['message']) {}
}
export class DoneLoadingAction {
public readonly type = ActionType.DoneLoading;
}
type Action = UpdateLoadingAction | DoneLoadingAction;
export const DEFAULT_STATE: LoadingState = {
loading: false,
message: ''
};
export default (state = DEFAULT_STATE, action: Action): LoadingState => {
switch (action.type) {
case ActionType.UpdateLoading:
return {
...state,
loading: true,
message: action.payload
};
case ActionType.DoneLoading:
return {
...state,
...DEFAULT_STATE
};
}
return state;
};