diff --git a/web/components/action-buttons/ActionButton/ActionButton.stories.tsx b/web/components/action-buttons/ActionButton/ActionButton.stories.tsx index d98fa7742..e174782dc 100644 --- a/web/components/action-buttons/ActionButton/ActionButton.stories.tsx +++ b/web/components/action-buttons/ActionButton/ActionButton.stories.tsx @@ -1,5 +1,6 @@ import React from 'react'; import { ComponentStory, ComponentMeta } from '@storybook/react'; +import { action } from '@storybook/addon-actions'; import { ActionButton } from './ActionButton'; export default { @@ -14,8 +15,14 @@ export default { }, } as ComponentMeta; -// eslint-disable-next-line @typescript-eslint/no-unused-vars -const Template: ComponentStory = args => ; +const itemSelected = a => { + console.log('itemSelected', a); + action(a.title); +}; + +const Template: ComponentStory = args => ( + +); // eslint-disable-next-line @typescript-eslint/no-unused-vars export const Example1 = Template.bind({}); diff --git a/web/components/action-buttons/ActionButton/ActionButton.tsx b/web/components/action-buttons/ActionButton/ActionButton.tsx index abdf06a07..739b4bb41 100644 --- a/web/components/action-buttons/ActionButton/ActionButton.tsx +++ b/web/components/action-buttons/ActionButton/ActionButton.tsx @@ -1,46 +1,30 @@ import { Button } from 'antd'; -import { FC, useState } from 'react'; -import { Modal } from '../../ui/Modal/Modal'; +import { FC } from 'react'; import { ExternalAction } from '../../../interfaces/external-action'; import styles from './ActionButton.module.scss'; export type ActionButtonProps = { action: ExternalAction; primary?: boolean; + externalActionSelected: (action: ExternalAction) => void; }; export const ActionButton: FC = ({ - action: { url, title, description, icon, color, openExternally }, + action, primary = true, + externalActionSelected, }) => { - const [showModal, setShowModal] = useState(false); - - const onButtonClicked = () => { - if (openExternally) { - window.open(url, '_blank'); - } else { - setShowModal(true); - } - }; + const { title, description, icon, color } = action; return ( - <> - - setShowModal(false)} - /> - + ); }; diff --git a/web/components/action-buttons/ActionButtonRow/ActionButtonRow.stories.tsx b/web/components/action-buttons/ActionButtonRow/ActionButtonRow.stories.tsx index ae7550fad..d0afab5fd 100644 --- a/web/components/action-buttons/ActionButtonRow/ActionButtonRow.stories.tsx +++ b/web/components/action-buttons/ActionButtonRow/ActionButtonRow.stories.tsx @@ -1,5 +1,6 @@ import React from 'react'; import { ComponentStory, ComponentMeta } from '@storybook/react'; +import { action } from '@storybook/addon-actions'; import { ActionButtonRow } from './ActionButtonRow'; import { ActionButton } from '../ActionButton/ActionButton'; @@ -42,7 +43,12 @@ const actions = [ }, ]; -const buttons = actions.map(action => ); +const itemSelected = a => { + console.log('itemSelected', a); + action(a.title); +}; + +const buttons = actions.map(a => ); export const Example1 = Template.bind({}); Example1.args = { buttons, diff --git a/web/components/ui/Content/Content.tsx b/web/components/ui/Content/Content.tsx index 466120285..ad8ef7388 100644 --- a/web/components/ui/Content/Content.tsx +++ b/web/components/ui/Content/Content.tsx @@ -34,13 +34,11 @@ import { ServerStatus } from '../../../interfaces/server-status.model'; import { Statusbar } from '../Statusbar/Statusbar'; import { ChatMessage } from '../../../interfaces/chat-message.model'; import { FollowerCollection } from '../followers/FollowerCollection/FollowerCollection'; +import { ExternalAction } from '../../../interfaces/external-action'; +import { Modal } from '../Modal/Modal'; const { Content: AntContent } = Layout; -// Lazy loaded components - -const Modal = dynamic(() => import('../Modal/Modal').then(mod => mod.Modal)); - const BrowserNotifyModal = dynamic(() => import('../../modals/BrowserNotifyModal/BrowserNotifyModal').then(mod => mod.BrowserNotifyModal), ); @@ -163,6 +161,19 @@ const MobileContent = ({ ); }; +const ExternalModal = ({ externalActionToDisplay, setExternalActionToDisplay }) => { + const { title, description, url } = externalActionToDisplay; + return ( + setExternalActionToDisplay(null)} + /> + ); +}; + export const Content: FC = () => { const appState = useRecoilValue(appStateAtom); const clientConfig = useRecoilValue(clientConfigStateAtom); @@ -194,9 +205,23 @@ export const Content: FC = () => { const { account: fediverseAccount } = federation; const { browser: browserNotifications } = notifications; const { enabled: browserNotificationsEnabled } = browserNotifications; + const [externalActionToDisplay, setExternalActionToDisplay] = useState(null); + + const externalActionSelected = (action: ExternalAction) => { + const { openExternally, url } = action; + if (openExternally) { + window.open(url, '_blank'); + } else { + setExternalActionToDisplay(action); + } + }; const externalActionButtons = externalActions.map(action => ( - + )); const incrementVisitCounter = () => { @@ -232,88 +257,100 @@ export const Content: FC = () => { incrementVisitCounter(); checkIfMobile(); window.addEventListener('resize', checkIfMobile); + return () => { + window.removeEventListener('resize', checkIfMobile); + }; }, []); const showChat = !chatDisabled && isChatAvailable && isChatVisible; return ( -
- - -
-
- {online && } - {!online && !appState.appLoading && ( - setShowNotifyPopup(true)} - /> - )} - {online && ( - - )} -
-
-
- - {externalActionButtons} - - setShowNotifyPopup(true)} - notificationClosed={() => disableNotifyReminderPopup()} - > - setShowNotifyPopup(true)} /> - - - - disableNotifyReminderPopup()} - handleCancel={() => disableNotifyReminderPopup()} - > - - + <> +
+ + +
+
+ {online && } + {!online && !appState.appLoading && ( + setShowNotifyPopup(true)} + /> + )} + {online && ( + + )}
+
+
+ + {externalActionButtons} + + setShowNotifyPopup(true)} + notificationClosed={() => disableNotifyReminderPopup()} + > + setShowNotifyPopup(true)} /> + + + + disableNotifyReminderPopup()} + handleCancel={() => disableNotifyReminderPopup()} + > + + +
+
+ {isMobile && isChatVisible ? ( + + ) : ( + + )}
- {isMobile && isChatVisible ? ( - - ) : ( - - )} -
- {showChat && !isMobile && } - - - {!isMobile &&
} -
+ {showChat && !isMobile && } + + + {!isMobile &&
} +
+ + {externalActionToDisplay && ( + + )} + ); }; export default Content;