Skip to content

Commit b28f566

Browse files
authored
feat: support use template on web (#22)
1 parent fa43205 commit b28f566

File tree

5 files changed

+54
-25
lines changed

5 files changed

+54
-25
lines changed

src/@types/translations/en.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3056,5 +3056,10 @@
30563056
"AISearchPlaceholder": "Search or ask a question...",
30573057
"searchLabel": "Search",
30583058
"publishSelectedViews": "Publish {{count}} selected views",
3059-
"untitled": "Untitled"
3059+
"untitled": "Untitled",
3060+
"addToWorkspace": "Added to your workspace",
3061+
"downloadTip": "Don't have AppFlowy Apps installed? Download <link/>.",
3062+
"here": "here",
3063+
"openInBrowser": "Open in browser",
3064+
"openInApp": "Open in app"
30603065
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,11 +972,14 @@ export async function duplicatePublishView (workspaceId: string, payload: Duplic
972972

973973
const res = await axiosInstance?.post<{
974974
code: number;
975+
data: {
976+
view_id: string;
977+
};
975978
message: string;
976979
}>(url, payload);
977980

978981
if (res?.data.code === 0) {
979-
return;
982+
return res.data.data.view_id;
980983
}
981984

982985
return Promise.reject(res?.data.message);

src/application/services/services.type.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,6 @@ export interface PublishService {
168168
getPublishViewReactions: (viewId: string, commentId?: string) => Promise<Record<string, Reaction[]>>;
169169
addPublishViewReaction: (viewId: string, commentId: string, reactionType: string) => Promise<void>;
170170
removePublishViewReaction: (viewId: string, commentId: string, reactionType: string) => Promise<void>;
171-
duplicatePublishView: (params: DuplicatePublishView) => Promise<void>;
171+
duplicatePublishView: (params: DuplicatePublishView) => Promise<string>;
172172

173173
}

src/components/app/SideBarBottom.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { IconButton, Tooltip } from '@mui/material';
22
import React from 'react';
33
import { useTranslation } from 'react-i18next';
4-
// import { ReactComponent as TemplateIcon } from '@/assets/template.svg';
4+
import { ReactComponent as TemplateIcon } from '@/assets/template.svg';
55
import { useNavigate } from 'react-router-dom';
66
import { ReactComponent as TrashIcon } from '@/assets/trash.svg';
77
import { QuickNote } from '@/components/quick-note';
88

9-
function SideBarBottom() {
9+
function SideBarBottom () {
1010
const { t } = useTranslation();
1111
const navigate = useNavigate();
1212

@@ -18,16 +18,16 @@ function SideBarBottom() {
1818
className={'flex py-4 border-t border-line-divider gap-1 justify-around items-center'}
1919

2020
>
21-
{/*<Tooltip title={t('template.label')}>*/}
22-
{/* <IconButton*/}
23-
{/* size={'small'}*/}
24-
{/* onClick={() => {*/}
25-
{/* window.open('https://appflowy.io/templates', '_blank');*/}
26-
{/* }}*/}
27-
{/* >*/}
28-
{/* <TemplateIcon/>*/}
29-
{/* </IconButton>*/}
30-
{/*</Tooltip>*/}
21+
<Tooltip title={t('template.label')}>
22+
<IconButton
23+
size={'small'}
24+
onClick={() => {
25+
window.open('https://appflowy.io/templates', '_blank');
26+
}}
27+
>
28+
<TemplateIcon />
29+
</IconButton>
30+
</Tooltip>
3131

3232
<Tooltip title={t('trash.text')}>
3333
<IconButton
@@ -36,11 +36,11 @@ function SideBarBottom() {
3636
navigate('/app/trash');
3737
}}
3838
>
39-
<TrashIcon/>
39+
<TrashIcon />
4040
</IconButton>
4141
</Tooltip>
4242

43-
<QuickNote/>
43+
<QuickNote />
4444
</div>
4545

4646
</div>

src/components/publish/header/duplicate/DuplicateModal.tsx

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { AFConfigContext } from '@/components/main/app.hooks';
22
import React, { useCallback, useContext, useEffect } from 'react';
3-
import { useTranslation } from 'react-i18next';
3+
import { Trans, useTranslation } from 'react-i18next';
44
import { NormalModal } from '@/components/_shared/modal';
55
import SelectWorkspace from '@/components/publish/header/duplicate/SelectWorkspace';
66
import { useLoadWorkspaces } from '@/components/publish/header/duplicate/useDuplicate';
@@ -31,6 +31,7 @@ function DuplicateModal ({ open, onClose }: { open: boolean; onClose: () => void
3131
const layout = viewMeta?.layout as ViewLayout;
3232
const [loading, setLoading] = React.useState<boolean>(false);
3333
const [successModalOpen, setSuccessModalOpen] = React.useState<boolean>(false);
34+
const [newViewId, setNewViewId] = React.useState<string | undefined>(undefined);
3435
const {
3536
workspaceList,
3637
spaceList,
@@ -64,15 +65,18 @@ function DuplicateModal ({ open, onClose }: { open: boolean; onClose: () => void
6465

6566
setLoading(true);
6667
try {
67-
await service?.duplicatePublishView({
68+
const newViewId = await service?.duplicatePublishView({
6869
workspaceId: selectedWorkspaceId,
6970
spaceViewId: selectedSpaceId,
7071
viewId,
7172
collabType,
7273
});
74+
7375
onClose();
7476
setSuccessModalOpen(true);
77+
setNewViewId(newViewId);
7578
} catch (e) {
79+
setNewViewId(undefined);
7680
notify.error(t('publish.duplicateFailed'));
7781
} finally {
7882
setLoading(false);
@@ -115,18 +119,35 @@ function DuplicateModal ({ open, onClose }: { open: boolean; onClose: () => void
115119
maxWidth: 420,
116120
},
117121
}}
118-
okText={t('publish.useThisTemplate')}
119-
cancelText={t('publish.downloadIt')}
120-
onOk={() => window.open(openAppFlowySchema, '_self')}
122+
okText={t('openInBrowser')}
123+
cancelText={t('openInApp')}
124+
onOk={() => {
125+
if (!newViewId || !selectedWorkspaceId) return;
126+
window.open(`/app/${selectedWorkspaceId}/${newViewId}`, '_self');
127+
}}
121128
onCancel={() => {
122-
window.open(downloadPage, '_blank');
129+
window.open(openAppFlowySchema, '_self');
123130
}}
124131
onClose={() => setSuccessModalOpen(false)}
125132
open={successModalOpen}
126-
title={<div className={'text-left'}>{t('publish.duplicateSuccessfully')}</div>}
133+
title={
134+
<div className={'text-left'}>
135+
{t('addToWorkspace')}
136+
</div>
137+
}
127138
>
128139
<div className={'w-full whitespace-pre-wrap break-words pb-1 text-text-caption'}>
129-
{t('publish.duplicateSuccessfullyDescription')}
140+
<Trans
141+
i18nKey="downloadTip"
142+
components={{
143+
link: <span
144+
onClick={() => {
145+
window.open(downloadPage, '_blank');
146+
}}
147+
className={'hover:underline cursor-pointer text-fill-default'}
148+
>{t('here')}</span>,
149+
}}
150+
/>
130151
</div>
131152
</NormalModal>
132153
</>

0 commit comments

Comments
 (0)