import { Button, theme } from "@prismicio/editor-ui";
import { useRouter } from "next/router";
import React, { PropsWithChildren, useEffect, useRef } from "react";
import { useSelector } from "react-redux";
import ReactTooltip from "react-tooltip";
import { telemetry } from "@/apiClient";
import {
HoverCard,
HoverCardCloseButton,
HoverCardDescription,
HoverCardMedia,
HoverCardTitle,
} from "@/components/HoverCard";
import { PlayCircleIcon } from "@/icons/PlayCircleIcon";
import {
SIMULATOR_WINDOW_ID,
VIDEO_SIMULATOR_TOOLTIP,
} from "@/legacy/lib/consts";
import { userHasSeenSimulatorToolTip } from "@/modules/userContext";
import useSliceMachineActions from "@/modules/useSliceMachineActions";
import { SliceMachineStoreType } from "@/redux/type";
const SimulatorOnboardingTooltip: React.FC<
PropsWithChildren<{
open: boolean;
onClose: () => void;
}>
> = ({ children, open, onClose }) => {
return (
Simulate your slices
{
void telemetry.track({
event: "open-video-tutorials",
video: VIDEO_SIMULATOR_TOOLTIP,
});
}}
/>
Minimize context-switching by previewing your Slice components in the
simulator.
Got it
);
};
const SimulatorButton: React.FC<{
disabled: boolean;
}> = ({ disabled }) => {
const router = useRouter();
const ref = useRef(null);
const { setSeenSimulatorToolTip } = useSliceMachineActions();
const { hasSeenSimulatorTooltip } = useSelector(
(store: SliceMachineStoreType) => ({
hasSeenSimulatorTooltip: userHasSeenSimulatorToolTip(store),
}),
);
useEffect(() => {
const node = ref.current;
if (node && !hasSeenSimulatorTooltip) {
setTimeout(() => ReactTooltip.show(node), 5000);
}
}, [hasSeenSimulatorTooltip]);
const onCloseToolTip = () => {
setSeenSimulatorToolTip();
if (ref.current) {
const { current } = ref;
ReactTooltip.hide(current);
}
};
const shouldShowSimulatorTooltip = !hasSeenSimulatorTooltip;
return (
);
};
export default SimulatorButton;