Skip to content

Commit 5edbbb7

Browse files
committed
feat: add comment and duplicate config
1 parent 41dddee commit 5edbbb7

File tree

14 files changed

+227
-19
lines changed

14 files changed

+227
-19
lines changed

src/@types/translations/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3061,5 +3061,7 @@
30613061
"downloadTip": "Don't have AppFlowy Apps installed? Download <link/>.",
30623062
"here": "here",
30633063
"openInBrowser": "Open in browser",
3064-
"openInApp": "Open in app"
3064+
"openInApp": "Open in app",
3065+
"comments": "Comments",
3066+
"duplicateAsTemplate": "Duplicate as template"
30653067
}

src/application/publish/context.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { notify } from '@/components/_shared/notify';
1313
import { findAncestors, findView } from '@/components/_shared/outline/utils';
1414
import { useService } from '@/components/main/app.hooks';
1515
import { useLiveQuery } from 'dexie-react-hooks';
16-
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
16+
import React, { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
1717
import { useNavigate } from 'react-router-dom';
1818

1919
export interface PublishContextType {
@@ -31,6 +31,8 @@ export interface PublishContextType {
3131
breadcrumbs: View[];
3232
rendered?: boolean;
3333
onRendered?: () => void;
34+
commentEnabled?: boolean;
35+
duplicateEnabled?: boolean;
3436
}
3537

3638
export const PublishContext = createContext<PublishContextType | null>(null);
@@ -73,6 +75,13 @@ export const PublishProvider = ({
7375
};
7476
}, [namespace, publishName, outline]);
7577

78+
const viewId = viewMeta?.view_id;
79+
80+
const [publishInfo, setPublishInfo] = React.useState<{
81+
commentEnabled: boolean,
82+
duplicateEnabled: boolean,
83+
} | undefined>();
84+
7685
const originalCrumbs = useMemo(() => {
7786
if (!viewMeta || !outline) return [];
7887
const ancestors = findAncestors(outline, viewMeta?.view_id);
@@ -175,6 +184,25 @@ export const PublishProvider = ({
175184
});
176185

177186
}, [service, publishName]);
187+
188+
const loadPublishInfo = useCallback(async () => {
189+
if (!service || !viewId) return;
190+
try {
191+
const res = await service.getPublishInfo(viewId);
192+
193+
setPublishInfo(res);
194+
195+
// eslint-disable-next-line
196+
} catch (e: any) {
197+
// do nothing
198+
}
199+
200+
}, [viewId, service]);
201+
202+
useEffect(() => {
203+
void loadPublishInfo();
204+
}, [loadPublishInfo]);
205+
178206
const navigate = useNavigate();
179207

180208
const loadViewMeta = useCallback(
@@ -385,6 +413,8 @@ export const PublishProvider = ({
385413
appendBreadcrumb,
386414
onRendered,
387415
rendered,
416+
commentEnabled: publishInfo?.commentEnabled !== false,
417+
duplicateEnabled: publishInfo?.duplicateEnabled !== false,
388418
}}
389419
>
390420
{children}

src/application/services/js-services/http/http_api.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
CreateWorkspacePayload,
2828
UpdateWorkspacePayload,
2929
PublishViewPayload,
30-
UploadPublishNamespacePayload,
30+
UploadPublishNamespacePayload, UpdatePublishConfigPayload,
3131
} from '@/application/types';
3232
import { GlobalComment, Reaction } from '@/application/comment.type';
3333
import { initGrantService, refreshToken } from '@/application/services/js-services/http/gotrue';
@@ -532,6 +532,20 @@ export async function getPublishView (publishNamespace: string, publishName: str
532532
}
533533
}
534534

535+
export async function updatePublishConfig (workspaceId: string, payload: UpdatePublishConfigPayload) {
536+
const url = `/api/workspace/${workspaceId}/publish`;
537+
const response = await axiosInstance?.patch<{
538+
code: number;
539+
message: string;
540+
}>(url, payload);
541+
542+
if (response?.data.code === 0) {
543+
return;
544+
}
545+
546+
return Promise.reject(response?.data);
547+
}
548+
535549
export async function getPublishInfoWithViewId (viewId: string) {
536550
const url = `/api/workspace/v1/published-info/${viewId}`;
537551
const response = await axiosInstance?.get<{
@@ -542,6 +556,8 @@ export async function getPublishInfoWithViewId (viewId: string) {
542556
publisher_email: string;
543557
view_id: string;
544558
publish_timestamp: string;
559+
comments_enabled: boolean;
560+
duplicate_enabled: boolean;
545561
};
546562
message: string;
547563
}>(url);

src/application/services/js-services/index.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,22 @@ import {
2929
UploadTemplatePayload,
3030
} from '@/application/template.type';
3131
import {
32-
CreatePagePayload, CreateSpacePayload, CreateWorkspacePayload,
32+
CreatePagePayload,
33+
CreateSpacePayload,
34+
CreateWorkspacePayload,
3335
DatabaseRelations,
34-
DuplicatePublishView, PublishViewPayload, QuickNoteEditorData,
35-
SubscriptionInterval, SubscriptionPlan,
36-
Types, UpdatePagePayload, UpdateSpacePayload, UpdateWorkspacePayload, UploadPublishNamespacePayload, WorkspaceMember,
36+
DuplicatePublishView,
37+
PublishViewPayload,
38+
QuickNoteEditorData,
39+
SubscriptionInterval,
40+
SubscriptionPlan,
41+
Types,
42+
UpdatePagePayload,
43+
UpdatePublishConfigPayload,
44+
UpdateSpacePayload,
45+
UpdateWorkspacePayload,
46+
UploadPublishNamespacePayload,
47+
WorkspaceMember,
3748
YjsEditorKey,
3849
} from '@/application/types';
3950
import { applyYDoc } from '@/application/ydoc/apply';
@@ -205,6 +216,8 @@ export class AFClientService implements AFService {
205216
publisherEmail: string;
206217
viewId: string;
207218
publishedAt: string;
219+
commentEnabled: boolean;
220+
duplicateEnabled: boolean;
208221
};
209222
}
210223

