2021-06-17 07:37:27 +00:00
|
|
|
import React, { useCallback, useEffect, useState } from "react";
|
2021-05-20 12:03:08 +00:00
|
|
|
import styled from "styled-components";
|
|
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
|
|
|
import TooltipComponent from "components/ads/Tooltip";
|
|
|
|
|
import TourTooltipWrapper from "components/ads/tour/TourTooltipWrapper";
|
|
|
|
|
import { ReactComponent as Pen } from "assets/icons/comments/pen.svg";
|
2021-06-17 07:37:27 +00:00
|
|
|
import { ReactComponent as Eye } from "assets/icons/comments/eye.svg";
|
2021-05-20 12:03:08 +00:00
|
|
|
import { ReactComponent as CommentModeUnread } from "assets/icons/comments/comment-mode-unread-indicator.svg";
|
|
|
|
|
import { ReactComponent as CommentMode } from "assets/icons/comments/chat.svg";
|
2021-06-11 15:01:32 +00:00
|
|
|
import { Indices } from "constants/Layers";
|
2021-05-20 12:03:08 +00:00
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
setCommentMode as setCommentModeAction,
|
|
|
|
|
fetchApplicationCommentsRequest,
|
|
|
|
|
showCommentsIntroCarousel,
|
|
|
|
|
} from "actions/commentActions";
|
|
|
|
|
import {
|
|
|
|
|
commentModeSelector,
|
|
|
|
|
areCommentsEnabledForUserAndApp as areCommentsEnabledForUserAndAppSelector,
|
|
|
|
|
showUnreadIndicator as showUnreadIndicatorSelector,
|
|
|
|
|
} from "../../selectors/commentsSelectors";
|
|
|
|
|
import { getCurrentUser } from "selectors/usersSelectors";
|
|
|
|
|
import { useLocation } from "react-router";
|
|
|
|
|
import history from "utils/history";
|
|
|
|
|
import { Position } from "@blueprintjs/core/lib/esm/common/position";
|
|
|
|
|
import { TourType } from "entities/Tour";
|
|
|
|
|
import useProceedToNextTourStep from "utils/hooks/useProceedToNextTourStep";
|
|
|
|
|
import { getCommentsIntroSeen } from "utils/storage";
|
|
|
|
|
import { User } from "constants/userConstants";
|
2021-06-17 07:37:27 +00:00
|
|
|
import { AppState } from "reducers";
|
|
|
|
|
import { APP_MODE } from "reducers/entityReducers/appReducer";
|
|
|
|
|
|
|
|
|
|
import { matchBuilderPath, matchViewerPath } from "constants/routes";
|
2021-05-20 12:03:08 +00:00
|
|
|
|
2021-07-02 06:04:36 +00:00
|
|
|
import { createMessage, ONE_UNREAD_MESSAGE } from "constants/messages";
|
|
|
|
|
|
|
|
|
|
import localStorage from "utils/localStorage";
|
|
|
|
|
|
|
|
|
|
const getShowCommentsButtonToolTip = () => {
|
|
|
|
|
const flag = localStorage.getItem("ShowCommentsButtonToolTip");
|
|
|
|
|
return flag === null || !!flag;
|
|
|
|
|
};
|
|
|
|
|
const setShowCommentsButtonToolTip = (value = "") =>
|
|
|
|
|
localStorage.setItem("ShowCommentsButtonToolTip", value);
|
|
|
|
|
|
2021-07-05 07:12:02 +00:00
|
|
|
const ModeButton = styled.div<{ active: 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) =>
|
|
|
|
|
props.active
|
|
|
|
|
? props.theme.colors.comments.activeModeBackground
|
|
|
|
|
: "transparent"};
|
|
|
|
|
|
|
|
|
|
svg path {
|
2021-07-05 07:12:02 +00:00
|
|
|
fill: ${(props) =>
|
|
|
|
|
props.type !== "fill"
|
|
|
|
|
? "transparent"
|
|
|
|
|
: props.active
|
|
|
|
|
? props.theme.colors.comments.activeModeIcon
|
|
|
|
|
: props.theme.colors.comments.modeIcon};
|
|
|
|
|
stroke: ${(props) =>
|
|
|
|
|
props.type !== "stroke"
|
|
|
|
|
? "transparent"
|
|
|
|
|
: props.active
|
|
|
|
|
? props.theme.colors.comments.activeModeIcon
|
|
|
|
|
: props.theme.colors.comments.modeIcon};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
svg rect:not(:first-child) {
|
2021-05-20 12:03:08 +00:00
|
|
|
fill: ${(props) =>
|
|
|
|
|
props.active
|
|
|
|
|
? props.theme.colors.comments.activeModeIcon
|
|
|
|
|
: props.theme.colors.comments.modeIcon};
|
|
|
|
|
}
|
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
|
|
|
|
|
? props.theme.colors.comments.activeModeIconCircleStroke
|
|
|
|
|
: props.theme.colors.comments.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
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sync comment mode in store with comment mode in URL
|
|
|
|
|
* Fetch app comments when comment mode is selected
|
|
|
|
|
*/
|
|
|
|
|
// eslint-disable-next-line
|
|
|
|
|
const useUpdateCommentMode = async (currentUser?: User) => {
|
|
|
|
|
const location = useLocation();
|
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
const isCommentMode = useSelector(commentModeSelector);
|
|
|
|
|
|
|
|
|
|
const setCommentModeInStore = useCallback(
|
|
|
|
|
(updatedIsCommentMode) =>
|
|
|
|
|
dispatch(setCommentModeAction(updatedIsCommentMode)),
|
|
|
|
|
[],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const handleLocationUpdate = async () => {
|
|
|
|
|
const searchParams = new URL(window.location.href).searchParams;
|
|
|
|
|
const isCommentMode = searchParams.get("isCommentMode");
|
|
|
|
|
const isCommentsIntroSeen = await getCommentsIntroSeen();
|
|
|
|
|
const updatedIsCommentMode = isCommentMode === "true" ? true : false;
|
|
|
|
|
|
|
|
|
|
if (updatedIsCommentMode && !isCommentsIntroSeen) {
|
|
|
|
|
dispatch(showCommentsIntroCarousel());
|
|
|
|
|
} else {
|
|
|
|
|
setCommentModeInStore(updatedIsCommentMode);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// sync comment mode in store with comment mode in URL
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (window.location.href) {
|
|
|
|
|
handleLocationUpdate();
|
|
|
|
|
}
|
|
|
|
|
}, [location]);
|
|
|
|
|
|
|
|
|
|
// fetch applications comments when comment mode is turned on
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (isCommentMode) {
|
|
|
|
|
dispatch(fetchApplicationCommentsRequest());
|
|
|
|
|
}
|
|
|
|
|
}, [isCommentMode]);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const setCommentModeInUrl = (isCommentMode: boolean) => {
|
|
|
|
|
const currentURL = new URL(window.location.href);
|
|
|
|
|
const searchParams = currentURL.searchParams;
|
|
|
|
|
searchParams.set("isCommentMode", `${isCommentMode}`);
|
|
|
|
|
// remove comment link params so that they don't get retriggered
|
|
|
|
|
// on toggling comment mode
|
|
|
|
|
searchParams.delete("commentId");
|
|
|
|
|
searchParams.delete("commentThreadId");
|
|
|
|
|
history.replace({
|
|
|
|
|
pathname: currentURL.pathname,
|
|
|
|
|
search: searchParams.toString(),
|
|
|
|
|
hash: currentURL.hash,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
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}
|
|
|
|
|
position={Position.BOTTOM}
|
|
|
|
|
>
|
|
|
|
|
<Pen />
|
|
|
|
|
</TooltipComponent>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ViewModeReset() {
|
|
|
|
|
return (
|
|
|
|
|
<TooltipComponent
|
|
|
|
|
content={
|
|
|
|
|
<>
|
|
|
|
|
View Mode
|
|
|
|
|
<span style={{ color: "#fff", marginLeft: 20 }}>V</span>
|
|
|
|
|
</>
|
|
|
|
|
}
|
|
|
|
|
hoverOpenDelay={1000}
|
|
|
|
|
position={Position.BOTTOM}
|
|
|
|
|
>
|
|
|
|
|
<Eye />
|
|
|
|
|
</TooltipComponent>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-02 06:04:36 +00:00
|
|
|
const tourToolTipProps = {
|
|
|
|
|
hasOverlay: true,
|
|
|
|
|
modifiers: {
|
|
|
|
|
offset: { enabled: true, offset: "3, 20" },
|
|
|
|
|
arrow: {
|
|
|
|
|
enabled: true,
|
|
|
|
|
fn: (data: any) => ({
|
|
|
|
|
...data,
|
|
|
|
|
offsets: {
|
|
|
|
|
...data.offsets,
|
|
|
|
|
arrow: {
|
|
|
|
|
top: -8,
|
|
|
|
|
left: 80,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
pulseStyles: {
|
|
|
|
|
top: 20,
|
|
|
|
|
left: 28,
|
|
|
|
|
height: 30,
|
|
|
|
|
width: 30,
|
|
|
|
|
},
|
|
|
|
|
showPulse: true,
|
|
|
|
|
tourIndex: 0,
|
|
|
|
|
tourType: TourType.COMMENTS_TOUR,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function ViewOrEditMode({ mode }: { mode?: APP_MODE }) {
|
|
|
|
|
return mode === APP_MODE.EDIT ? <EditModeReset /> : <ViewModeReset />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function CommentModeBtn({
|
|
|
|
|
handleSetCommentModeButton,
|
|
|
|
|
isCommentMode,
|
|
|
|
|
showUnreadIndicator,
|
|
|
|
|
}: {
|
|
|
|
|
handleSetCommentModeButton: () => void;
|
|
|
|
|
isCommentMode: boolean;
|
|
|
|
|
showUnreadIndicator: boolean;
|
|
|
|
|
}) {
|
|
|
|
|
const CommentModeIcon = showUnreadIndicator ? CommentModeUnread : CommentMode;
|
|
|
|
|
|
|
|
|
|
return (
|
2021-07-05 07:12:02 +00:00
|
|
|
<ModeButton
|
|
|
|
|
active={isCommentMode}
|
|
|
|
|
className="t--switch-comment-mode-on"
|
|
|
|
|
onClick={handleSetCommentModeButton}
|
|
|
|
|
type="stroke"
|
|
|
|
|
>
|
2021-07-02 06:04:36 +00:00
|
|
|
<TooltipComponent
|
|
|
|
|
content={
|
|
|
|
|
<>
|
|
|
|
|
Comment Mode
|
|
|
|
|
<span style={{ color: "#fff", marginLeft: 20 }}>C</span>
|
|
|
|
|
</>
|
|
|
|
|
}
|
|
|
|
|
hoverOpenDelay={1000}
|
|
|
|
|
position={Position.BOTTOM}
|
|
|
|
|
>
|
|
|
|
|
<CommentModeIcon />
|
|
|
|
|
</TooltipComponent>
|
|
|
|
|
</ModeButton>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-20 12:03:08 +00:00
|
|
|
function ToggleCommentModeButton() {
|
|
|
|
|
const commentsEnabled = useSelector(areCommentsEnabledForUserAndAppSelector);
|
|
|
|
|
const isCommentMode = useSelector(commentModeSelector);
|
|
|
|
|
const currentUser = useSelector(getCurrentUser);
|
2021-07-02 06:04:36 +00:00
|
|
|
const [
|
|
|
|
|
showCommentButtonDiscoveryTooltip,
|
|
|
|
|
setShowCommentButtonDiscoveryTooltipInState,
|
|
|
|
|
] = useState(getShowCommentsButtonToolTip());
|
2021-05-20 12:03:08 +00:00
|
|
|
|
2021-07-07 15:13:44 +00:00
|
|
|
const showUnreadIndicator =
|
|
|
|
|
useSelector(showUnreadIndicatorSelector) ||
|
|
|
|
|
showCommentButtonDiscoveryTooltip;
|
|
|
|
|
|
2021-05-20 12:03:08 +00:00
|
|
|
useUpdateCommentMode(currentUser);
|
|
|
|
|
const proceedToNextTourStep = useProceedToNextTourStep(
|
|
|
|
|
TourType.COMMENTS_TOUR,
|
|
|
|
|
0,
|
|
|
|
|
);
|
|
|
|
|
|
2021-06-17 07:37:27 +00:00
|
|
|
const mode = useSelector((state: AppState) => state.entities.app.mode);
|
|
|
|
|
|
2021-07-02 06:04:36 +00:00
|
|
|
const handleSetCommentModeButton = useCallback(() => {
|
|
|
|
|
setCommentModeInUrl(true);
|
|
|
|
|
proceedToNextTourStep();
|
|
|
|
|
setShowCommentButtonDiscoveryTooltipInState(false);
|
|
|
|
|
setShowCommentsButtonToolTip();
|
|
|
|
|
}, [proceedToNextTourStep, setShowCommentButtonDiscoveryTooltipInState]);
|
|
|
|
|
|
2021-06-17 07:37:27 +00:00
|
|
|
// Show comment mode button only on the canvas editor and viewer
|
|
|
|
|
const [shouldHide, setShouldHide] = useState(false);
|
|
|
|
|
const location = useLocation();
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const pathName = window.location.pathname;
|
|
|
|
|
const shouldShow = matchBuilderPath(pathName) || matchViewerPath(pathName);
|
|
|
|
|
setShouldHide(!shouldShow);
|
|
|
|
|
}, [location]);
|
|
|
|
|
if (shouldHide) return null;
|
|
|
|
|
|
2021-05-20 12:03:08 +00:00
|
|
|
if (!commentsEnabled) return null;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Container>
|
2021-07-02 06:04:36 +00:00
|
|
|
<TourTooltipWrapper {...tourToolTipProps}>
|
2021-06-11 15:01:32 +00:00
|
|
|
<div style={{ display: "flex" }}>
|
|
|
|
|
<ModeButton
|
|
|
|
|
active={!isCommentMode}
|
|
|
|
|
onClick={() => setCommentModeInUrl(false)}
|
2021-07-05 07:12:02 +00:00
|
|
|
type="fill"
|
2021-06-11 15:01:32 +00:00
|
|
|
>
|
2021-07-02 06:04:36 +00:00
|
|
|
<ViewOrEditMode mode={mode} />
|
2021-06-11 15:01:32 +00:00
|
|
|
</ModeButton>
|
2021-07-02 06:04:36 +00:00
|
|
|
<TooltipComponent
|
|
|
|
|
content={createMessage(ONE_UNREAD_MESSAGE)}
|
|
|
|
|
isOpen={showCommentButtonDiscoveryTooltip}
|
2021-05-20 12:03:08 +00:00
|
|
|
>
|
2021-07-02 06:04:36 +00:00
|
|
|
<CommentModeBtn
|
|
|
|
|
{...{
|
|
|
|
|
handleSetCommentModeButton,
|
|
|
|
|
isCommentMode,
|
|
|
|
|
showUnreadIndicator,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</TooltipComponent>
|
2021-06-11 15:01:32 +00:00
|
|
|
</div>
|
2021-05-20 12:03:08 +00:00
|
|
|
</TourTooltipWrapper>
|
|
|
|
|
</Container>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default ToggleCommentModeButton;
|