Skip to content

Commit

Permalink
feat(ui): add actions for video modal clicks
Browse files Browse the repository at this point in the history
  • Loading branch information
Mary Hipp authored and Mary Hipp committed Nov 21, 2024
1 parent 549f4e9 commit d4d406b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { ExternalLink, Flex, Spacer, Text } from '@invoke-ai/ui-library';
import { useAppDispatch } from 'app/store/storeHooks';
import type { VideoData } from 'features/system/components/VideosModal/data';
import { memo } from 'react';
import { videoModalLinkClicked } from 'features/system/store/actions';
import { memo, useCallback } from 'react';
import { useTranslation } from 'react-i18next';

const formatTime = ({ minutes, seconds }: { minutes: number; seconds: number }) => {
Expand All @@ -9,7 +11,12 @@ const formatTime = ({ minutes, seconds }: { minutes: number; seconds: number })

export const VideoCard = memo(({ video }: { video: VideoData }) => {
const { t } = useTranslation();
const dispatch = useAppDispatch();
const { tKey, link, length } = video;
const handleLinkClick = useCallback(() => {
dispatch(videoModalLinkClicked(t(`supportVideos.videos.${tKey}.title`)));
}, [dispatch, t, tKey]);

return (
<Flex flexDir="column" gap={1}>
<Flex alignItems="center" gap={2}>
Expand All @@ -18,7 +25,7 @@ export const VideoCard = memo(({ video }: { video: VideoData }) => {
</Text>
<Spacer />
<Text variant="subtext">{formatTime(length)}</Text>
<ExternalLink fontSize="sm" href={link} label={t('supportVideos.watch')} />
<ExternalLink fontSize="sm" href={link} label={t('supportVideos.watch')} onClick={handleLinkClick} />
</Flex>
<Text fontSize="md" variant="subtext">
{t(`supportVideos.videos.${tKey}.description`)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ModalOverlay,
Text,
} from '@invoke-ai/ui-library';
import { useAppDispatch } from 'app/store/storeHooks';
import ScrollableContent from 'common/components/OverlayScrollbars/ScrollableContent';
import { buildUseDisclosure } from 'common/hooks/useBoolean';
import {
Expand All @@ -18,25 +19,45 @@ import {
studioSessionsPlaylistLink,
} from 'features/system/components/VideosModal/data';
import { VideoCardList } from 'features/system/components/VideosModal/VideoCardList';
import { videoModalLinkClicked } from 'features/system/store/actions';
import { discordLink } from 'features/system/store/constants';
import { memo } from 'react';
import { memo, useCallback } from 'react';
import { Trans, useTranslation } from 'react-i18next';

export const [useVideosModal] = buildUseDisclosure(false);

const StudioSessionsPlaylistLink = () => {
const dispatch = useAppDispatch();
const handleLinkClick = useCallback(() => {
dispatch(videoModalLinkClicked('Studio session playlist'));
}, [dispatch]);

return (
<ExternalLink
fontWeight="semibold"
href={studioSessionsPlaylistLink}
display="inline-flex"
label="Studio Sessions playlist"
onClick={handleLinkClick}
/>
);
};

const DiscordLink = () => {
return <ExternalLink fontWeight="semibold" href={discordLink} display="inline-flex" label="Discord" />;
const dispatch = useAppDispatch();
const handleLinkClick = useCallback(() => {
dispatch(videoModalLinkClicked('Discord'));
}, [dispatch]);

return (
<ExternalLink
fontWeight="semibold"
href={discordLink}
display="inline-flex"
label="Discord"
onClick={handleLinkClick}
/>
);
};

const components = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
import { IconButton } from '@invoke-ai/ui-library';
import { useAppDispatch } from 'app/store/storeHooks';
import { useVideosModal } from 'features/system/components/VideosModal/VideosModal';
import { memo } from 'react';
import { videoModalOpened } from 'features/system/store/actions';
import { memo, useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { PiYoutubeLogoFill } from 'react-icons/pi';

export const VideosModalButton = memo(() => {
const { t } = useTranslation();
const dispatch = useAppDispatch();

const videosModal = useVideosModal();

const onClickOpen = useCallback(() => {
dispatch(videoModalOpened());
videosModal.open();
}, [videosModal, dispatch]);

return (
<IconButton
aria-label={t('supportVideos.supportVideos')}
variant="link"
icon={<PiYoutubeLogoFill fontSize={20} />}
boxSize={8}
onClick={videosModal.open}
onClick={onClickOpen}
/>
);
});
Expand Down
4 changes: 4 additions & 0 deletions invokeai/frontend/web/src/features/system/store/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { createAction } from '@reduxjs/toolkit';

export const videoModalLinkClicked = createAction<string>('system/videoModalLinkClicked');
export const videoModalOpened = createAction('system/videoModalOpened');

0 comments on commit d4d406b

Please sign in to comment.