chore: fix code style issues (#4857)

This commit is contained in:
EYHN
2023-11-08 13:51:08 +08:00
committed by GitHub
parent 83472cc682
commit b7edaab387
30 changed files with 423 additions and 471 deletions

View File

@@ -22,7 +22,6 @@ export default defineConfig({
root, root,
'src/__internal__/workspace.ts' 'src/__internal__/workspace.ts'
), ),
'__internal__/react': resolve(root, 'src/__internal__/react.ts'),
'__internal__/plugin': resolve(root, 'src/__internal__/plugin.ts'), '__internal__/plugin': resolve(root, 'src/__internal__/plugin.ts'),
}, },
formats: ['es', 'cjs'], formats: ['es', 'cjs'],

View File

@@ -9,7 +9,7 @@ export type Notification = {
theme?: 'light' | 'dark' | 'default'; theme?: 'light' | 'dark' | 'default';
timeout?: number; timeout?: number;
progressingBar?: boolean; progressingBar?: boolean;
multimedia?: React.ReactNode | JSX.Element | HTMLElement; multimedia?: React.ReactNode | JSX.Element;
// actions // actions
undo?: () => Promise<void>; undo?: () => Promise<void>;
}; };

View File

@@ -7,7 +7,7 @@ import * as Toast from '@radix-ui/react-toast';
import { IconButton } from '@toeverything/components/button'; import { IconButton } from '@toeverything/components/button';
import clsx from 'clsx'; import clsx from 'clsx';
import { useAtom, useAtomValue, useSetAtom } from 'jotai'; import { useAtom, useAtomValue, useSetAtom } from 'jotai';
import type { ReactElement } from 'react'; import type { ReactNode } from 'react';
import { import {
useCallback, useCallback,
useEffect, useEffect,
@@ -70,7 +70,7 @@ const typeColorMap = {
}, },
}; };
function NotificationCard(props: NotificationCardProps): ReactElement { function NotificationCard(props: NotificationCardProps): ReactNode {
const removeNotification = useSetAtom(removeNotificationAtom); const removeNotification = useSetAtom(removeNotificationAtom);
const { notification, notifications, setHeights, heights, index } = props; const { notification, notifications, setHeights, heights, index } = props;
@@ -270,7 +270,7 @@ function NotificationCard(props: NotificationCardProps): ReactElement {
> >
{notification.multimedia ? ( {notification.multimedia ? (
<div className={styles.notificationMultimediaStyle}> <div className={styles.notificationMultimediaStyle}>
<>{notification.multimedia}</> {notification.multimedia}
<IconButton className={styles.closeButtonWithMediaStyle}> <IconButton className={styles.closeButtonWithMediaStyle}>
<CloseIcon onClick={onClickRemove} /> <CloseIcon onClick={onClickRemove} />
</IconButton> </IconButton>
@@ -373,7 +373,7 @@ function NotificationCard(props: NotificationCardProps): ReactElement {
); );
} }
export function NotificationCenter(): ReactElement { export function NotificationCenter(): ReactNode {
const notifications = useAtomValue(notificationsAtom); const notifications = useAtomValue(notificationsAtom);
const [expand, setExpand] = useAtom(expandNotificationCenterAtom); const [expand, setExpand] = useAtom(expandNotificationCenterAtom);
@@ -390,7 +390,7 @@ export function NotificationCenter(): ReactElement {
} }
}, [notifications, setExpand]); }, [notifications, setExpand]);
if (!notifications.length) return <></>; if (!notifications.length) return null;
return ( return (
<Toast.Provider swipeDirection="right"> <Toast.Provider swipeDirection="right">
{notifications.map((notification, index) => {notifications.map((notification, index) =>

View File

@@ -97,7 +97,7 @@ export const ExportMenuItems = ({
const items = itemMap.map(({ component: Component, props }) => ( const items = itemMap.map(({ component: Component, props }) => (
<Component key={props.label} {...props} /> <Component key={props.label} {...props} />
)); ));
return <>{items}</>; return items;
}; };
export const Export = ({ exportHandler, className }: ExportProps) => { export const Export = ({ exportHandler, className }: ExportProps) => {

View File

@@ -15,7 +15,7 @@ test('ProviderComposer', async () => {
}; };
const ConsumerComponent = () => { const ConsumerComponent = () => {
const value = useContext(Context); const value = useContext(Context);
return <>{value}</>; return value;
}; };
const Component = () => { const Component = () => {
return ( return (

View File

@@ -38,13 +38,9 @@ export const LocalSharePage = (props: ShareMenuProps) => {
const t = useAFFiNEI18N(); const t = useAFFiNEI18N();
return ( return (
<>
<div className={styles.localSharePage}> <div className={styles.localSharePage}>
<div className={styles.columnContainerStyle} style={{ gap: '12px' }}> <div className={styles.columnContainerStyle} style={{ gap: '12px' }}>
<div <div className={styles.descriptionStyle} style={{ maxWidth: '230px' }}>
className={styles.descriptionStyle}
style={{ maxWidth: '230px' }}
>
{t['com.affine.share-menu.EnableCloudDescription']()} {t['com.affine.share-menu.EnableCloudDescription']()}
</div> </div>
<div> <div>
@@ -61,7 +57,6 @@ export const LocalSharePage = (props: ShareMenuProps) => {
<CloudSvg /> <CloudSvg />
</div> </div>
</div> </div>
</>
); );
}; };
@@ -218,11 +213,7 @@ export const SharePage = (props: ShareMenuProps) => {
if (props.workspace.flavour === WorkspaceFlavour.LOCAL) { if (props.workspace.flavour === WorkspaceFlavour.LOCAL) {
return <LocalSharePage {...props} />; return <LocalSharePage {...props} />;
} else if (props.workspace.flavour === WorkspaceFlavour.AFFINE_CLOUD) { } else if (props.workspace.flavour === WorkspaceFlavour.AFFINE_CLOUD) {
return ( return <AffineSharePage {...props} />;
<>
<AffineSharePage {...props} />
</>
);
} }
throw new Error('Unreachable'); throw new Error('Unreachable');
}; };

View File

@@ -121,7 +121,7 @@ export const WorkspaceList = (props: WorkspaceListProps) => {
<SortableContext items={optimisticList}> <SortableContext items={optimisticList}>
{optimisticList.map(item => ( {optimisticList.map(item => (
<Suspense fallback={<WorkspaceCardSkeleton />} key={item.id}> <Suspense fallback={<WorkspaceCardSkeleton />} key={item.id}>
<SortableWorkspaceItem {...props} item={item} key={item.id} /> <SortableWorkspaceItem key={item.id} {...props} item={item} />
</Suspense> </Suspense>
))} ))}
</SortableContext> </SortableContext>

View File

@@ -171,8 +171,7 @@ export const Popper = ({
}} }}
> >
{showArrow ? ( {showArrow ? (
<> placement.indexOf('bottom') === 0 ? (
{placement.indexOf('bottom') === 0 ? (
<div <div
style={{ style={{
display: 'flex', display: 'flex',
@@ -270,10 +269,9 @@ export const Popper = ({
/> />
</svg> </svg>
</div> </div>
)} )
</>
) : ( ) : (
<>{content}</> content
)} )}
</div> </div>
</Grow> </Grow>

View File

@@ -76,9 +76,7 @@ export const TreeNodeItem = <RenderProps,>({
disableCollapse, disableCollapse,
allowDrop = true, allowDrop = true,
}: TreeNodeItemProps<RenderProps>) => { }: TreeNodeItemProps<RenderProps>) => {
return ( return node.render?.(node, {
<>
{node.render?.(node, {
isOver: isOver && allowDrop, isOver: isOver && allowDrop,
onAdd: () => onAdd?.(node.id), onAdd: () => onAdd?.(node.id),
onDelete: () => onDelete?.(node.id), onDelete: () => onDelete?.(node.id),
@@ -86,7 +84,5 @@ export const TreeNodeItem = <RenderProps,>({
setCollapsed, setCollapsed,
isSelected: selectedId === node.id, isSelected: selectedId === node.id,
disableCollapse, disableCollapse,
})} });
</>
);
}; };

View File

@@ -48,14 +48,12 @@ export const UI = {
); );
return ( return (
<>
<PageDetailEditor <PageDetailEditor
pageId={currentPageId} pageId={currentPageId}
onInit={useCallback(async page => initEmptyPage(page), [])} onInit={useCallback(async page => initEmptyPage(page), [])}
onLoad={onLoad} onLoad={onLoad}
workspace={workspace.blockSuiteWorkspace} workspace={workspace.blockSuiteWorkspace}
/> />
</>
); );
}, },
NewSettingsDetail: ({ NewSettingsDetail: ({

View File

@@ -92,14 +92,12 @@ export const LocalAdapter: WorkspaceAdapter<WorkspaceFlavour.LOCAL> = {
throw new PageNotFoundError(workspace, currentPageId); throw new PageNotFoundError(workspace, currentPageId);
} }
return ( return (
<>
<PageDetailEditor <PageDetailEditor
pageId={currentPageId} pageId={currentPageId}
onInit={useCallback(async page => initEmptyPage(page), [])} onInit={useCallback(async page => initEmptyPage(page), [])}
onLoad={onLoadEditor} onLoad={onLoadEditor}
workspace={workspace} workspace={workspace}
/> />
</>
); );
}, },
NewSettingsDetail: ({ NewSettingsDetail: ({

View File

@@ -16,14 +16,12 @@ export const UI = {
throw new PageNotFoundError(workspace.blockSuiteWorkspace, currentPageId); throw new PageNotFoundError(workspace.blockSuiteWorkspace, currentPageId);
} }
return ( return (
<>
<PageDetailEditor <PageDetailEditor
pageId={currentPageId} pageId={currentPageId}
onInit={useCallback(async page => initEmptyPage(page), [])} onInit={useCallback(async page => initEmptyPage(page), [])}
onLoad={onLoadEditor} onLoad={onLoadEditor}
workspace={workspace.blockSuiteWorkspace} workspace={workspace.blockSuiteWorkspace}
/> />
</>
); );
}, },
NewSettingsDetail: () => { NewSettingsDetail: () => {

View File

@@ -43,7 +43,7 @@ export const Captcha = () => {
const [response] = useAtom(responseAtom); const [response] = useAtom(responseAtom);
if (!runtimeConfig.enableCaptcha) { if (!runtimeConfig.enableCaptcha) {
return <></>; return null;
} }
if (environment.isDesktop) { if (environment.isDesktop) {

View File

@@ -2,7 +2,7 @@ import { SubscriptionPlan } from '@affine/graphql';
import { useAFFiNEI18N } from '@affine/i18n/hooks'; import { useAFFiNEI18N } from '@affine/i18n/hooks';
import Tooltip from '@toeverything/components/tooltip'; import Tooltip from '@toeverything/components/tooltip';
import { useSetAtom } from 'jotai'; import { useSetAtom } from 'jotai';
import React, { useCallback } from 'react'; import { useCallback } from 'react';
import { withErrorBoundary } from 'react-error-boundary'; import { withErrorBoundary } from 'react-error-boundary';
import { openSettingModalAtom } from '../../../atoms'; import { openSettingModalAtom } from '../../../atoms';
@@ -39,5 +39,5 @@ const UserPlanButtonWithData = () => {
// If fetch user data failed, just render empty. // If fetch user data failed, just render empty.
export const UserPlanButton = withErrorBoundary(UserPlanButtonWithData, { export const UserPlanButton = withErrorBoundary(UserPlanButtonWithData, {
fallbackRender: () => <React.Fragment />, fallbackRender: () => null,
}); });

View File

@@ -86,7 +86,6 @@ export const ExportPanel = ({ workspace }: ExportPanelProps) => {
}, [pushNotification, syncing, t, workspace, workspaceId]); }, [pushNotification, syncing, t, workspace, workspaceId]);
return ( return (
<>
<SettingRow name={t['Export']()} desc={t['Export Description']()}> <SettingRow name={t['Export']()} desc={t['Export Description']()}>
<Button <Button
data-testid="export-affine-backup" data-testid="export-affine-backup"
@@ -96,6 +95,5 @@ export const ExportPanel = ({ workspace }: ExportPanelProps) => {
{t['Export']()} {t['Export']()}
</Button> </Button>
</SettingRow> </SettingRow>
</>
); );
}; };

View File

@@ -121,7 +121,6 @@ export const AvatarAndName = () => {
}, [allowUpdate, input, user]); }, [allowUpdate, input, user]);
return ( return (
<>
<SettingRow <SettingRow
name={t['com.affine.settings.profile']()} name={t['com.affine.settings.profile']()}
desc={t['com.affine.settings.profile.message']()} desc={t['com.affine.settings.profile.message']()}
@@ -162,7 +161,6 @@ export const AvatarAndName = () => {
</div> </div>
</FlexWrapper> </FlexWrapper>
</SettingRow> </SettingRow>
</>
); );
}; };

View File

@@ -9,7 +9,7 @@ import { Trans } from '@affine/i18n';
import { useAFFiNEI18N } from '@affine/i18n/hooks'; import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { useQuery } from '@affine/workspace/affine/gql'; import { useQuery } from '@affine/workspace/affine/gql';
import { useSetAtom } from 'jotai'; import { useSetAtom } from 'jotai';
import React, { Suspense, useEffect, useRef, useState } from 'react'; import { Suspense, useEffect, useRef, useState } from 'react';
import type { FallbackProps } from 'react-error-boundary'; import type { FallbackProps } from 'react-error-boundary';
import { SWRErrorBoundary } from '../../../../../components/pure/swr-error-bundary'; import { SWRErrorBoundary } from '../../../../../components/pure/swr-error-bundary';
@@ -205,9 +205,9 @@ const PlansErrorBoundary = ({ resetErrorBoundary }: FallbackProps) => {
const t = useAFFiNEI18N(); const t = useAFFiNEI18N();
const title = t['com.affine.payment.title'](); const title = t['com.affine.payment.title']();
const subtitle = <React.Fragment />; const subtitle = '';
const tabs = <React.Fragment />; const tabs = '';
const footer = <React.Fragment />; const footer = '';
const scroll = ( const scroll = (
<div className={styles.errorTip}> <div className={styles.errorTip}>

View File

@@ -406,7 +406,6 @@ const Upgrade = ({
}, [onClose]); }, [onClose]);
return ( return (
<>
<Button <Button
className={styles.planAction} className={styles.planAction}
type="primary" type="primary"
@@ -416,7 +415,6 @@ const Upgrade = ({
> >
{t['com.affine.payment.upgrade']()} {t['com.affine.payment.upgrade']()}
</Button> </Button>
</>
); );
}; };

View File

@@ -218,7 +218,6 @@ export const PageMenu = ({ rename, pageId }: PageMenuProps) => {
return null; return null;
} }
return ( return (
<>
<FlexWrapper alignItems="center" justifyContent="center" ref={ref}> <FlexWrapper alignItems="center" justifyContent="center" ref={ref}>
<Menu <Menu
items={EditMenu} items={EditMenu}
@@ -229,6 +228,5 @@ export const PageMenu = ({ rename, pageId }: PageMenuProps) => {
<HeaderDropDownButton /> <HeaderDropDownButton />
</Menu> </Menu>
</FlexWrapper> </FlexWrapper>
</>
); );
}; };

View File

@@ -2,7 +2,7 @@ import { pushNotificationAtom } from '@affine/component/notification-center';
import { assertExists } from '@blocksuite/global/utils'; import { assertExists } from '@blocksuite/global/utils';
import { GraphQLError } from 'graphql'; import { GraphQLError } from 'graphql';
import { useSetAtom } from 'jotai'; import { useSetAtom } from 'jotai';
import type { PropsWithChildren, ReactElement } from 'react'; import type { PropsWithChildren, ReactNode } from 'react';
import { useCallback } from 'react'; import { useCallback } from 'react';
import type { SWRConfiguration } from 'swr'; import type { SWRConfiguration } from 'swr';
import { SWRConfig } from 'swr'; import { SWRConfig } from 'swr';
@@ -49,9 +49,9 @@ const cloudConfig: SWRConfiguration = {
], ],
}; };
export const Provider = (props: PropsWithChildren): ReactElement => { export const Provider = (props: PropsWithChildren): ReactNode => {
if (!runtimeConfig.enableCloud) { if (!runtimeConfig.enableCloud) {
return <>{props.children}</>; return props.children;
} }
return <SWRConfig value={cloudConfig}>{props.children}</SWRConfig>; return <SWRConfig value={cloudConfig}>{props.children}</SWRConfig>;

View File

@@ -328,10 +328,8 @@ export const PageDetailEditor = (props: PageDetailEditorProps) => {
} }
return ( return (
<>
<Suspense> <Suspense>
<LayoutPanel node={layout} editorProps={props} depth={0} /> <LayoutPanel node={layout} editorProps={props} depth={0} />
</Suspense> </Suspense>
</>
); );
}; };

View File

@@ -49,9 +49,7 @@ export const WorkspaceAvatar = forwardRef<HTMLDivElement, WorkspaceAvatarProps>(
const size = props.size || 20; const size = props.size || 20;
const sizeStr = size + 'px'; const sizeStr = size + 'px';
return ( return props.avatar ? (
<>
{props.avatar ? (
<div <div
style={{ style={{
...props.style, ...props.style,
@@ -94,8 +92,6 @@ export const WorkspaceAvatar = forwardRef<HTMLDivElement, WorkspaceAvatarProps>(
> >
{(props.name || 'AFFiNE').substring(0, 1)} {(props.name || 'AFFiNE').substring(0, 1)}
</div> </div>
)}
</>
); );
} }
); );

View File

@@ -170,7 +170,6 @@ export const RootAppSidebar = ({
useRegisterBlocksuiteEditorCommands(router.back, router.forward); useRegisterBlocksuiteEditorCommands(router.back, router.forward);
const userInfo = useDeleteCollectionInfo(); const userInfo = useDeleteCollectionInfo();
return ( return (
<>
<AppSidebar <AppSidebar
router={router} router={router}
hasBackground={ hasBackground={
@@ -193,9 +192,7 @@ export const RootAppSidebar = ({
rootOptions={{ rootOptions={{
open: openUserWorkspaceList, open: openUserWorkspaceList,
}} }}
items={ items={<UserWithWorkspaceList onEventEnd={closeUserWorkspaceList} />}
<UserWithWorkspaceList onEventEnd={closeUserWorkspaceList} />
}
contentOptions={{ contentOptions={{
// hide trigger // hide trigger
sideOffset: -58, sideOffset: -58,
@@ -273,6 +270,5 @@ export const RootAppSidebar = ({
<AddPageButton onClick={onClickNewPage} /> <AddPageButton onClick={onClickNewPage} />
</SidebarContainer> </SidebarContainer>
</AppSidebar> </AppSidebar>
</>
); );
}; };

View File

@@ -34,7 +34,7 @@ import { loadPage } from '@toeverything/hooks/use-block-suite-workspace-page';
import { currentWorkspaceIdAtom } from '@toeverything/infra/atom'; import { currentWorkspaceIdAtom } from '@toeverything/infra/atom';
import { useAtom, useAtomValue, useSetAtom } from 'jotai'; import { useAtom, useAtomValue, useSetAtom } from 'jotai';
import { nanoid } from 'nanoid'; import { nanoid } from 'nanoid';
import type { PropsWithChildren, ReactElement } from 'react'; import type { PropsWithChildren, ReactNode } from 'react';
import { lazy, Suspense, useCallback, useEffect } from 'react'; import { lazy, Suspense, useCallback, useEffect } from 'react';
import { useLocation, useParams } from 'react-router-dom'; import { useLocation, useParams } from 'react-router-dom';
import { Map as YMap } from 'yjs'; import { Map as YMap } from 'yjs';
@@ -101,7 +101,7 @@ const showList: IslandItemNames[] = environment.isDesktop
export const CurrentWorkspaceContext = ({ export const CurrentWorkspaceContext = ({
children, children,
}: PropsWithChildren): ReactElement => { }: PropsWithChildren): ReactNode => {
const workspaceId = useAtomValue(currentWorkspaceIdAtom); const workspaceId = useAtomValue(currentWorkspaceIdAtom);
const metadata = useAtomValue(rootWorkspacesMetadataAtom); const metadata = useAtomValue(rootWorkspacesMetadataAtom);
const exist = metadata.find(m => m.id === workspaceId); const exist = metadata.find(m => m.id === workspaceId);
@@ -114,7 +114,7 @@ export const CurrentWorkspaceContext = ({
if (!exist) { if (!exist) {
return <WorkspaceFallback key="workspace-not-found" />; return <WorkspaceFallback key="workspace-not-found" />;
} }
return <>{children}</>; return children;
}; };
type WorkspaceLayoutProps = { type WorkspaceLayoutProps = {

View File

@@ -108,7 +108,6 @@ const usePageOperationsRenderer = () => {
}); });
}; };
return ( return (
<>
<OperationCell <OperationCell
favorite={!!page.favorite} favorite={!!page.favorite}
isPublic={!!page.isPublic} isPublic={!!page.isPublic}
@@ -131,7 +130,6 @@ const usePageOperationsRenderer = () => {
); );
}} }}
/> />
</>
); );
}, },
[currentWorkspace.id, setTrashModal, t, toggleFavorite] [currentWorkspace.id, setTrashModal, t, toggleFavorite]

View File

@@ -59,7 +59,6 @@ export const TrashPage = () => {
[permanentlyDeletePage, restoreFromTrash, t] [permanentlyDeletePage, restoreFromTrash, t]
); );
return ( return (
<>
<div className={styles.root}> <div className={styles.root}>
<WorkspaceHeader <WorkspaceHeader
currentWorkspaceId={currentWorkspace.id} currentWorkspaceId={currentWorkspace.id}
@@ -83,7 +82,6 @@ export const TrashPage = () => {
/> />
)} )}
</div> </div>
</>
); );
}; };

View File

@@ -53,12 +53,10 @@ const Main = () => {
export const Default: StoryFn = () => { export const Default: StoryFn = () => {
return ( return (
<>
<Container> <Container>
<AppSidebar /> <AppSidebar />
<Main /> <Main />
</Container> </Container>
</>
); );
}; };

View File

@@ -28,10 +28,8 @@ export const CMDKModalStory: StoryFn = () => {
export const CMDKPanelStory: StoryFn = () => { export const CMDKPanelStory: StoryFn = () => {
const [query, setQuery] = useState(''); const [query, setQuery] = useState('');
return ( return (
<>
<CMDKModal open> <CMDKModal open>
<CMDKContainer open query={query} onQueryChange={setQuery} /> <CMDKContainer open query={query} onQueryChange={setQuery} />
</CMDKModal> </CMDKModal>
</>
); );
}; };