feat: rewrite publish style

This commit is contained in:
DiamondThree
2023-01-23 11:23:41 +08:00
parent 6d41090e27
commit 0fa44f82dd
2 changed files with 50 additions and 54 deletions
@@ -14,16 +14,18 @@ import { toast } from '@/ui/toast';
import { WorkspaceUnit } from '@affine/datacenter'; import { WorkspaceUnit } from '@affine/datacenter';
import { useWorkspaceHelper } from '@/hooks/use-workspace-helper'; import { useWorkspaceHelper } from '@/hooks/use-workspace-helper';
import { useTranslation } from '@affine/i18n'; import { useTranslation } from '@affine/i18n';
import Loading from '@/components/loading';
import { Wrapper } from '@/ui/layout';
import { EnableWorkspaceButton } from '../enable-workspace'; import { EnableWorkspaceButton } from '../enable-workspace';
export const PublishPage = ({ workspace }: { workspace: WorkspaceUnit }) => { export const PublishPage = ({ workspace }: { workspace: WorkspaceUnit }) => {
const shareUrl = window.location.host + '/public-workspace/' + workspace.id; const shareUrl = window.location.host + '/public-workspace/' + workspace.id;
const { publishWorkspace } = useWorkspaceHelper(); const { publishWorkspace } = useWorkspaceHelper();
const { t } = useTranslation(); const { t } = useTranslation();
const [loaded, setLoaded] = useState(true); const [loaded, setLoaded] = useState(false);
const togglePublic = async (flag: boolean) => { const togglePublic = async (flag: boolean) => {
await publishWorkspace(workspace.id.toString(), flag); try {
await publishWorkspace(workspace.id.toString(), flag);
} catch (e) {
toast('Failed to publish workspace');
}
}; };
const copyUrl = () => { const copyUrl = () => {
@@ -34,17 +36,21 @@ export const PublishPage = ({ workspace }: { workspace: WorkspaceUnit }) => {
return ( return (
<> <>
{workspace.provider === 'affine' ? ( {workspace.provider === 'affine' ? (
<div> <div
style={{ height: '100%', display: 'flex', flexDirection: 'column' }}
>
<StyledPublishContent> <StyledPublishContent>
{workspace.published ? ( {workspace.published ? (
<> <>
<StyledPublishExplanation> <StyledPublishExplanation>
{t('Publishing')} The current workspace has been published to the web, everyone
can view the contents of this workspace through the link.
</StyledPublishExplanation> </StyledPublishExplanation>
<StyledSettingH2 marginTop={48}>
{t('Share with link')}
</StyledSettingH2>
<StyledPublishCopyContainer> <StyledPublishCopyContainer>
<StyledSettingH2 marginBottom={16}>
{t('Share with link')}
</StyledSettingH2>
<Input width={500} value={shareUrl} disabled={true}></Input> <Input width={500} value={shareUrl} disabled={true}></Input>
<StyledCopyButtonContainer> <StyledCopyButtonContainer>
<Button onClick={copyUrl} type="primary" shape="circle"> <Button onClick={copyUrl} type="primary" shape="circle">
@@ -56,6 +62,20 @@ export const PublishPage = ({ workspace }: { workspace: WorkspaceUnit }) => {
) : ( ) : (
<StyledPublishExplanation> <StyledPublishExplanation>
{t('Publishing Description')} {t('Publishing Description')}
<div style={{ marginTop: '64px' }}>
<Button
onClick={async () => {
setLoaded(true);
await togglePublic(true);
setLoaded(false);
}}
loading={loaded}
type="primary"
shape="circle"
>
{t('Publish to web')}
</Button>
</div>
</StyledPublishExplanation> </StyledPublishExplanation>
)} )}
</StyledPublishContent> </StyledPublishContent>
@@ -64,10 +84,11 @@ export const PublishPage = ({ workspace }: { workspace: WorkspaceUnit }) => {
<StyledStopPublishContainer> <StyledStopPublishContainer>
<Button <Button
onClick={async () => { onClick={async () => {
setLoaded(false); setLoaded(true);
await togglePublic(false); await togglePublic(false);
setLoaded(true); setLoaded(true);
}} }}
loading={false}
type="danger" type="danger"
shape="circle" shape="circle"
> >
@@ -75,39 +96,22 @@ export const PublishPage = ({ workspace }: { workspace: WorkspaceUnit }) => {
</Button> </Button>
</StyledStopPublishContainer> </StyledStopPublishContainer>
) : ( ) : (
<StyledPublishCopyContainer> <></>
<Button
onClick={async () => {
setLoaded(false);
await togglePublic(true);
setLoaded(true);
}}
type="primary"
shape="circle"
>
{t('Publish to web')}
</Button>
</StyledPublishCopyContainer>
)} )}
</div> </div>
) : ( ) : (
<StyledPublishContent> <StyledPublishContent>
<> <>
<StyledPublishExplanation> <StyledPublishExplanation>
{t('Publishing')} Publishing to web requires AFFiNE Cloud service.
</StyledPublishExplanation> </StyledPublishExplanation>
<StyledPublishCopyContainer> <div style={{ marginTop: '72px' }}>
<EnableWorkspaceButton></EnableWorkspaceButton> <EnableWorkspaceButton></EnableWorkspaceButton>
</StyledPublishCopyContainer> </div>
</> </>
</StyledPublishContent> </StyledPublishContent>
)} )}
{!loaded && (
<Wrapper>
<Loading size={25} />
</Wrapper>
)}
</> </>
); );
}; };
@@ -1,4 +1,4 @@
import { displayFlex, styled } from '@/styles'; import { styled } from '@/styles';
export const StyledSettingContainer = styled('div')(() => { export const StyledSettingContainer = styled('div')(() => {
return { return {
@@ -85,26 +85,25 @@ export const StyledSettingTagIconContainer = styled('div')(() => {
}; };
}); });
export const StyledSettingH2 = styled('h2')<{ marginTop?: number }>( export const StyledSettingH2 = styled('h2')<{
({ marginTop, theme }) => { marginTop?: number;
return { marginBottom?: number;
fontWeight: '500', }>(({ marginTop, marginBottom, theme }) => {
fontSize: theme.font.base, return {
lineHeight: theme.font.lineHeightBase, fontWeight: '500',
marginTop: marginTop ? `${marginTop}px` : '0px', fontSize: theme.font.base,
}; lineHeight: theme.font.lineHeightBase,
} marginTop: marginTop ? `${marginTop}px` : '0px',
); marginBottom: marginBottom ? `${marginBottom}px` : '0px',
};
});
export const StyledPublishExplanation = styled('div')(() => { export const StyledPublishExplanation = styled('div')(() => {
return { return {
...displayFlex('row', 'center', 'center'),
paddingRight: '48px', paddingRight: '48px',
fontWeight: '500', fontWeight: '500',
fontSize: '18px', fontSize: '18px',
lineHeight: '26px', lineHeight: '26px',
flex: 1,
marginBottom: '22px', marginBottom: '22px',
}; };
}); });
@@ -126,21 +125,14 @@ export const StyledWorkspaceType = styled('div')(() => {
export const StyledPublishCopyContainer = styled('div')(() => { export const StyledPublishCopyContainer = styled('div')(() => {
return { return {
marginTop: '12px', marginTop: '12px',
display: 'flex',
flexDirection: 'column',
alignItems: 'start',
justifyContent: 'center',
marginBottom: '20px', marginBottom: '20px',
paddingTop: '20px', paddingTop: '20px',
flex: 1,
}; };
}); });
export const StyledStopPublishContainer = styled('div')(() => { export const StyledStopPublishContainer = styled('div')(() => {
return { return {
position: 'absolute', textAlign: 'center',
bottom: '0',
left: '50%',
transform: 'translateX(-50%)',
marginBottom: '20px',
}; };
}); });