From b28f566f0a375d93d30ec0c633399e271a5ec844 Mon Sep 17 00:00:00 2001 From: "Kilu.He" <108015703+qinluhe@users.noreply.github.com> Date: Tue, 14 Jan 2025 15:18:08 +0800 Subject: [PATCH] feat: support use template on web (#22) --- src/@types/translations/en.json | 7 +++- .../services/js-services/http/http_api.ts | 5 ++- src/application/services/services.type.ts | 2 +- src/components/app/SideBarBottom.tsx | 28 +++++++------- .../header/duplicate/DuplicateModal.tsx | 37 +++++++++++++++---- 5 files changed, 54 insertions(+), 25 deletions(-) diff --git a/src/@types/translations/en.json b/src/@types/translations/en.json index edd7707..b653fae 100644 --- a/src/@types/translations/en.json +++ b/src/@types/translations/en.json @@ -3056,5 +3056,10 @@ "AISearchPlaceholder": "Search or ask a question...", "searchLabel": "Search", "publishSelectedViews": "Publish {{count}} selected views", - "untitled": "Untitled" + "untitled": "Untitled", + "addToWorkspace": "Added to your workspace", + "downloadTip": "Don't have AppFlowy Apps installed? Download .", + "here": "here", + "openInBrowser": "Open in browser", + "openInApp": "Open in app" } diff --git a/src/application/services/js-services/http/http_api.ts b/src/application/services/js-services/http/http_api.ts index 098ea50..23350c9 100644 --- a/src/application/services/js-services/http/http_api.ts +++ b/src/application/services/js-services/http/http_api.ts @@ -972,11 +972,14 @@ export async function duplicatePublishView (workspaceId: string, payload: Duplic const res = await axiosInstance?.post<{ code: number; + data: { + view_id: string; + }; message: string; }>(url, payload); if (res?.data.code === 0) { - return; + return res.data.data.view_id; } return Promise.reject(res?.data.message); diff --git a/src/application/services/services.type.ts b/src/application/services/services.type.ts index 5d91018..25d9d30 100644 --- a/src/application/services/services.type.ts +++ b/src/application/services/services.type.ts @@ -168,6 +168,6 @@ export interface PublishService { getPublishViewReactions: (viewId: string, commentId?: string) => Promise>; addPublishViewReaction: (viewId: string, commentId: string, reactionType: string) => Promise; removePublishViewReaction: (viewId: string, commentId: string, reactionType: string) => Promise; - duplicatePublishView: (params: DuplicatePublishView) => Promise; + duplicatePublishView: (params: DuplicatePublishView) => Promise; } diff --git a/src/components/app/SideBarBottom.tsx b/src/components/app/SideBarBottom.tsx index 4fd3b64..f7c10d4 100644 --- a/src/components/app/SideBarBottom.tsx +++ b/src/components/app/SideBarBottom.tsx @@ -1,12 +1,12 @@ import { IconButton, Tooltip } from '@mui/material'; import React from 'react'; import { useTranslation } from 'react-i18next'; -// import { ReactComponent as TemplateIcon } from '@/assets/template.svg'; +import { ReactComponent as TemplateIcon } from '@/assets/template.svg'; import { useNavigate } from 'react-router-dom'; import { ReactComponent as TrashIcon } from '@/assets/trash.svg'; import { QuickNote } from '@/components/quick-note'; -function SideBarBottom() { +function SideBarBottom () { const { t } = useTranslation(); const navigate = useNavigate(); @@ -18,16 +18,16 @@ function SideBarBottom() { className={'flex py-4 border-t border-line-divider gap-1 justify-around items-center'} > - {/**/} - {/* {*/} - {/* window.open('https://appflowy.io/templates', '_blank');*/} - {/* }}*/} - {/* >*/} - {/* */} - {/* */} - {/**/} + + { + window.open('https://appflowy.io/templates', '_blank'); + }} + > + + + - + - + diff --git a/src/components/publish/header/duplicate/DuplicateModal.tsx b/src/components/publish/header/duplicate/DuplicateModal.tsx index 4ae4705..bb9f5bd 100644 --- a/src/components/publish/header/duplicate/DuplicateModal.tsx +++ b/src/components/publish/header/duplicate/DuplicateModal.tsx @@ -1,6 +1,6 @@ import { AFConfigContext } from '@/components/main/app.hooks'; import React, { useCallback, useContext, useEffect } from 'react'; -import { useTranslation } from 'react-i18next'; +import { Trans, useTranslation } from 'react-i18next'; import { NormalModal } from '@/components/_shared/modal'; import SelectWorkspace from '@/components/publish/header/duplicate/SelectWorkspace'; import { useLoadWorkspaces } from '@/components/publish/header/duplicate/useDuplicate'; @@ -31,6 +31,7 @@ function DuplicateModal ({ open, onClose }: { open: boolean; onClose: () => void const layout = viewMeta?.layout as ViewLayout; const [loading, setLoading] = React.useState(false); const [successModalOpen, setSuccessModalOpen] = React.useState(false); + const [newViewId, setNewViewId] = React.useState(undefined); const { workspaceList, spaceList, @@ -64,15 +65,18 @@ function DuplicateModal ({ open, onClose }: { open: boolean; onClose: () => void setLoading(true); try { - await service?.duplicatePublishView({ + const newViewId = await service?.duplicatePublishView({ workspaceId: selectedWorkspaceId, spaceViewId: selectedSpaceId, viewId, collabType, }); + onClose(); setSuccessModalOpen(true); + setNewViewId(newViewId); } catch (e) { + setNewViewId(undefined); notify.error(t('publish.duplicateFailed')); } finally { setLoading(false); @@ -115,18 +119,35 @@ function DuplicateModal ({ open, onClose }: { open: boolean; onClose: () => void maxWidth: 420, }, }} - okText={t('publish.useThisTemplate')} - cancelText={t('publish.downloadIt')} - onOk={() => window.open(openAppFlowySchema, '_self')} + okText={t('openInBrowser')} + cancelText={t('openInApp')} + onOk={() => { + if (!newViewId || !selectedWorkspaceId) return; + window.open(`/app/${selectedWorkspaceId}/${newViewId}`, '_self'); + }} onCancel={() => { - window.open(downloadPage, '_blank'); + window.open(openAppFlowySchema, '_self'); }} onClose={() => setSuccessModalOpen(false)} open={successModalOpen} - title={
{t('publish.duplicateSuccessfully')}
} + title={ +
+ {t('addToWorkspace')} +
+ } >
- {t('publish.duplicateSuccessfullyDescription')} + { + window.open(downloadPage, '_blank'); + }} + className={'hover:underline cursor-pointer text-fill-default'} + >{t('here')}, + }} + />