2022-08-03 07:02:49 +00:00
|
|
|
import React, { useCallback } from "react";
|
2021-05-20 12:03:08 +00:00
|
|
|
import styled from "styled-components";
|
|
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
2022-06-24 14:23:02 +00:00
|
|
|
import { TooltipComponent } from "design-system";
|
2021-10-04 15:34:37 +00:00
|
|
|
import Pen from "remixicon-react/PencilFillIcon";
|
|
|
|
|
import Eye from "remixicon-react/EyeLineIcon";
|
2021-06-11 15:01:32 +00:00
|
|
|
import { Indices } from "constants/Layers";
|
2021-05-20 12:03:08 +00:00
|
|
|
|
2022-08-24 12:16:32 +00:00
|
|
|
import { AppState } from "@appsmith/reducers";
|
2021-08-06 09:17:56 +00:00
|
|
|
import { APP_MODE } from "entities/App";
|
2021-06-17 07:37:27 +00:00
|
|
|
|
2021-08-23 09:25:16 +00:00
|
|
|
import AnalyticsUtil from "utils/AnalyticsUtil";
|
2022-07-26 12:34:54 +00:00
|
|
|
import { getAppMode } from "selectors/applicationSelectors";
|
2021-11-23 08:01:46 +00:00
|
|
|
import { setPreviewModeAction } from "actions/editorActions";
|
2022-08-03 07:02:49 +00:00
|
|
|
import { previewModeSelector } from "selectors/editorSelectors";
|
2021-07-02 06:04:36 +00:00
|
|
|
|
2022-01-25 13:56:52 +00:00
|
|
|
import { isExploringSelector } from "selectors/onboardingSelectors";
|
2021-11-02 07:33:12 +00:00
|
|
|
|
2021-07-15 10:56:18 +00:00
|
|
|
const ModeButton = styled.div<{
|
|
|
|
|
active: boolean;
|
|
|
|
|
showSelectedMode: boolean;
|
|
|
|
|
type: string;
|
|
|
|
|
}>`
|
2021-05-20 12:03:08 +00:00
|
|
|
position: relative;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
|
|
|
|
height: ${(props) => props.theme.smallHeaderHeight};
|
|
|
|
|
width: ${(props) => props.theme.smallHeaderHeight};
|
|
|
|
|
background: ${(props) =>
|
2021-07-15 10:56:18 +00:00
|
|
|
props.active && props.showSelectedMode
|
2022-08-03 07:02:49 +00:00
|
|
|
? props.theme.colors.toggleMode.activeModeBackground
|
2021-05-20 12:03:08 +00:00
|
|
|
: "transparent"};
|
|
|
|
|
|
|
|
|
|
svg path {
|
2021-07-05 07:12:02 +00:00
|
|
|
fill: ${(props) =>
|
|
|
|
|
props.type !== "fill"
|
|
|
|
|
? "transparent"
|
|
|
|
|
: props.active
|
2022-08-03 07:02:49 +00:00
|
|
|
? props.theme.colors.toggleMode.activeModeIcon
|
|
|
|
|
: props.theme.colors.toggleMode.modeIcon};
|
2021-07-05 07:12:02 +00:00
|
|
|
stroke: ${(props) =>
|
|
|
|
|
props.type !== "stroke"
|
|
|
|
|
? "transparent"
|
|
|
|
|
: props.active
|
2022-08-03 07:02:49 +00:00
|
|
|
? props.theme.colors.toggleMode.activeModeIcon
|
|
|
|
|
: props.theme.colors.toggleMode.modeIcon};
|
2021-07-05 07:12:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
svg rect:not(:first-child) {
|
2021-05-20 12:03:08 +00:00
|
|
|
fill: ${(props) =>
|
|
|
|
|
props.active
|
2022-08-03 07:02:49 +00:00
|
|
|
? props.theme.colors.toggleMode.activeModeIcon
|
|
|
|
|
: props.theme.colors.toggleMode.modeIcon};
|
2021-05-20 12:03:08 +00:00
|
|
|
}
|
2021-07-05 07:12:02 +00:00
|
|
|
|
2021-05-20 12:03:08 +00:00
|
|
|
svg circle {
|
2021-07-05 07:12:02 +00:00
|
|
|
stroke: ${(props) =>
|
|
|
|
|
props.active
|
2022-08-03 07:02:49 +00:00
|
|
|
? props.theme.colors.toggleMode.activeModeIconCircleStroke
|
|
|
|
|
: props.theme.colors.toggleMode.modeIconCircleStroke};
|
2021-05-20 12:03:08 +00:00
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const Container = styled.div`
|
|
|
|
|
display: flex;
|
|
|
|
|
flex: 1;
|
2021-06-11 15:01:32 +00:00
|
|
|
z-index: ${Indices.Layer1};
|
2021-05-20 12:03:08 +00:00
|
|
|
`;
|
|
|
|
|
|
2021-06-17 07:37:27 +00:00
|
|
|
function EditModeReset() {
|
|
|
|
|
return (
|
|
|
|
|
<TooltipComponent
|
|
|
|
|
content={
|
|
|
|
|
<>
|
|
|
|
|
Edit Mode
|
|
|
|
|
<span style={{ color: "#fff", marginLeft: 20 }}>V</span>
|
|
|
|
|
</>
|
|
|
|
|
}
|
|
|
|
|
hoverOpenDelay={1000}
|
2022-06-24 14:23:02 +00:00
|
|
|
position="bottom"
|
2021-06-17 07:37:27 +00:00
|
|
|
>
|
2021-10-04 15:34:37 +00:00
|
|
|
<Pen size={20} />
|
2021-06-17 07:37:27 +00:00
|
|
|
</TooltipComponent>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ViewModeReset() {
|
|
|
|
|
return (
|
|
|
|
|
<TooltipComponent
|
|
|
|
|
content={
|
|
|
|
|
<>
|
|
|
|
|
View Mode
|
|
|
|
|
<span style={{ color: "#fff", marginLeft: 20 }}>V</span>
|
|
|
|
|
</>
|
|
|
|
|
}
|
|
|
|
|
hoverOpenDelay={1000}
|
2022-06-24 14:23:02 +00:00
|
|
|
position="bottom"
|
2021-06-17 07:37:27 +00:00
|
|
|
>
|
2021-10-04 15:34:37 +00:00
|
|
|
<Eye size={20} />
|
2021-06-17 07:37:27 +00:00
|
|
|
</TooltipComponent>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-02 06:04:36 +00:00
|
|
|
function ViewOrEditMode({ mode }: { mode?: APP_MODE }) {
|
|
|
|
|
return mode === APP_MODE.EDIT ? <EditModeReset /> : <ViewModeReset />;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-03 07:02:49 +00:00
|
|
|
function ToggleModeButton({ showSelectedMode = true }) {
|
2021-11-23 08:01:46 +00:00
|
|
|
const dispatch = useDispatch();
|
2022-01-25 13:56:52 +00:00
|
|
|
const isExploring = useSelector(isExploringSelector);
|
2021-11-23 08:01:46 +00:00
|
|
|
const isPreviewMode = useSelector(previewModeSelector);
|
2021-10-19 10:26:56 +00:00
|
|
|
const appMode = useSelector(getAppMode);
|
2021-07-16 08:31:26 +00:00
|
|
|
|
2021-06-17 07:37:27 +00:00
|
|
|
const mode = useSelector((state: AppState) => state.entities.app.mode);
|
2022-05-04 09:45:57 +00:00
|
|
|
const isViewMode = mode === APP_MODE.PUBLISHED;
|
2021-06-17 07:37:27 +00:00
|
|
|
|
2021-11-23 08:01:46 +00:00
|
|
|
const onClickPreviewModeButton = useCallback(() => {
|
|
|
|
|
dispatch(setPreviewModeAction(true));
|
|
|
|
|
}, [dispatch, setPreviewModeAction]);
|
|
|
|
|
|
2021-05-20 12:03:08 +00:00
|
|
|
return (
|
2021-10-22 11:40:12 +00:00
|
|
|
<Container className="t--comment-mode-switch-toggle">
|
2022-08-03 07:02:49 +00:00
|
|
|
<div style={{ display: "flex" }}>
|
|
|
|
|
{!isExploring && !isViewMode && (
|
|
|
|
|
<ModeButton
|
|
|
|
|
active={!isPreviewMode}
|
|
|
|
|
className="t--switch-comment-mode-off"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
AnalyticsUtil.logEvent("COMMENTS_TOGGLE_MODE", {
|
|
|
|
|
mode,
|
|
|
|
|
source: "CLICK",
|
|
|
|
|
});
|
|
|
|
|
dispatch(setPreviewModeAction(false));
|
|
|
|
|
}}
|
|
|
|
|
showSelectedMode={showSelectedMode}
|
|
|
|
|
type="fill"
|
|
|
|
|
>
|
|
|
|
|
<ViewOrEditMode mode={mode} />
|
|
|
|
|
</ModeButton>
|
|
|
|
|
)}
|
|
|
|
|
{appMode === APP_MODE.EDIT && (
|
|
|
|
|
<TooltipComponent
|
|
|
|
|
content={
|
|
|
|
|
<>
|
|
|
|
|
Preview Mode
|
|
|
|
|
<span style={{ color: "#fff", marginLeft: 20 }}>P</span>
|
|
|
|
|
</>
|
|
|
|
|
}
|
|
|
|
|
hoverOpenDelay={1000}
|
|
|
|
|
position="bottom"
|
|
|
|
|
>
|
2022-01-25 13:56:52 +00:00
|
|
|
<ModeButton
|
2022-08-03 07:02:49 +00:00
|
|
|
active={isPreviewMode}
|
|
|
|
|
className="t--switch-preview-mode-toggle"
|
|
|
|
|
onClick={onClickPreviewModeButton}
|
2022-01-25 13:56:52 +00:00
|
|
|
showSelectedMode={showSelectedMode}
|
|
|
|
|
type="fill"
|
|
|
|
|
>
|
2022-08-03 07:02:49 +00:00
|
|
|
<Eye size={20} />
|
2022-01-25 13:56:52 +00:00
|
|
|
</ModeButton>
|
2022-08-03 07:02:49 +00:00
|
|
|
</TooltipComponent>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2021-05-20 12:03:08 +00:00
|
|
|
</Container>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-03 07:02:49 +00:00
|
|
|
export default ToggleModeButton;
|