Skip to content

Commit

Permalink
feat(tutorial): Update tutorial tooltip condition
Browse files Browse the repository at this point in the history
  • Loading branch information
xrutayisire committed Oct 27, 2023
1 parent 9486332 commit 5e97d59
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
import {
userHasSeenChangesToolTip,
userHasSeenSimulatorToolTip,
userHasSeenTutorialsToolTip,
} from "@src/modules/userContext";
import useSliceMachineActions from "@src/modules/useSliceMachineActions";
import { ChangesRightElement } from "./ChangesRightElement";
Expand Down Expand Up @@ -68,13 +67,11 @@ const useOpenChangesHoverCard = () => {
const {
hasSeenChangesToolTip,
hasSeenSimulatorToolTip,
hasSeenTutorialsToolTip,
isSavingCustomType,
isSavingSlice,
} = useSelector((store: SliceMachineStoreType) => ({
hasSeenChangesToolTip: userHasSeenChangesToolTip(store),
hasSeenSimulatorToolTip: userHasSeenSimulatorToolTip(store),
hasSeenTutorialsToolTip: userHasSeenTutorialsToolTip(store),
isSavingCustomType: isLoading(store, LoadingKeysEnum.SAVE_CUSTOM_TYPE),
isSavingSlice: isLoading(store, LoadingKeysEnum.SAVE_SLICE),
}));
Expand All @@ -88,7 +85,6 @@ const useOpenChangesHoverCard = () => {

return (
!hasSeenChangesToolTip &&
hasSeenTutorialsToolTip &&
hasSeenSimulatorToolTip &&
!isSaving &&
prevIsSaving
Expand Down
41 changes: 24 additions & 17 deletions packages/slice-machine/components/Navigation/VideoItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import {
RefCallback,
ReactNode,
forwardRef,
PropsWithChildren,
} from "react";
import { useSelector } from "react-redux";
import ReactTooltip from "react-tooltip";
import { Close, Flex, Paragraph } from "theme-ui";
import { ReactTooltipPortal } from "@components/ReactTooltipPortal";
Expand All @@ -21,6 +23,8 @@ import {
HoverCardTitle,
} from "@src/components/HoverCard";
import { useAdapterName } from "@src/hooks/useAdapterName";
import { getUserReview } from "@src/modules/userContext";
import { SliceMachineStoreType } from "@src/redux/type";

import style from "./VideoItem.module.css";

Expand All @@ -44,7 +48,7 @@ export const VideoItem = forwardRef<HTMLLIElement, VideoItemProps>(
>
<SideNavListItem ref={ref}>
<SideNavLink
title="Tutorial"
title={isNext ? "Academy" : "Tutorial"}
href={videoUrl}
target="_blank"
Icon={(props) => <PlayCircleIcon {...props} />}
Expand Down Expand Up @@ -73,10 +77,17 @@ const MaybeVideoTooltipWrapper: FC<MaybeVideoTooltipWrapperProps> = ({
onClose,
hasSeenTutorialsToolTip,
}) => {
const { userReview } = useSelector((store: SliceMachineStoreType) => ({
userReview: getUserReview(store),
}));
const open =
!hasSeenTutorialsToolTip &&
(userReview.onboarding || userReview.advancedRepository);

if (isNext) {
return (
<HoverCard
open={!hasSeenTutorialsToolTip}
open={open}
side="right"
onClose={onClose}
trigger={children}
Expand All @@ -89,7 +100,7 @@ const MaybeVideoTooltipWrapper: FC<MaybeVideoTooltipWrapperProps> = ({
component="video"
cloudName="dmtf1daqp"
publicId="Tooltips/pa-course-overview_eaopsn"
poster="/phil.png"
poster="/prismic-academy-101.png"
controls
/>
<HoverCardDescription>
Expand All @@ -102,22 +113,18 @@ const MaybeVideoTooltipWrapper: FC<MaybeVideoTooltipWrapperProps> = ({
}

return (
<OldVideoItem
onClose={onClose}
hasSeenTutorialsToolTip={hasSeenTutorialsToolTip}
>
<OldVideoItem onClose={onClose} open={open}>
{children}
</OldVideoItem>
);
};

type OldVideoItemProps = VideoItemProps & { children: ReactNode };
type OldVideoItemProps = PropsWithChildren<{
open: boolean;
onClose: () => void;
}>;

const OldVideoItem: FC<OldVideoItemProps> = ({
hasSeenTutorialsToolTip,
onClose,
children,
}) => {
const OldVideoItem: FC<OldVideoItemProps> = ({ open, onClose, children }) => {
const id = "video-tool-tip";
const ref = useRef<HTMLDivElement | null>(null);

Expand All @@ -126,12 +133,12 @@ const OldVideoItem: FC<OldVideoItemProps> = ({
if (ref.current) {
return;
}
if (node && !hasSeenTutorialsToolTip) {
if (node && open) {
setTimeout(() => ReactTooltip.show(node), 5000);
ref.current = node;
}
ref.current = node;
},
[hasSeenTutorialsToolTip],
[open],
);

return (
Expand All @@ -144,7 +151,7 @@ const OldVideoItem: FC<OldVideoItemProps> = ({
>
{children}

{!hasSeenTutorialsToolTip && <ToolTip id={id} onClose={onClose} />}
{open && <ToolTip id={id} onClose={onClose} />}
</div>
);
};
Expand Down
15 changes: 2 additions & 13 deletions packages/slice-machine/components/Navigation/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ describe("Side Navigation", () => {

renderSideNavigation({ canUpdate: true });

const link = (await screen.findByText("Tutorial")).parentElement
const link = (await screen.findByText("Academy")).parentElement
?.parentElement as HTMLElement;

await waitFor(() =>
Expand All @@ -284,7 +284,7 @@ describe("Side Navigation", () => {
});

test("Video Item not next", async () => {
const { user } = renderSideNavigation({ canUpdate: true });
renderSideNavigation({ canUpdate: true });

const link = (await screen.findByText("Tutorial")).parentElement
?.parentElement as HTMLElement;
Expand All @@ -293,16 +293,5 @@ describe("Side Navigation", () => {
"https://youtube.com/playlist?list=PLUVZjQltoA3wnaQudcqQ3qdZNZ6hyfyhH",
);
expect(link).toHaveAttribute("target", "_blank");

await user.hover(link);

const tooltip = await screen.findByRole("tooltip");
expect(tooltip).toBeVisible();
const closeButton = await within(tooltip).findByTestId(
"video-tooltip-close-button",
);
await user.click(closeButton);

expect(screen.queryByRole("tooltip")).not.toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import { useRouter } from "next/router";
import ReactTooltip from "react-tooltip";

import { PlayCircleIcon } from "@src/icons/PlayCircleIcon";
import {
userHasSeenSimulatorToolTip,
userHasSeenTutorialsToolTip,
} from "@src/modules/userContext";
import { userHasSeenSimulatorToolTip } from "@src/modules/userContext";
import { useSelector } from "react-redux";
import { SliceMachineStoreType } from "@src/redux/type";
import useSliceMachineActions from "@src/modules/useSliceMachineActions";
Expand Down Expand Up @@ -97,28 +94,18 @@ const SimulatorButton: React.FC<{

const { setSeenSimulatorToolTip } = useSliceMachineActions();

const { hasSeenSimulatorTooltip, hasSeenTutorialsToolTip } = useSelector(
const { hasSeenSimulatorTooltip } = useSelector(
(store: SliceMachineStoreType) => ({
hasSeenSimulatorTooltip: userHasSeenSimulatorToolTip(store),
hasSeenTutorialsToolTip: userHasSeenTutorialsToolTip(store),
}),
);

useEffect(() => {
const node = ref.current;
if (
node &&
isSimulatorAvailableForFramework &&
!hasSeenSimulatorTooltip &&
hasSeenTutorialsToolTip
) {
if (node && isSimulatorAvailableForFramework && !hasSeenSimulatorTooltip) {
setTimeout(() => ReactTooltip.show(node), 5000);
}
}, [
isSimulatorAvailableForFramework,
hasSeenSimulatorTooltip,
hasSeenTutorialsToolTip,
]);
}, [isSimulatorAvailableForFramework, hasSeenSimulatorTooltip]);

const onCloseToolTip = () => {
setSeenSimulatorToolTip();
Expand All @@ -131,9 +118,7 @@ const SimulatorButton: React.FC<{
const disabled = !isSimulatorAvailableForFramework || isTouched;

const shouldShowSimulatorTooltip =
isSimulatorAvailableForFramework &&
!hasSeenSimulatorTooltip &&
hasSeenTutorialsToolTip;
isSimulatorAvailableForFramework && !hasSeenSimulatorTooltip;

const shouldShowNeedToSaveTooltip =
isSimulatorAvailableForFramework &&
Expand Down
Binary file removed packages/slice-machine/public/phil.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const Video = {
component="video"
cloudName="dmtf1daqp"
publicId="Tooltips/pa-course-overview_eaopsn"
poster="phil.png"
poster="prismic-academy-101.png"
/>
<HoverCardDescription>
Lorem ipsum dolor sit amet consectetur. Aenean purus aliquam vel eget
Expand Down

0 comments on commit 5e97d59

Please sign in to comment.