From c07158935df877f148ea2f835b34e89d43e4041b Mon Sep 17 00:00:00 2001 From: Kilu Date: Fri, 28 Jun 2024 11:53:37 +0800 Subject: [PATCH] fix: some style --- .../components/_shared/view-icon/ViewIcon.tsx | 44 +++++++++++++++++++ .../src/components/_shared/view-icon/index.ts | 1 + .../components/leaf/mention/MentionPage.tsx | 24 ++-------- .../publish/header/BreadcrumbItem.tsx | 30 ++----------- .../publish/header/PublishViewHeader.tsx | 5 ++- .../publish/outline/OutlineDrawer.tsx | 4 +- .../publish/outline/OutlineItem.tsx | 10 +++-- .../publish/outline/OutlinePopover.tsx | 21 ++++----- .../publish/outline/SearchInput.tsx | 1 - .../src/components/view-meta/ViewCover.tsx | 2 +- 10 files changed, 74 insertions(+), 68 deletions(-) create mode 100644 frontend/appflowy_web_app/src/components/_shared/view-icon/ViewIcon.tsx create mode 100644 frontend/appflowy_web_app/src/components/_shared/view-icon/index.ts diff --git a/frontend/appflowy_web_app/src/components/_shared/view-icon/ViewIcon.tsx b/frontend/appflowy_web_app/src/components/_shared/view-icon/ViewIcon.tsx new file mode 100644 index 0000000000..4a802a174d --- /dev/null +++ b/frontend/appflowy_web_app/src/components/_shared/view-icon/ViewIcon.tsx @@ -0,0 +1,44 @@ +import { ViewLayout } from '@/application/collab.type'; +import React, { useMemo } from 'react'; +import { ReactComponent as BoardSvg } from '@/assets/board.svg'; +import { ReactComponent as CalendarSvg } from '@/assets/calendar.svg'; +import { ReactComponent as DocumentSvg } from '@/assets/document.svg'; +import { ReactComponent as GridSvg } from '@/assets/grid.svg'; + +export function ViewIcon({ layout, size }: { layout: ViewLayout; size: number | 'small' | 'medium' | 'large' }) { + const iconSize = useMemo(() => { + if (size === 'small') { + return 'h-4 w-4'; + } + + if (size === 'medium') { + return 'h-6 w-6'; + } + + if (size === 'large') { + return 'h-8 w-8'; + } + + return `h-${size} w-${size}`; + }, [size]); + + if (layout === ViewLayout.Grid) { + return ; + } + + if (layout === ViewLayout.Board) { + return ; + } + + if (layout === ViewLayout.Calendar) { + return ; + } + + if (layout === ViewLayout.Document) { + return ; + } + + return null; +} + +export default ViewIcon; diff --git a/frontend/appflowy_web_app/src/components/_shared/view-icon/index.ts b/frontend/appflowy_web_app/src/components/_shared/view-icon/index.ts new file mode 100644 index 0000000000..1db8ea5807 --- /dev/null +++ b/frontend/appflowy_web_app/src/components/_shared/view-icon/index.ts @@ -0,0 +1 @@ +export * from './ViewIcon'; diff --git a/frontend/appflowy_web_app/src/components/editor/components/leaf/mention/MentionPage.tsx b/frontend/appflowy_web_app/src/components/editor/components/leaf/mention/MentionPage.tsx index de3d0b4f10..340af53dc1 100644 --- a/frontend/appflowy_web_app/src/components/editor/components/leaf/mention/MentionPage.tsx +++ b/frontend/appflowy_web_app/src/components/editor/components/leaf/mention/MentionPage.tsx @@ -1,9 +1,6 @@ -import { ReactComponent as DocumentSvg } from '$icons/16x/document.svg'; -import { ReactComponent as GridSvg } from '$icons/16x/grid.svg'; -import { ReactComponent as BoardSvg } from '$icons/16x/board.svg'; -import { ReactComponent as CalendarSvg } from '$icons/16x/date.svg'; import { ViewLayout } from '@/application/collab.type'; import { ViewMeta } from '@/application/db/tables/view_metas'; +import { ViewIcon } from '@/components/_shared/view-icon'; import { useEditorContext } from '@/components/editor/EditorContext'; import React, { useEffect, useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; @@ -33,21 +30,6 @@ function MentionPage({ pageId }: { pageId: string }) { return meta?.icon; }, [meta?.icon]); - const defaultIcon = useMemo(() => { - switch (meta?.layout) { - case ViewLayout.Document: - return ; - case ViewLayout.Grid: - return ; - case ViewLayout.Board: - return ; - case ViewLayout.Calendar: - return ; - default: - return ; - } - }, [meta?.layout]); - const { t } = useTranslation(); return ( @@ -62,7 +44,9 @@ function MentionPage({ pageId }: { pageId: string }) { No Access ) : ( <> - {icon?.value || defaultIcon} + + {icon?.value || } + {meta?.name || t('menuAppHeader.defaultNewPageName')} diff --git a/frontend/appflowy_web_app/src/components/publish/header/BreadcrumbItem.tsx b/frontend/appflowy_web_app/src/components/publish/header/BreadcrumbItem.tsx index 9c88c5b121..9e0e87f82c 100644 --- a/frontend/appflowy_web_app/src/components/publish/header/BreadcrumbItem.tsx +++ b/frontend/appflowy_web_app/src/components/publish/header/BreadcrumbItem.tsx @@ -1,42 +1,20 @@ -import { ReactComponent as BoardSvg } from '@/assets/board.svg'; -import { ReactComponent as CalendarSvg } from '@/assets/calendar.svg'; -import { ReactComponent as DocumentSvg } from '@/assets/document.svg'; -import { ReactComponent as GridSvg } from '@/assets/grid.svg'; import { ViewLayout } from '@/application/collab.type'; import { usePublishContext } from '@/application/publish'; import { notify } from '@/components/_shared/notify'; +import { ViewIcon } from '@/components/_shared/view-icon'; import React from 'react'; import { useTranslation } from 'react-i18next'; -export const renderCrumbIcon = (icon: string) => { - if (Number(icon) === ViewLayout.Grid) { - return ; - } - - if (Number(icon) === ViewLayout.Board) { - return ; - } - - if (Number(icon) === ViewLayout.Calendar) { - return ; - } - - if (Number(icon) === ViewLayout.Document) { - return ; - } - - return icon; -}; - export interface Crumb { viewId: string; rowId?: string; name: string; icon: string; + layout: ViewLayout; } function BreadcrumbItem({ crumb, disableClick = false }: { crumb: Crumb; disableClick?: boolean }) { - const { viewId, icon, name } = crumb; + const { viewId, icon, name, layout } = crumb; const { t } = useTranslation(); const onNavigateToView = usePublishContext()?.toView; @@ -53,7 +31,7 @@ function BreadcrumbItem({ crumb, disableClick = false }: { crumb: Crumb; disable } }} > - {renderCrumbIcon(icon)} + {icon || } diff --git a/frontend/appflowy_web_app/src/components/publish/header/PublishViewHeader.tsx b/frontend/appflowy_web_app/src/components/publish/header/PublishViewHeader.tsx index dab2192b83..40933eda75 100644 --- a/frontend/appflowy_web_app/src/components/publish/header/PublishViewHeader.tsx +++ b/frontend/appflowy_web_app/src/components/publish/header/PublishViewHeader.tsx @@ -36,7 +36,8 @@ export function PublishViewHeader({ return { viewId: ancestor.view_id, name: ancestor.name, - icon: icon || String(viewMeta?.layout), + icon: icon, + layout: ancestor.layout, }; }); }, [viewMeta]); @@ -64,7 +65,7 @@ export function PublishViewHeader({ width: openDrawer ? `calc(100% - ${drawerWidth}px)` : '100%', transition: 'width 0.2s ease-in-out 0s', }} - className={'appflowy-top-bar flex h-[64px] px-5'} + className={'appflowy-top-bar flex h-[48px] px-5'} >
{!openDrawer && ( diff --git a/frontend/appflowy_web_app/src/components/publish/outline/OutlineDrawer.tsx b/frontend/appflowy_web_app/src/components/publish/outline/OutlineDrawer.tsx index 4f9f645d99..9c8fb6e4b3 100644 --- a/frontend/appflowy_web_app/src/components/publish/outline/OutlineDrawer.tsx +++ b/frontend/appflowy_web_app/src/components/publish/outline/OutlineDrawer.tsx @@ -31,9 +31,9 @@ function OutlineDrawer({ open, width, onClose }: { open: boolean; width: number; autoFocus >
-
+
{ window.open('https://appflowy.io', '_blank'); }} diff --git a/frontend/appflowy_web_app/src/components/publish/outline/OutlineItem.tsx b/frontend/appflowy_web_app/src/components/publish/outline/OutlineItem.tsx index caf71bfb75..7b9f1d7950 100644 --- a/frontend/appflowy_web_app/src/components/publish/outline/OutlineItem.tsx +++ b/frontend/appflowy_web_app/src/components/publish/outline/OutlineItem.tsx @@ -1,7 +1,7 @@ import { PublishViewInfo, ViewLayout } from '@/application/collab.type'; import { PublishContext } from '@/application/publish'; import { notify } from '@/components/_shared/notify'; -import { renderCrumbIcon } from '@/components/publish/header/BreadcrumbItem'; +import { ViewIcon } from '@/components/_shared/view-icon'; import React, { useCallback, useContext } from 'react'; import { ReactComponent as ChevronDownIcon } from '@/assets/chevron_down.svg'; import { useTranslation } from 'react-i18next'; @@ -35,6 +35,8 @@ function OutlineItem({ view }: { view: PublishViewInfo }) { const navigateToView = useContext(PublishContext)?.toView; const renderItem = (item: PublishViewInfo) => { + const { icon, layout, name, view_id } = item; + return (
{ try { - await navigateToView?.(item.view_id); + await navigateToView?.(view_id); } catch (e) { notify.error(t('publish.hasNotBeenPublished')); } }} className={'flex flex-1 cursor-pointer items-center gap-1 overflow-hidden'} > -
{renderCrumbIcon(item.icon?.value || String(item.layout))}
-
{item.name}
+
{icon?.value || }
+
{name}
diff --git a/frontend/appflowy_web_app/src/components/publish/outline/OutlinePopover.tsx b/frontend/appflowy_web_app/src/components/publish/outline/OutlinePopover.tsx index a64f2084ba..0c9cf0197c 100644 --- a/frontend/appflowy_web_app/src/components/publish/outline/OutlinePopover.tsx +++ b/frontend/appflowy_web_app/src/components/publish/outline/OutlinePopover.tsx @@ -30,7 +30,7 @@ export function OutlinePopover({
{Boolean(viewMeta?.child_views?.length) && } -
-
{t('publish.createdWith')}
-
{ - window.open('https://appflowy.io', '_blank'); - }} - > - - -
+
{ + window.open('https://appflowy.io', '_blank'); + }} + className={'flex w-full cursor-pointer items-center justify-center text-sm text-text-title opacity-50'} + > + +
diff --git a/frontend/appflowy_web_app/src/components/publish/outline/SearchInput.tsx b/frontend/appflowy_web_app/src/components/publish/outline/SearchInput.tsx index 5f83b758d6..f3dbadc906 100644 --- a/frontend/appflowy_web_app/src/components/publish/outline/SearchInput.tsx +++ b/frontend/appflowy_web_app/src/components/publish/outline/SearchInput.tsx @@ -21,7 +21,6 @@ function SearchInput({ onSearch }: { onSearch: (value: string) => void }) { return ( diff --git a/frontend/appflowy_web_app/src/components/view-meta/ViewCover.tsx b/frontend/appflowy_web_app/src/components/view-meta/ViewCover.tsx index 9221c8c3b6..df7c495bb3 100644 --- a/frontend/appflowy_web_app/src/components/view-meta/ViewCover.tsx +++ b/frontend/appflowy_web_app/src/components/view-meta/ViewCover.tsx @@ -22,7 +22,7 @@ function ViewCover({ coverValue, coverType }: { coverValue?: string; coverType?: } return ( -
+
{coverType === 'color' && renderCoverColor(coverValue)} {(coverType === 'custom' || coverType === 'built_in') && renderCoverImage(coverValue)}