feat: publish local workspace (#1406)
This commit is contained in:
@@ -4,11 +4,9 @@ import { CloseIcon } from '@blocksuite/icons';
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { useCurrentUser } from '../../../hooks/current/use-current-user';
|
import { useCurrentUser } from '../../../hooks/current/use-current-user';
|
||||||
import { AffineWorkspace } from '../../../shared';
|
|
||||||
import { Content, ContentTitle, Header, StyleButton, StyleTips } from './style';
|
import { Content, ContentTitle, Header, StyleButton, StyleTips } from './style';
|
||||||
|
|
||||||
interface EnableAffineCloudModalProps {
|
interface EnableAffineCloudModalProps {
|
||||||
workspace: AffineWorkspace;
|
|
||||||
open: boolean;
|
open: boolean;
|
||||||
onConfirm: () => void;
|
onConfirm: () => void;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
|
|||||||
@@ -7,24 +7,27 @@ import {
|
|||||||
Wrapper,
|
Wrapper,
|
||||||
} from '@affine/component';
|
} from '@affine/component';
|
||||||
import { useTranslation } from '@affine/i18n';
|
import { useTranslation } from '@affine/i18n';
|
||||||
|
import { Box } from '@mui/material';
|
||||||
import React, { useCallback, useEffect, useState } from 'react';
|
import React, { useCallback, useEffect, useState } from 'react';
|
||||||
|
|
||||||
import { lockMutex } from '../../../../../atoms';
|
|
||||||
import { useToggleWorkspacePublish } from '../../../../../hooks/affine/use-toggle-workspace-publish';
|
import { useToggleWorkspacePublish } from '../../../../../hooks/affine/use-toggle-workspace-publish';
|
||||||
|
import { transformWorkspace } from '../../../../../plugins';
|
||||||
import {
|
import {
|
||||||
AffineOfficialWorkspace,
|
AffineOfficialWorkspace,
|
||||||
AffineWorkspace,
|
AffineWorkspace,
|
||||||
LocalWorkspace,
|
LocalWorkspace,
|
||||||
RemWorkspaceFlavour,
|
RemWorkspaceFlavour,
|
||||||
} from '../../../../../shared';
|
} from '../../../../../shared';
|
||||||
|
import { apis } from '../../../../../shared/apis';
|
||||||
import { Unreachable } from '../../../affine-error-eoundary';
|
import { Unreachable } from '../../../affine-error-eoundary';
|
||||||
import { EnableAffineCloudModal } from '../../../enable-affine-cloud-modal';
|
import { EnableAffineCloudModal } from '../../../enable-affine-cloud-modal';
|
||||||
|
import { WorkspaceSettingDetailProps } from '../../index';
|
||||||
|
|
||||||
export type PublishPanelProps = {
|
export type PublishPanelProps = WorkspaceSettingDetailProps & {
|
||||||
workspace: AffineOfficialWorkspace;
|
workspace: AffineOfficialWorkspace;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type PublishPanelAffineProps = {
|
export type PublishPanelAffineProps = WorkspaceSettingDetailProps & {
|
||||||
workspace: AffineWorkspace;
|
workspace: AffineWorkspace;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -70,9 +73,7 @@ const PublishPanelAffine: React.FC<PublishPanelAffineProps> = ({
|
|||||||
</FlexWrapper>
|
</FlexWrapper>
|
||||||
<Button
|
<Button
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
lockMutex(async () => {
|
await publishWorkspace(false);
|
||||||
return publishWorkspace(false);
|
|
||||||
});
|
|
||||||
}}
|
}}
|
||||||
loading={false}
|
loading={false}
|
||||||
type="danger"
|
type="danger"
|
||||||
@@ -97,51 +98,76 @@ const PublishPanelAffine: React.FC<PublishPanelAffineProps> = ({
|
|||||||
{t('Publish to web')}
|
{t('Publish to web')}
|
||||||
</Button>
|
</Button>
|
||||||
<EnableAffineCloudModal
|
<EnableAffineCloudModal
|
||||||
workspace={workspace}
|
|
||||||
open={open}
|
open={open}
|
||||||
onClose={() => {
|
onClose={() => {
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
}}
|
}}
|
||||||
onConfirm={() => {
|
onConfirm={async () => {
|
||||||
lockMutex(async () => {
|
await publishWorkspace(true);
|
||||||
return publishWorkspace(true);
|
setOpen(false);
|
||||||
}).then(() => {
|
|
||||||
setOpen(false);
|
|
||||||
});
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export type PublishPanelLocalProps = {
|
export type PublishPanelLocalProps = WorkspaceSettingDetailProps & {
|
||||||
workspace: LocalWorkspace;
|
workspace: LocalWorkspace;
|
||||||
};
|
};
|
||||||
|
|
||||||
const PublishPanelLocal: React.FC<PublishPanelLocalProps> = ({ workspace }) => {
|
const PublishPanelLocal: React.FC<PublishPanelLocalProps> = ({
|
||||||
|
workspace,
|
||||||
|
onTransferWorkspace,
|
||||||
|
}) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Wrapper marginBottom="42px">{t('Publishing')}</Wrapper>
|
<Box
|
||||||
|
sx={{
|
||||||
|
marginBottom: '42px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t('Publishing')}
|
||||||
|
</Box>
|
||||||
<Button
|
<Button
|
||||||
type="light"
|
type="light"
|
||||||
shape="circle"
|
shape="circle"
|
||||||
onClick={async () => {
|
onClick={() => {
|
||||||
// fixme: regression
|
setOpen(true);
|
||||||
toast('You need to enable AFFiNE Cloud to use this feature.');
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{t('Enable AFFiNE Cloud')}
|
{t('Enable AFFiNE Cloud')}
|
||||||
</Button>
|
</Button>
|
||||||
|
<EnableAffineCloudModal
|
||||||
|
open={open}
|
||||||
|
onClose={() => {
|
||||||
|
setOpen(false);
|
||||||
|
}}
|
||||||
|
onConfirm={async () => {
|
||||||
|
const id = await transformWorkspace(
|
||||||
|
RemWorkspaceFlavour.LOCAL,
|
||||||
|
RemWorkspaceFlavour.AFFINE,
|
||||||
|
workspace
|
||||||
|
);
|
||||||
|
await apis.updateWorkspace({
|
||||||
|
id,
|
||||||
|
public: true,
|
||||||
|
});
|
||||||
|
// fixme: there imply that reload the whole page
|
||||||
|
onTransferWorkspace(id);
|
||||||
|
setOpen(false);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const PublishPanel: React.FC<PublishPanelProps> = ({ workspace }) => {
|
export const PublishPanel: React.FC<PublishPanelProps> = props => {
|
||||||
if (workspace.flavour === RemWorkspaceFlavour.AFFINE) {
|
if (props.workspace.flavour === RemWorkspaceFlavour.AFFINE) {
|
||||||
return <PublishPanelAffine workspace={workspace} />;
|
return <PublishPanelAffine {...props} workspace={props.workspace} />;
|
||||||
} else if (workspace.flavour === RemWorkspaceFlavour.LOCAL) {
|
} else if (props.workspace.flavour === RemWorkspaceFlavour.LOCAL) {
|
||||||
return <PublishPanelLocal workspace={workspace} />;
|
return <PublishPanelLocal {...props} workspace={props.workspace} />;
|
||||||
}
|
}
|
||||||
throw new Unreachable();
|
throw new Unreachable();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import '@blocksuite/editor/themes/affine.css';
|
||||||
|
|
||||||
import { config } from '@affine/env';
|
import { config } from '@affine/env';
|
||||||
import { BlockHub } from '@blocksuite/blocks';
|
import { BlockHub } from '@blocksuite/blocks';
|
||||||
import { EditorContainer } from '@blocksuite/editor';
|
import { EditorContainer } from '@blocksuite/editor';
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import '@blocksuite/editor/themes/affine.css';
|
|
||||||
import '../styles/globals.css';
|
import '../styles/globals.css';
|
||||||
|
|
||||||
import { config, setupGlobal } from '@affine/env';
|
import { config, setupGlobal } from '@affine/env';
|
||||||
|
|||||||
@@ -102,8 +102,9 @@ const SettingPage: NextPageWithLayout = () => {
|
|||||||
(targetWorkspaceId: string) => {
|
(targetWorkspaceId: string) => {
|
||||||
router
|
router
|
||||||
.replace({
|
.replace({
|
||||||
pathname: `/workspace/[workspaceId]/all`,
|
pathname: `/workspace/[workspaceId]/setting`,
|
||||||
query: {
|
query: {
|
||||||
|
...router.query,
|
||||||
workspaceId: targetWorkspaceId,
|
workspaceId: targetWorkspaceId,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -20,7 +20,14 @@ const ThemeInjector = React.memo<{
|
|||||||
return (
|
return (
|
||||||
<GlobalStyles
|
<GlobalStyles
|
||||||
styles={{
|
styles={{
|
||||||
'#__next': globalThemeVariables(themeStyle) as any,
|
'#__next': {
|
||||||
|
...globalThemeVariables(themeStyle),
|
||||||
|
},
|
||||||
|
html: {
|
||||||
|
fontFamily: themeStyle.font.family,
|
||||||
|
fontSize: themeStyle.font.base,
|
||||||
|
lineHeight: themeStyle.font.lineHeight,
|
||||||
|
},
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -149,7 +149,6 @@ legend {
|
|||||||
border: 0;
|
border: 0;
|
||||||
font-size: var(--affine-font-base);
|
font-size: var(--affine-font-base);
|
||||||
line-height: var(--affine-line-height);
|
line-height: var(--affine-line-height);
|
||||||
color: var(--affine-text-color);
|
|
||||||
font-family: var(--affine-font-family);
|
font-family: var(--affine-font-family);
|
||||||
}
|
}
|
||||||
body {
|
body {
|
||||||
|
|||||||
Reference in New Issue
Block a user