2022-10-28 16:11:08 +00:00
|
|
|
import {makeT} from 'app/client/lib/localization';
|
2023-04-06 15:10:29 +00:00
|
|
|
import {logTelemetryEvent} from 'app/client/lib/telemetry';
|
2023-03-27 17:25:25 +00:00
|
|
|
import {getMainOrgUrl} from 'app/client/models/gristUrlState';
|
2022-06-17 03:43:26 +00:00
|
|
|
import {cssLinkText, cssPageEntryMain, cssPageIcon, cssPageLink} from 'app/client/ui/LeftPanelCommon';
|
2023-03-27 17:25:25 +00:00
|
|
|
import {YouTubePlayer} from 'app/client/ui/YouTubePlayer';
|
2022-09-06 01:51:57 +00:00
|
|
|
import {theme} from 'app/client/ui2018/cssVars';
|
2022-06-17 03:43:26 +00:00
|
|
|
import {icon} from 'app/client/ui2018/icons';
|
2022-12-20 02:06:39 +00:00
|
|
|
import {cssModalCloseButton, modal} from 'app/client/ui2018/modals';
|
2024-07-22 15:10:57 +00:00
|
|
|
import {isFeatureEnabled, ONBOARDING_VIDEO_YOUTUBE_EMBED_ID} from 'app/common/gristUrls';
|
|
|
|
import {dom, keyframes, makeTestId, styled} from 'grainjs';
|
2022-06-17 03:43:26 +00:00
|
|
|
|
2022-10-28 16:11:08 +00:00
|
|
|
const t = makeT('OpenVideoTour');
|
|
|
|
|
2022-06-17 03:43:26 +00:00
|
|
|
const testId = makeTestId('test-video-tour-');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens a modal containing a video tour of Grist.
|
|
|
|
*/
|
|
|
|
export function openVideoTour(refElement: HTMLElement) {
|
|
|
|
return modal(
|
2023-04-06 15:10:29 +00:00
|
|
|
(ctl, owner) => {
|
|
|
|
const youtubePlayer = YouTubePlayer.create(owner,
|
2024-07-22 15:10:57 +00:00
|
|
|
ONBOARDING_VIDEO_YOUTUBE_EMBED_ID,
|
2023-04-06 15:10:29 +00:00
|
|
|
{
|
|
|
|
onPlayerReady: (player) => player.playVideo(),
|
|
|
|
height: '100%',
|
|
|
|
width: '100%',
|
|
|
|
origin: getMainOrgUrl(),
|
|
|
|
},
|
|
|
|
cssYouTubePlayer.cls(''),
|
|
|
|
);
|
|
|
|
|
|
|
|
owner.onDispose(async () => {
|
|
|
|
if (youtubePlayer.isLoading()) { return; }
|
|
|
|
|
2023-05-18 22:35:39 +00:00
|
|
|
logTelemetryEvent('watchedVideoTour', {
|
2023-06-06 17:08:50 +00:00
|
|
|
limited: {watchTimeSeconds: Math.floor(youtubePlayer.getCurrentTime())},
|
2023-04-06 15:10:29 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-06-17 03:43:26 +00:00
|
|
|
return [
|
|
|
|
cssModal.cls(''),
|
2022-12-20 02:06:39 +00:00
|
|
|
cssModalCloseButton(
|
2022-06-17 03:43:26 +00:00
|
|
|
cssCloseIcon('CrossBig'),
|
|
|
|
dom.on('click', () => ctl.close()),
|
|
|
|
testId('close'),
|
|
|
|
),
|
2023-04-06 15:10:29 +00:00
|
|
|
cssYouTubePlayerContainer(youtubePlayer.buildDom()),
|
2022-06-17 03:43:26 +00:00
|
|
|
testId('modal'),
|
|
|
|
];
|
|
|
|
},
|
|
|
|
{
|
|
|
|
refElement,
|
|
|
|
variant: 'collapsing',
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a text button that shows the video tour on click.
|
|
|
|
*/
|
|
|
|
export function createVideoTourTextButton(): HTMLDivElement {
|
|
|
|
const elem: HTMLDivElement = cssVideoTourTextButton(
|
|
|
|
cssVideoIcon('Video'),
|
2022-12-06 13:57:29 +00:00
|
|
|
t("Grist Video Tour"),
|
2022-06-17 03:43:26 +00:00
|
|
|
dom.on('click', () => openVideoTour(elem)),
|
|
|
|
testId('text-button'),
|
|
|
|
);
|
|
|
|
|
|
|
|
return elem;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the "Video Tour" button for the "Tools" section of the left panel.
|
|
|
|
*
|
|
|
|
* Shows the video tour on click.
|
|
|
|
*/
|
|
|
|
export function createVideoTourToolsButton(): HTMLDivElement | null {
|
2023-05-20 23:58:41 +00:00
|
|
|
if (!isFeatureEnabled('helpCenter')) { return null; }
|
2022-06-17 03:43:26 +00:00
|
|
|
|
|
|
|
let iconElement: HTMLElement;
|
|
|
|
|
|
|
|
return cssPageEntryMain(
|
|
|
|
cssPageLink(
|
|
|
|
iconElement = cssPageIcon('Video'),
|
2022-12-06 13:57:29 +00:00
|
|
|
cssLinkText(t("Video Tour")),
|
2022-06-17 03:43:26 +00:00
|
|
|
dom.cls('tour-help-center'),
|
|
|
|
dom.on('click', () => openVideoTour(iconElement)),
|
|
|
|
testId('tools-button'),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const cssModal = styled('div', `
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
gap: 16px;
|
|
|
|
padding: 16px;
|
|
|
|
width: 100%;
|
|
|
|
max-width: 864px;
|
|
|
|
`);
|
|
|
|
|
2024-07-22 15:10:57 +00:00
|
|
|
const delayedVisibility = keyframes(`
|
|
|
|
to {
|
|
|
|
visibility: visible;
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
2023-03-27 17:25:25 +00:00
|
|
|
const cssYouTubePlayerContainer = styled('div', `
|
2022-06-17 03:43:26 +00:00
|
|
|
position: relative;
|
|
|
|
padding-bottom: 56.25%;
|
|
|
|
height: 0;
|
2024-07-22 15:10:57 +00:00
|
|
|
/* Wait until the modal is finished animating. */
|
|
|
|
visibility: hidden;
|
|
|
|
animation: 0s linear 0.4s forwards ${delayedVisibility};
|
2022-06-17 03:43:26 +00:00
|
|
|
`);
|
|
|
|
|
2023-03-27 17:25:25 +00:00
|
|
|
const cssYouTubePlayer = styled('div', `
|
2022-06-17 03:43:26 +00:00
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssVideoTourTextButton = styled('div', `
|
2022-09-06 01:51:57 +00:00
|
|
|
color: ${theme.controlFg};
|
2022-06-17 03:43:26 +00:00
|
|
|
cursor: pointer;
|
|
|
|
|
|
|
|
&:hover {
|
2022-09-06 01:51:57 +00:00
|
|
|
color: ${theme.controlHoverFg};
|
2022-06-17 03:43:26 +00:00
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssVideoIcon = styled(icon, `
|
2022-09-06 01:51:57 +00:00
|
|
|
background-color: ${theme.controlFg};
|
2022-06-17 03:43:26 +00:00
|
|
|
cursor: pointer;
|
|
|
|
margin: 0px 4px 3px 0;
|
|
|
|
|
|
|
|
.${cssVideoTourTextButton.className}:hover > & {
|
2022-09-06 01:51:57 +00:00
|
|
|
background-color: ${theme.controlHoverFg};
|
2022-06-17 03:43:26 +00:00
|
|
|
}
|
|
|
|
`);
|
|
|
|
|
|
|
|
const cssCloseIcon = styled(icon, `
|
|
|
|
padding: 12px;
|
|
|
|
`);
|