import { prefixUrl } from '@affine/env'; import { Trans, useTranslation } from '@affine/i18n'; import type { LocalWorkspace } from '@affine/workspace/type'; import { WorkspaceFlavour } from '@affine/workspace/type'; import { useBlockSuiteWorkspacePageIsPublic } from '@toeverything/hooks/use-blocksuite-workspace-page-is-public'; import type { FC } from 'react'; import { useState } from 'react'; import { useCallback, useMemo } from 'react'; import { toast } from '../..'; import { PublicLinkDisableModal } from './disable-public-link'; import { descriptionStyle, inputButtonRowStyle, menuItemStyle, } from './index.css'; import type { ShareMenuProps } from './ShareMenu'; import { StyledButton, StyledDisableButton, StyledInput, StyledLinkSpan, } from './styles'; export const LocalSharePage: FC = props => { const { t } = useTranslation(); return (
{t('Shared Pages Description')}
{ props.onEnableAffineCloud(props.workspace as LocalWorkspace); }} > {t('Enable AFFiNE Cloud')}
); }; export const AffineSharePage: FC = props => { const [isPublic, setIsPublic] = useBlockSuiteWorkspacePageIsPublic( props.currentPage ); const [showDisable, setShowDisable] = useState(false); const { t } = useTranslation(); const sharingUrl = useMemo(() => { return `${prefixUrl}public-workspace/${props.workspace.id}/${props.currentPage.id}`; }, [props.workspace.id, props.currentPage.id]); const onClickCreateLink = useCallback(() => { setIsPublic(true); }, [setIsPublic]); const onClickCopyLink = useCallback(() => { navigator.clipboard.writeText(sharingUrl); toast(t('Copied link to clipboard')); }, [sharingUrl, t]); return (
{t('Create Shared Link Description')}
{!isPublic && ( {t('Create')} )} {isPublic && ( {t('Copy Link')} )}
The entire Workspace is published on the web and can be edited via { props.onOpenWorkspaceSettings(props.workspace); }} > Workspace Settings .
{isPublic && ( <> setShowDisable(true)}> {t('Disable Public Link')} { setShowDisable(false); }} /> )}
); }; export const SharePage: FC = props => { if (props.workspace.flavour === WorkspaceFlavour.LOCAL) { return ; } else if (props.workspace.flavour === WorkspaceFlavour.AFFINE) { return ; } throw new Error('Unreachable'); };