@@ -222,13 +235,19 @@ export class AFClientService implements AFService {
222235
publisherEmail: info.publisher_email,
223236
viewId: info.view_id,
224237
publishedAt: info.publish_timestamp,
238+
commentEnabled: info.comments_enabled,
239+
duplicateEnabled: info.duplicate_enabled,
225240
};
226241

227242
this.publishViewInfo.set(viewId, data);
228243

229244
return data;
230245
}
231246

247+
async updatePublishConfig (workspaceId: string, config: UpdatePublishConfigPayload) {
248+
return APIService.updatePublishConfig(workspaceId, config);
249+
}
250+
232251
async getPublishOutline (namespace: string) {
233252
return APIService.getPublishOutline(namespace);
234253
}

src/application/services/services.type.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
CreateWorkspacePayload,
2525
UpdateWorkspacePayload,
2626
PublishViewPayload,
27-
UploadPublishNamespacePayload,
27+
UploadPublishNamespacePayload, UpdatePublishConfigPayload,
2828
} from '@/application/types';
2929
import { GlobalComment, Reaction } from '@/application/comment.type';
3030
import { ViewMeta } from '@/application/db/tables/view_metas';
@@ -153,8 +153,11 @@ export interface PublishService {
153153
namespace: string;
154154
publishName: string,
155155
publisherEmail: string,
156-
publishedAt: string
156+
publishedAt: string,
157+
commentEnabled: boolean,
158+
duplicateEnabled: boolean,
157159
}>;
160+
updatePublishConfig: (workspaceId: string, payload: UpdatePublishConfigPayload) => Promise<void>;
158161
getPublishNamespace: (namespace: string) => Promise<string>;
159162
getPublishHomepage: (workspaceId: string) => Promise<{ view_id: string }>;
160163
updatePublishHomepage: (workspaceId: string, viewId: string) => Promise<void>;

src/application/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,12 @@ export interface View {
852852
publish_timestamp?: string;
853853
}
854854

855+
export interface UpdatePublishConfigPayload {
856+
comments_enabled?: boolean;
857+
duplicate_enabled?: boolean;
858+
view_id: string;
859+
}
860+
855861
export interface Invitation {
856862
invite_id: string;
857863
workspace_id: string;

src/assets/switch_checked.svg

Lines changed: 4 additions & 0 deletions
Loading

src/assets/unswitch.svg

Lines changed: 4 additions & 0 deletions
Loading
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { styled, Switch as MUISwitch, SwitchProps } from '@mui/material';
2+
3+
export const Switch = styled((props: SwitchProps) => (
4+
<MUISwitch
5+
focusVisibleClassName=".Mui-focusVisible"
6+
disableRipple
7+
{...props}
8+
/>
9+
))(({ theme, size }) => ({
10+
width: size === 'small' ? 30 : 56,
11+
height: size === 'small' ? 18 : 32,
12+
padding: 0,
13+
'& .MuiSwitch-switchBase': {
14+
padding: 0,
15+
margin: 2,
16+
transitionDuration: '300ms',
17+
'&.Mui-checked': {
18+
transform: size === 'small' ? 'translateX(12px)' : 'translateX(16px)',
19+
color: '#fff',
20+
'& + .MuiSwitch-track': {
21+
backgroundColor: 'var(--fill-default)',
22+
opacity: 1,
23+
border: 0,
24+
...theme.applyStyles('dark', {
25+
backgroundColor: 'var(--fill-default)',
26+
}),
27+
},
28+
'&.Mui-disabled + .MuiSwitch-track': {
29+
opacity: 0.5,
30+
},
31+
},
32+
'&.Mui-focusVisible .MuiSwitch-thumb': {
33+
color: 'var(--fill-default)',
34+
border: '6px solid #fff',
35+
},
36+
'&.Mui-disabled .MuiSwitch-thumb': {
37+
color: theme.palette.grey[100],
38+
...theme.applyStyles('dark', {
39+
color: theme.palette.grey[600],
40+
}),
41+
},
42+
'&.Mui-disabled + .MuiSwitch-track': {
43+
opacity: 0.7,
44+
...theme.applyStyles('dark', {
45+
opacity: 0.3,
46+
}),
47+
},
48+
},
49+
'& .MuiSwitch-thumb': {
50+
boxSizing: 'border-box',
51+
width: size === 'small' ? 14 : 20,
52+
height: size === 'small' ? 14 : 20,
53+
},
54+
'& .MuiSwitch-track': {
55+
borderRadius: size === 'small' ? 9 : 16,
56+
backgroundColor: '#E9E9EA',
57+
opacity: 1,
58+
transition: theme.transitions.create(['background-color'], {
59+
duration: 500,
60+
}),
61+
...theme.applyStyles('dark', {
62+
backgroundColor: '#39393D',
63+
}),
64+
},
65+
}));
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './Switch';

0 commit comments

Comments
 (0)