feat(core): add enable url preview to workspace settings (#8089)

This commit is contained in:
JimmFly
2024-09-10 04:04:05 +00:00
parent fe1eefdbb2
commit 9d343bdaa6
12 changed files with 276 additions and 0 deletions
@@ -17,6 +17,7 @@ import { ExportPanel } from './export';
import { LabelsPanel } from './labels';
import { MembersPanel } from './members';
import { ProfilePanel } from './profile';
import { SharingPanel } from './sharing';
import type { WorkspaceSettingDetailProps } from './types';
export const WorkspaceSettingDetail = ({
@@ -67,6 +68,7 @@ export const WorkspaceSettingDetail = ({
<EnableCloudPanel />
<MembersPanel />
</SettingWrapper>
<SharingPanel />
{environment.isElectron && (
<SettingWrapper title={t['Storage and Export']()}>
<ExportPanel
@@ -0,0 +1,49 @@
import { Switch } from '@affine/component';
import {
SettingRow,
SettingWrapper,
} from '@affine/component/setting-components';
import { useAsyncCallback } from '@affine/core/hooks/affine-async-hooks';
import { WorkspaceShareSettingService } from '@affine/core/modules/share-setting';
import { WorkspaceFlavour } from '@affine/env/workspace';
import { useI18n } from '@affine/i18n';
import { useLiveData, useService, WorkspaceService } from '@toeverything/infra';
export const SharingPanel = () => {
const workspace = useService(WorkspaceService).workspace;
if (workspace.flavour === WorkspaceFlavour.LOCAL) {
return null;
}
return <Sharing />;
};
export const Sharing = () => {
const t = useI18n();
const shareSetting = useService(WorkspaceShareSettingService).sharePreview;
const enableUrlPreview = useLiveData(shareSetting.enableUrlPreview$);
const loading = useLiveData(shareSetting.isLoading$);
const handleCheck = useAsyncCallback(
async (checked: boolean) => {
await shareSetting.setEnableUrlPreview(checked);
},
[shareSetting]
);
return (
<SettingWrapper title={t['com.affine.settings.workspace.sharing.title']()}>
<SettingRow
name={t['com.affine.settings.workspace.sharing.url-preview.title']()}
desc={t[
'com.affine.settings.workspace.sharing.url-preview.description'
]()}
>
<Switch
checked={enableUrlPreview || false}
onChange={handleCheck}
disabled={loading}
/>
</SettingRow>
</SettingWrapper>
);
};