style: add no-misused-promises rule (#3547)

Co-authored-by: Peng Xiao <pengxiao@outlook.com>
This commit is contained in:
LongYinan
2023-08-04 16:08:10 +08:00
committed by GitHub
parent f8e49ee3be
commit 5795020403
19 changed files with 130 additions and 74 deletions

View File

@@ -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]);

View File

@@ -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

View File

@@ -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]
);

View File

@@ -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>

View File

@@ -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);

View File

@@ -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;
};

View File

@@ -87,23 +87,22 @@ const main = async () => {
language => language.completeRate > 0.4
);
availableLanguages
for (const language of availableLanguages
// skip base language
.filter(i => !i.base)
.forEach(async language => {
await fs.writeFile(
path.resolve(RES_DIR, `${language.tag}.json`),
JSON.stringify(
{
'// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.':
'',
...flattenTranslation(language.translations),
},
null,
INDENT
) + '\n'
);
});
.filter(i => !i.base)) {
await fs.writeFile(
path.resolve(RES_DIR, `${language.tag}.json`),
JSON.stringify(
{
'// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.':
'',
...flattenTranslation(language.translations),
},
null,
INDENT
) + '\n'
);
}
console.log('Generating meta data...');
const code = `// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.

View File

@@ -127,11 +127,11 @@ const main = async () => {
return;
}
diff.add.forEach(async key => {
for (const key of diff.add) {
const val = flatLocalTranslations[key];
console.log(`Creating new key: ${key} -> ${val}`);
await createsNewKey(key, { [BASE_LANGUAGES]: val });
});
}
// TODO remove unused tags from used keys

View File

@@ -116,7 +116,7 @@ function getMainAPIs() {
}
const helperPort$ = new Promise<MessagePort>(resolve =>
ipcRenderer.on('helper-connection', async e => {
ipcRenderer.on('helper-connection', e => {
console.info('[preload] helper-connection', e);
resolve(e.ports[0]);
})

View File

@@ -106,14 +106,15 @@ export const createSQLiteDBDownloadProvider: DocProviderCreator = (
cleanup: () => {
// todo
},
sync: async () => {
sync: () => {
logger.info('connect sqlite download provider', id);
try {
await syncUpdates(rootDoc);
_resolve();
} catch (error) {
_reject(error);
}
syncUpdates(rootDoc)
.then(() => {
_resolve();
})
.catch(error => {
_reject(error);
});
},
};
};