feat:publish workspace

This commit is contained in:
DiamondThree
2022-12-22 23:16:56 +08:00
parent d89f19e542
commit 911bf14e61
@@ -42,6 +42,7 @@ import {
Workspace, Workspace,
Member, Member,
removeMember, removeMember,
updateWorkspace,
} from '@pathfinder/data-services'; } from '@pathfinder/data-services';
import { Avatar } from '@mui/material'; import { Avatar } from '@mui/material';
import { Menu, MenuItem } from '@/ui/menu'; import { Menu, MenuItem } from '@/ui/menu';
@@ -158,7 +159,9 @@ export const WorkspaceSetting = ({
{activeTab === ActiveTab.members && workspace && ( {activeTab === ActiveTab.members && workspace && (
<MembersPage workspace={workspace} /> <MembersPage workspace={workspace} />
)} )}
{activeTab === ActiveTab.publish && <PublishPage />} {activeTab === ActiveTab.publish && (
<PublishPage workspace={workspace} />
)}
</StyledSettingContent> </StyledSettingContent>
</StyledSettingContainer> </StyledSettingContainer>
</Modal> </Modal>
@@ -286,31 +289,69 @@ const MembersPage = ({ workspace }: { workspace: Workspace }) => {
); );
}; };
const PublishPage = () => { const PublishPage = ({ workspace }: { workspace: Workspace }) => {
const { refreshWorkspacesMeta } = useAppState();
const shareUrl = window.location.host + '/workspace/' + workspace.id;
const togglePublic = (flag: boolean) => {
updateWorkspace({
id: workspace.id,
public: flag,
}).then(data => {
refreshWorkspacesMeta();
toast('Updated');
});
};
const copyUrl = () => {
navigator.clipboard.writeText(shareUrl);
toast('Copied');
};
return ( return (
<div> <div>
<StyledPublishContent> <StyledPublishContent>
<StyledPublishExplanation> {workspace.public ? (
After publishing to the web, everyone can view the content of this <StyledPublishExplanation>
workspace through the link. After publishing to the web, everyone can view the content of this
</StyledPublishExplanation> workspace through the link.
<StyledSettingH2 marginTop={48}>Share with link</StyledSettingH2> </StyledPublishExplanation>
<StyledPublishCopyContainer> ) : (
<Input <>
width={500} <StyledPublishExplanation>
value={'www.baidu.com/asdsadas/asdsadasd'} The current workspace has been published to the web, everyone can
disabled view the contents of this workspace through the link.
></Input> </StyledPublishExplanation>
<StyledCopyButtonContainer> <StyledSettingH2 marginTop={48}>Share with link</StyledSettingH2>
<Button type="primary" shape="circle"> <StyledPublishCopyContainer>
Copy Link <Input width={500} value={shareUrl} disabled={true}></Input>
</Button> <StyledCopyButtonContainer>
</StyledCopyButtonContainer> <Button onClick={copyUrl} type="primary" shape="circle">
</StyledPublishCopyContainer> Copy Link
</Button>
</StyledCopyButtonContainer>
</StyledPublishCopyContainer>
</>
)}
</StyledPublishContent> </StyledPublishContent>
<Button type="primary" shape="circle"> {!workspace.public ? (
Publish to web <Button
</Button> onClick={() => {
togglePublic(true);
}}
type="primary"
shape="circle"
>
Publish to web
</Button>
) : (
<Button
onClick={() => {
togglePublic(false);
}}
type="primary"
shape="circle"
>
Stop publishing
</Button>
)}
</div> </div>
); );
}; };