ligo/tools/webide/packages/client/src/redux/share.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

83 lines
2.5 KiB
TypeScript

import { ActionType as CompileActionType, ChangeEntrypointAction as ChangeCompileEntrypointAction } from './compile';
import {
ActionType as DeployActionType,
ChangeEntrypointAction as ChangeDeployEntrypointAction,
ChangeStorageAction as ChangeDeployStorageAction,
UseTezBridgeAction,
} from './deploy';
import {
ActionType as DryRunActionType,
ChangeEntrypointAction as ChangeDryRunEntrypointAction,
ChangeParametersAction as ChangeDryRunParametersAction,
ChangeStorageAction as ChangeDryRunStorageAction,
} from './dry-run';
import { ActionType as EditorActionType, ChangeCodeAction, ChangeLanguageAction } from './editor';
import {
ActionType as EvaluateFunctionActionType,
ChangeEntrypointAction as ChangeEvaluateFunctionEntrypointAction,
ChangeParametersAction as ChangeEvaluateFunctionParametersAction,
} from './evaluate-function';
import {
ActionType as EvaluateValueActionType,
ChangeEntrypointAction as ChangeEvaluateValueEntrypointAction,
} from './evaluate-value';
export enum ActionType {
ChangeShareLink = 'share-change-link'
}
export interface ShareState {
link: string;
}
export class ChangeShareLinkAction {
public readonly type = ActionType.ChangeShareLink;
constructor(public payload: ShareState['link']) {}
}
type Action =
| ChangeShareLinkAction
| ChangeCodeAction
| ChangeLanguageAction
| ChangeCompileEntrypointAction
| ChangeDeployEntrypointAction
| ChangeDeployStorageAction
| UseTezBridgeAction
| ChangeDryRunEntrypointAction
| ChangeDryRunParametersAction
| ChangeDryRunStorageAction
| ChangeEvaluateFunctionEntrypointAction
| ChangeEvaluateFunctionParametersAction
| ChangeEvaluateValueEntrypointAction;
const DEFAULT_STATE: ShareState = {
link: ''
};
export default (state = DEFAULT_STATE, action: Action): ShareState => {
switch (action.type) {
case EditorActionType.ChangeCode:
case EditorActionType.ChangeLanguage:
case CompileActionType.ChangeEntrypoint:
case DeployActionType.ChangeEntrypoint:
case DeployActionType.ChangeStorage:
case DeployActionType.UseTezBridge:
case DryRunActionType.ChangeEntrypoint:
case DryRunActionType.ChangeParameters:
case DryRunActionType.ChangeStorage:
case EvaluateFunctionActionType.ChangeEntrypoint:
case EvaluateFunctionActionType.ChangeParameters:
case EvaluateValueActionType.ChangeEntrypoint:
return {
...state,
...DEFAULT_STATE
};
case ActionType.ChangeShareLink:
return {
...state,
link: action.payload
};
}
return state;
};