Skip to content

Commit

Permalink
Comment button discovery tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhsaxena committed Jun 20, 2021
1 parent 62690b6 commit d1a5249
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 67 deletions.
41 changes: 20 additions & 21 deletions app/client/src/pages/Editor/EditorHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,27 +223,26 @@ export function EditorHeader(props: EditorHeaderProps) {
/>
</Link>
<Boxed step={OnboardingStep.FINISH}>
{currentApplication && (
<EditableAppName
className="t--application-name editable-application-name"
defaultValue={currentApplication.name || ""}
editInteractionKind={EditInteractionKind.SINGLE}
fill
isNewApp={
applicationList.filter((el) => el.id === applicationId)
.length > 0
}
onBlur={(value: string) =>
updateApplicationDispatch(applicationId || "", {
name: value,
currentApp: true,
})
}
savingState={
isSavingName ? SavingState.STARTED : SavingState.NOT_STARTED
}
/>
)}
<EditableAppName
className="t--application-name editable-application-name"
defaultValue={currentApplication?.name || ""}
editInteractionKind={EditInteractionKind.SINGLE}
fill
isNewApp={
applicationList.filter((el) => el.id === applicationId).length >
0
}
onBlur={(value: string) =>
updateApplicationDispatch(applicationId || "", {
name: value,
currentApp: true,
})
}
savingState={
isSavingName ? SavingState.STARTED : SavingState.NOT_STARTED
}
/>
)
<ToggleModeButton />
</Boxed>
</HeaderSection>
Expand Down
120 changes: 74 additions & 46 deletions app/client/src/pages/Editor/ToggleModeButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ import { APP_MODE } from "reducers/entityReducers/appReducer";

import { matchBuilderPath, matchViewerPath } from "constants/routes";

import {
getShowCommentsButtonToolTip,
setShowCommentsButtonToolTip,
} from "utils/storage";

const ModeButton = styled.div<{ active: boolean }>`
position: relative;
display: flex;
Expand Down Expand Up @@ -156,11 +161,51 @@ function ViewModeReset() {
);
}

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 ToggleCommentModeButton() {
const commentsEnabled = useSelector(areCommentsEnabledForUserAndAppSelector);
const isCommentMode = useSelector(commentModeSelector);
const showUnreadIndicator = useSelector(showUnreadIndicatorSelector);
const currentUser = useSelector(getCurrentUser);
const [
showCommentButtonDiscoveryTooltip,
setShowCommentButtonDiscoveryTooltipInState,
] = useState(false);

useEffect(() => {
(async () => {
const shouldShow = await getShowCommentsButtonToolTip();
setShowCommentButtonDiscoveryTooltipInState(!!shouldShow);
})();
}, []);

useUpdateCommentMode(currentUser);
const proceedToNextTourStep = useProceedToNextTourStep(
Expand All @@ -184,63 +229,46 @@ function ToggleCommentModeButton() {

const CommentModeIcon = showUnreadIndicator ? CommentModeUnread : CommentMode;

const handleSetCommentModeButton = () => {
setCommentModeInUrl(true);
proceedToNextTourStep();
setShowCommentButtonDiscoveryTooltipInState(false);
setShowCommentsButtonToolTip(false);
};

return (
<Container>
<TourTooltipWrapper
hasOverlay
modifiers={{
offset: { enabled: true, offset: "3, 20" },
arrow: {
enabled: true,
fn: (data) => ({
...data,
offsets: {
...data.offsets,
arrow: {
top: -8,
left: 80,
},
},
}),
},
}}
pulseStyles={{
top: 20,
left: 28,
height: 30,
width: 30,
}}
showPulse
tourIndex={0}
tourType={TourType.COMMENTS_TOUR}
>
<TourTooltipWrapper {...tourToolTipProps}>
<div style={{ display: "flex" }}>
<ModeButton
active={!isCommentMode}
onClick={() => setCommentModeInUrl(false)}
>
{mode === APP_MODE.EDIT ? <EditModeReset /> : <ViewModeReset />}
</ModeButton>
<ModeButton
active={isCommentMode}
onClick={() => {
setCommentModeInUrl(true);
proceedToNextTourStep();
}}
{/** TODO: move to messages */}
<TooltipComponent
content={<>You have 1 unread conversation</>}
isOpen={showCommentButtonDiscoveryTooltip}
>
<TooltipComponent
content={
<>
Comment Mode
<span style={{ color: "#fff", marginLeft: 20 }}>C</span>
</>
}
hoverOpenDelay={1000}
position={Position.BOTTOM}
<ModeButton
active={isCommentMode}
onClick={handleSetCommentModeButton}
>
<CommentModeIcon />
</TooltipComponent>
</ModeButton>
<TooltipComponent
content={
<>
Comment Mode
<span style={{ color: "#fff", marginLeft: 20 }}>C</span>
</>
}
hoverOpenDelay={1000}
position={Position.BOTTOM}
>
<CommentModeIcon />
</TooltipComponent>
</ModeButton>
</TooltipComponent>
</div>
</TourTooltipWrapper>
</Container>
Expand Down
28 changes: 28 additions & 0 deletions app/client/src/utils/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const STORAGE_KEYS: { [id: string]: string } = {
ONBOARDING_WELCOME_STATE: "OnboardingWelcomeState",
RECENT_ENTITIES: "RecentEntities",
COMMENTS_INTRO_SEEN: "CommentsIntroSeen",
SHOW_COMMENTS_BUTTON_TOOLTIP: "ShowCommentsButtonToolTip",
};

const store = localforage.createInstance({
Expand Down Expand Up @@ -204,3 +205,30 @@ export const getCommentsIntroSeen = async () => {
console.log("An error occurred while fetching COMMENTS_INTRO_SEEN", error);
}
};

export const setShowCommentsButtonToolTip = async (flag: boolean) => {
try {
await store.setItem(STORAGE_KEYS.SHOW_COMMENTS_BUTTON_TOOLTIP, flag);
return true;
} catch (error) {
console.log(
"An error occurred when setting SHOW_COMMENTS_BUTTON_TOOLTIP",
error,
);
return false;
}
};

export const getShowCommentsButtonToolTip = async () => {
try {
const shouldShow = (await store.getItem(
STORAGE_KEYS.SHOW_COMMENTS_BUTTON_TOOLTIP,
)) as boolean;
return shouldShow === false ? false : true;
} catch (error) {
console.log(
"An error occurred while fetching SHOW_COMMENTS_BUTTON_TOOLTIP",
error,
);
}
};

0 comments on commit d1a5249

Please sign in to comment.