mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-20 11:36:25 +08:00
chore: modify code style (#3914)
This commit is contained in:
@@ -22,22 +22,15 @@ import {
|
|||||||
import { FilterList } from '../filter';
|
import { FilterList } from '../filter';
|
||||||
import * as styles from './collection-list.css';
|
import * as styles from './collection-list.css';
|
||||||
|
|
||||||
type CreateCollectionProps = {
|
interface EditCollectionModelProps {
|
||||||
|
init?: Collection;
|
||||||
title?: string;
|
title?: string;
|
||||||
init: Collection;
|
open: boolean;
|
||||||
onConfirm: (collection: Collection) => void;
|
|
||||||
onConfirmText?: string;
|
|
||||||
getPageInfo: GetPageInfoById;
|
getPageInfo: GetPageInfoById;
|
||||||
propertiesMeta: PropertiesMeta;
|
propertiesMeta: PropertiesMeta;
|
||||||
};
|
onClose: () => void;
|
||||||
|
onConfirm: (view: Collection) => Promise<void>;
|
||||||
type SaveCollectionButtonProps = {
|
}
|
||||||
onConfirm: (collection: Collection) => Promise<void>;
|
|
||||||
getPageInfo: GetPageInfoById;
|
|
||||||
propertiesMeta: PropertiesMeta;
|
|
||||||
filterList: Filter[];
|
|
||||||
workspaceId: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const EditCollectionModel = ({
|
export const EditCollectionModel = ({
|
||||||
init,
|
init,
|
||||||
@@ -47,15 +40,7 @@ export const EditCollectionModel = ({
|
|||||||
getPageInfo,
|
getPageInfo,
|
||||||
propertiesMeta,
|
propertiesMeta,
|
||||||
title,
|
title,
|
||||||
}: {
|
}: EditCollectionModelProps) => {
|
||||||
init?: Collection;
|
|
||||||
onConfirm: (view: Collection) => Promise<void>;
|
|
||||||
open: boolean;
|
|
||||||
onClose: () => void;
|
|
||||||
title?: string;
|
|
||||||
getPageInfo: GetPageInfoById;
|
|
||||||
propertiesMeta: PropertiesMeta;
|
|
||||||
}) => {
|
|
||||||
const t = useAFFiNEI18N();
|
const t = useAFFiNEI18N();
|
||||||
const onConfirmOnCollection = useCallback(
|
const onConfirmOnCollection = useCallback(
|
||||||
(view: Collection) => {
|
(view: Collection) => {
|
||||||
@@ -95,47 +80,46 @@ export const EditCollectionModel = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const Page = ({
|
interface PageProps {
|
||||||
id,
|
|
||||||
onClick,
|
|
||||||
getPageInfo,
|
|
||||||
}: {
|
|
||||||
id: string;
|
id: string;
|
||||||
onClick: (id: string) => void;
|
|
||||||
getPageInfo: GetPageInfoById;
|
getPageInfo: GetPageInfoById;
|
||||||
}) => {
|
onClick: (id: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Page = ({ id, onClick, getPageInfo }: PageProps) => {
|
||||||
const page = getPageInfo(id);
|
const page = getPageInfo(id);
|
||||||
if (!page) {
|
const handleClick = useCallback(() => onClick(id), [id, onClick]);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const icon = page.isEdgeless ? (
|
|
||||||
<EdgelessIcon
|
|
||||||
style={{
|
|
||||||
width: 17.5,
|
|
||||||
height: 17.5,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<PageIcon
|
|
||||||
style={{
|
|
||||||
width: 17.5,
|
|
||||||
height: 17.5,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
const click = () => {
|
|
||||||
onClick(id);
|
|
||||||
};
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.pageContainer}>
|
<>
|
||||||
<div className={styles.pageIcon}>{icon}</div>
|
{page ? (
|
||||||
<div className={styles.pageTitle}>{page.title}</div>
|
<div className={styles.pageContainer}>
|
||||||
<div onClick={click} className={styles.deleteIcon}>
|
<div className={styles.pageIcon}>
|
||||||
<RemoveIcon />
|
{page.isEdgeless ? (
|
||||||
</div>
|
<EdgelessIcon style={{ width: 17.5, height: 17.5 }} />
|
||||||
</div>
|
) : (
|
||||||
|
<PageIcon style={{ width: 17.5, height: 17.5 }} />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className={styles.pageTitle}>{page.title}</div>
|
||||||
|
<div onClick={handleClick} className={styles.deleteIcon}>
|
||||||
|
<RemoveIcon />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
interface EditCollectionProps {
|
||||||
|
title?: string;
|
||||||
|
onConfirmText?: string;
|
||||||
|
init: Collection;
|
||||||
|
getPageInfo: GetPageInfoById;
|
||||||
|
propertiesMeta: PropertiesMeta;
|
||||||
|
onCancel: () => void;
|
||||||
|
onConfirm: (collection: Collection) => void;
|
||||||
|
}
|
||||||
|
|
||||||
export const EditCollection = ({
|
export const EditCollection = ({
|
||||||
title,
|
title,
|
||||||
init,
|
init,
|
||||||
@@ -144,9 +128,7 @@ export const EditCollection = ({
|
|||||||
onConfirmText,
|
onConfirmText,
|
||||||
getPageInfo,
|
getPageInfo,
|
||||||
propertiesMeta,
|
propertiesMeta,
|
||||||
}: CreateCollectionProps & {
|
}: EditCollectionProps) => {
|
||||||
onCancel: () => void;
|
|
||||||
}) => {
|
|
||||||
const t = useAFFiNEI18N();
|
const t = useAFFiNEI18N();
|
||||||
const [value, onChange] = useState<Collection>(init);
|
const [value, onChange] = useState<Collection>(init);
|
||||||
const removeFromExcludeList = useCallback(
|
const removeFromExcludeList = useCallback(
|
||||||
@@ -223,13 +205,8 @@ export const EditCollection = ({
|
|||||||
<FilterList
|
<FilterList
|
||||||
propertiesMeta={propertiesMeta}
|
propertiesMeta={propertiesMeta}
|
||||||
value={value.filterList}
|
value={value.filterList}
|
||||||
onChange={list =>
|
onChange={filterList => onChange({ ...value, filterList })}
|
||||||
onChange({
|
/>
|
||||||
...value,
|
|
||||||
filterList: list,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
></FilterList>
|
|
||||||
{value.allowList ? (
|
{value.allowList ? (
|
||||||
<div className={styles.allowList}>
|
<div className={styles.allowList}>
|
||||||
<div className={styles.allowTitle}>With follow pages:</div>
|
<div className={styles.allowTitle}>With follow pages:</div>
|
||||||
@@ -253,12 +230,7 @@ export const EditCollection = ({
|
|||||||
data-testid="input-collection-title"
|
data-testid="input-collection-title"
|
||||||
placeholder={t['Untitled Collection']()}
|
placeholder={t['Untitled Collection']()}
|
||||||
defaultValue={value.name}
|
defaultValue={value.name}
|
||||||
onChange={text =>
|
onChange={name => onChange({ ...value, name })}
|
||||||
onChange({
|
|
||||||
...value,
|
|
||||||
name: text,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</ScrollableContainer>
|
</ScrollableContainer>
|
||||||
@@ -288,6 +260,15 @@ export const EditCollection = ({
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
interface SaveCollectionButtonProps {
|
||||||
|
getPageInfo: GetPageInfoById;
|
||||||
|
propertiesMeta: PropertiesMeta;
|
||||||
|
filterList: Filter[];
|
||||||
|
workspaceId: string;
|
||||||
|
onConfirm: (collection: Collection) => Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
export const SaveCollectionButton = ({
|
export const SaveCollectionButton = ({
|
||||||
onConfirm,
|
onConfirm,
|
||||||
getPageInfo,
|
getPageInfo,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||||
import { Button } from '@toeverything/components/button';
|
import { Button } from '@toeverything/components/button';
|
||||||
|
import { useCallback, useMemo } from 'react';
|
||||||
|
|
||||||
import type { ModalProps } from '../modal';
|
import type { ModalProps } from '../modal';
|
||||||
import { Modal, ModalCloseButton } from '../modal';
|
import { Modal, ModalCloseButton } from '../modal';
|
||||||
@@ -39,33 +40,36 @@ export const Confirm = ({
|
|||||||
confirmButtonTestId = '',
|
confirmButtonTestId = '',
|
||||||
}: ConfirmProps) => {
|
}: ConfirmProps) => {
|
||||||
const t = useAFFiNEI18N();
|
const t = useAFFiNEI18N();
|
||||||
|
const cancelText_ = useMemo<string>(() => {
|
||||||
|
return cancelText === 'Cancel' ? t['Cancel']() : cancelText;
|
||||||
|
}, [cancelText, t]);
|
||||||
|
|
||||||
|
const handleCancel = useCallback(() => {
|
||||||
|
onCancel?.();
|
||||||
|
}, [onCancel]);
|
||||||
|
const handleConfirm = useCallback(() => {
|
||||||
|
onConfirm?.();
|
||||||
|
}, [onConfirm]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal open={open} disablePortal={false}>
|
<Modal open={open} disablePortal={false}>
|
||||||
<StyledModalWrapper>
|
<StyledModalWrapper>
|
||||||
<ModalCloseButton
|
<ModalCloseButton onClick={handleCancel} />
|
||||||
onClick={() => {
|
|
||||||
onCancel?.();
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<StyledConfirmTitle>{title}</StyledConfirmTitle>
|
<StyledConfirmTitle>{title}</StyledConfirmTitle>
|
||||||
<StyledConfirmContent>{content}</StyledConfirmContent>
|
<StyledConfirmContent>{content}</StyledConfirmContent>
|
||||||
{buttonDirection === 'row' ? (
|
{buttonDirection === 'row' ? (
|
||||||
<StyledRowButtonWrapper>
|
<StyledRowButtonWrapper>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={handleCancel}
|
||||||
onCancel?.();
|
|
||||||
}}
|
|
||||||
size="large"
|
size="large"
|
||||||
style={{ marginRight: '24px' }}
|
style={{ marginRight: '24px' }}
|
||||||
data-testid={cancelButtonTestId}
|
data-testid={cancelButtonTestId}
|
||||||
>
|
>
|
||||||
{cancelText === 'Cancel' ? t['Cancel']() : cancelText}
|
{cancelText_}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
type={confirmType}
|
type={confirmType}
|
||||||
onClick={() => {
|
onClick={handleConfirm}
|
||||||
onConfirm?.();
|
|
||||||
}}
|
|
||||||
size="large"
|
size="large"
|
||||||
data-testid={confirmButtonTestId}
|
data-testid={confirmButtonTestId}
|
||||||
>
|
>
|
||||||
@@ -76,18 +80,14 @@ export const Confirm = ({
|
|||||||
<StyledColumnButtonWrapper>
|
<StyledColumnButtonWrapper>
|
||||||
<Button
|
<Button
|
||||||
type={confirmType}
|
type={confirmType}
|
||||||
onClick={() => {
|
onClick={handleConfirm}
|
||||||
onConfirm?.();
|
|
||||||
}}
|
|
||||||
style={{ width: '284px', height: '38px', textAlign: 'center' }}
|
style={{ width: '284px', height: '38px', textAlign: 'center' }}
|
||||||
data-testid={confirmButtonTestId}
|
data-testid={confirmButtonTestId}
|
||||||
>
|
>
|
||||||
{confirmText}
|
{confirmText}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={handleCancel}
|
||||||
onCancel?.();
|
|
||||||
}}
|
|
||||||
style={{
|
style={{
|
||||||
marginTop: '16px',
|
marginTop: '16px',
|
||||||
width: '284px',
|
width: '284px',
|
||||||
@@ -96,7 +96,7 @@ export const Confirm = ({
|
|||||||
}}
|
}}
|
||||||
data-testid={cancelButtonTestId}
|
data-testid={cancelButtonTestId}
|
||||||
>
|
>
|
||||||
{cancelText === 'Cancel' ? t['Cancel']() : cancelText}
|
{cancelText_}
|
||||||
</Button>
|
</Button>
|
||||||
</StyledColumnButtonWrapper>
|
</StyledColumnButtonWrapper>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user