mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
style: add no-misused-promises rule (#3547)
Co-authored-by: Peng Xiao <pengxiao@outlook.com>
This commit is contained in:
@@ -181,7 +181,9 @@ function NotificationCard(props: NotificationCardProps): ReactElement {
|
||||
|
||||
const onClickUndo = useCallback(() => {
|
||||
if (notification.undo) {
|
||||
return notification.undo();
|
||||
notification.undo().catch(err => {
|
||||
console.error(err);
|
||||
});
|
||||
}
|
||||
return void 0;
|
||||
}, [notification]);
|
||||
|
||||
@@ -63,10 +63,14 @@ export const CollectionBar = (props: CollectionBarProps) => {
|
||||
: t['com.affine.collection-bar.action.tooltip.pin'](),
|
||||
className: styles.pin,
|
||||
click: () => {
|
||||
return setting.updateCollection({
|
||||
...collection,
|
||||
pinned: !collection.pinned,
|
||||
});
|
||||
setting
|
||||
.updateCollection({
|
||||
...collection,
|
||||
pinned: !collection.pinned,
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -102,6 +106,7 @@ export const CollectionBar = (props: CollectionBarProps) => {
|
||||
init={collection}
|
||||
open={open}
|
||||
onClose={onClose}
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||
onConfirm={setting.updateCollection}
|
||||
></EditCollectionModel>
|
||||
<ViewLayersIcon
|
||||
|
||||
@@ -43,10 +43,14 @@ const CollectionOption = ({
|
||||
icon: <PinIcon />,
|
||||
name: 'pin',
|
||||
click: () => {
|
||||
return setting.updateCollection({
|
||||
...collection,
|
||||
pinned: !collection.pinned,
|
||||
});
|
||||
setting
|
||||
.updateCollection({
|
||||
...collection,
|
||||
pinned: !collection.pinned,
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -144,10 +148,14 @@ export const CollectionList = ({
|
||||
const [collection, setCollection] = useState<Collection>();
|
||||
const onChange = useCallback(
|
||||
(filterList: Filter[]) => {
|
||||
return setting.updateCollection({
|
||||
...setting.currentCollection,
|
||||
filterList,
|
||||
});
|
||||
setting
|
||||
.updateCollection({
|
||||
...setting.currentCollection,
|
||||
filterList,
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
});
|
||||
},
|
||||
[setting]
|
||||
);
|
||||
@@ -156,10 +164,9 @@ export const CollectionList = ({
|
||||
[]
|
||||
);
|
||||
const onConfirm = useCallback(
|
||||
(view: Collection) => {
|
||||
return setting.updateCollection(view).then(() => {
|
||||
closeUpdateCollectionModal();
|
||||
});
|
||||
async (view: Collection) => {
|
||||
await setting.updateCollection(view);
|
||||
closeUpdateCollectionModal();
|
||||
},
|
||||
[closeUpdateCollectionModal, setting]
|
||||
);
|
||||
|
||||
@@ -32,7 +32,7 @@ type CreateCollectionProps = {
|
||||
};
|
||||
|
||||
type SaveCollectionButtonProps = {
|
||||
onConfirm: (collection: Collection) => void;
|
||||
onConfirm: (collection: Collection) => Promise<void>;
|
||||
getPageInfo: GetPageInfoById;
|
||||
propertiesMeta: PropertiesMeta;
|
||||
filterList: Filter[];
|
||||
@@ -49,7 +49,7 @@ export const EditCollectionModel = ({
|
||||
title,
|
||||
}: {
|
||||
init?: Collection;
|
||||
onConfirm: (view: Collection) => void;
|
||||
onConfirm: (view: Collection) => Promise<void>;
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
title?: string;
|
||||
@@ -57,6 +57,18 @@ export const EditCollectionModel = ({
|
||||
propertiesMeta: PropertiesMeta;
|
||||
}) => {
|
||||
const t = useAFFiNEI18N();
|
||||
const onConfirmOnCollection = useCallback(
|
||||
(view: Collection) => {
|
||||
onConfirm(view)
|
||||
.then(() => {
|
||||
onClose();
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
});
|
||||
},
|
||||
[onClose, onConfirm]
|
||||
);
|
||||
return (
|
||||
<Modal open={open} onClose={onClose}>
|
||||
<ModalWrapper
|
||||
@@ -75,10 +87,7 @@ export const EditCollectionModel = ({
|
||||
init={init}
|
||||
getPageInfo={getPageInfo}
|
||||
onCancel={onClose}
|
||||
onConfirm={view => {
|
||||
onConfirm(view);
|
||||
onClose();
|
||||
}}
|
||||
onConfirm={onConfirmOnCollection}
|
||||
/>
|
||||
) : null}
|
||||
</ModalWrapper>
|
||||
|
||||
@@ -47,9 +47,15 @@ export const AffineSharePage: FC<ShareMenuProps> = props => {
|
||||
const onClickCreateLink = useCallback(() => {
|
||||
setIsPublic(true);
|
||||
}, [setIsPublic]);
|
||||
const onClickCopyLink = useCallback(async () => {
|
||||
await navigator.clipboard.writeText(sharingUrl);
|
||||
toast(t['Copied link to clipboard']());
|
||||
const onClickCopyLink = useCallback(() => {
|
||||
navigator.clipboard
|
||||
.writeText(sharingUrl)
|
||||
.then(() => {
|
||||
toast(t['Copied link to clipboard']());
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
});
|
||||
}, [sharingUrl, t]);
|
||||
const onDisablePublic = useCallback(() => {
|
||||
setIsPublic(false);
|
||||
|
||||
@@ -115,21 +115,26 @@ export const toast = (
|
||||
|
||||
element.animate(fadeIn, options);
|
||||
|
||||
setTimeout(async () => {
|
||||
setTimeout(() => {
|
||||
const animation = element.animate(
|
||||
// fade out
|
||||
fadeIn.reverse(),
|
||||
options
|
||||
);
|
||||
await animation.finished;
|
||||
element.style.maxHeight = '0';
|
||||
element.style.margin = '0';
|
||||
element.style.padding = '0';
|
||||
// wait for transition
|
||||
// ToastContainer = null;
|
||||
element.addEventListener('transitionend', () => {
|
||||
element.remove();
|
||||
});
|
||||
animation.finished
|
||||
.then(() => {
|
||||
element.style.maxHeight = '0';
|
||||
element.style.margin = '0';
|
||||
element.style.padding = '0';
|
||||
// wait for transition
|
||||
// ToastContainer = null;
|
||||
element.addEventListener('transitionend', () => {
|
||||
element.remove();
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
});
|
||||
}, duration);
|
||||
return element;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user