mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-11-22 07:52:07 +03:00
style: add no-misused-promises rule (#3547)
Co-authored-by: Peng Xiao <pengxiao@outlook.com>
This commit is contained in:
parent
f8e49ee3be
commit
5795020403
@ -214,6 +214,7 @@ const config = {
|
||||
ignoreIIFE: false,
|
||||
},
|
||||
],
|
||||
'@typescript-eslint/no-misused-promises': ['error'],
|
||||
},
|
||||
})),
|
||||
{
|
||||
@ -239,6 +240,7 @@ const config = {
|
||||
},
|
||||
],
|
||||
'@typescript-eslint/no-floating-promises': 0,
|
||||
'@typescript-eslint/no-misused-promises': 0,
|
||||
},
|
||||
},
|
||||
],
|
||||
|
@ -115,7 +115,11 @@ function startPollingSecondaryDB(db: WorkspaceSQLiteDB) {
|
||||
const secondaryDB = new SecondaryWorkspaceSQLiteDB(path, db);
|
||||
return new Observable<SecondaryWorkspaceSQLiteDB>(subscriber => {
|
||||
subscriber.next(secondaryDB);
|
||||
return () => secondaryDB.destroy();
|
||||
return () => {
|
||||
secondaryDB.destroy().catch(err => {
|
||||
subscriber.error(err);
|
||||
});
|
||||
};
|
||||
});
|
||||
}),
|
||||
switchMap(secondaryDB => {
|
||||
|
@ -38,7 +38,7 @@ app.on('second-instance', () => {
|
||||
);
|
||||
});
|
||||
|
||||
app.on('open-url', async (_, _url) => {
|
||||
app.on('open-url', (_, _url) => {
|
||||
// todo: handle `affine://...` urls
|
||||
});
|
||||
|
||||
@ -54,7 +54,11 @@ app.on('window-all-closed', () => {
|
||||
/**
|
||||
* @see https://www.electronjs.org/docs/v14-x-y/api/app#event-activate-macos Event: 'activate'
|
||||
*/
|
||||
app.on('activate', restoreOrCreateWindow);
|
||||
app.on('activate', () => {
|
||||
restoreOrCreateWindow().catch(err => {
|
||||
console.error(err);
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Create app window when background process will be ready
|
||||
|
@ -34,7 +34,7 @@ export function getGoogleOauthCode() {
|
||||
logger.error('Failed to open external url', e);
|
||||
reject(e);
|
||||
});
|
||||
const handleOpenUrl = async (_: any, url: string) => {
|
||||
const handleOpenUrl = (_: any, url: string) => {
|
||||
const mainWindow = BrowserWindow.getAllWindows().find(
|
||||
w => !w.isDestroyed()
|
||||
);
|
||||
|
@ -99,7 +99,9 @@ export const registerUpdater = async () => {
|
||||
});
|
||||
autoUpdater.forceDevUpdateConfig = isDev;
|
||||
|
||||
app.on('activate', async () => {
|
||||
await checkForUpdates(false);
|
||||
app.on('activate', () => {
|
||||
checkForUpdates(false).catch(err => {
|
||||
console.error(err);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
@ -19,10 +19,15 @@ const mainThread = AsyncCall<{
|
||||
channel: new MessageEventChannel(parentPort),
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||
globalThis.console.log = mainThread.log;
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||
globalThis.console.error = mainThread.log;
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||
globalThis.console.info = mainThread.log;
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||
globalThis.console.debug = mainThread.log;
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||
globalThis.console.warn = mainThread.log;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
|
@ -77,7 +77,7 @@ export class WorkspaceResolver {
|
||||
return workspace.permission;
|
||||
}
|
||||
|
||||
const permission = this.permissionProvider.get(workspace.id, user.id);
|
||||
const permission = await this.permissionProvider.get(workspace.id, user.id);
|
||||
|
||||
if (!permission) {
|
||||
throw new ForbiddenException();
|
||||
|
@ -9,8 +9,10 @@ export class PrismaService extends PrismaClient implements OnModuleInit {
|
||||
}
|
||||
|
||||
async enableShutdownHooks(app: INestApplication) {
|
||||
process.on('beforeExit', async () => {
|
||||
await app.close();
|
||||
process.on('beforeExit', () => {
|
||||
app.close().catch(e => {
|
||||
console.error(e);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
||||
|
@ -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]);
|
||||
})
|
||||
|
@ -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);
|
||||
});
|
||||
},
|
||||
};
|
||||
};
|
||||
|
@ -34,9 +34,12 @@ const Actions = () => {
|
||||
/>
|
||||
<IconButton
|
||||
className={sendButtonStyle}
|
||||
onClick={useCallback(async () => {
|
||||
await call(input);
|
||||
await generateFollowingUp();
|
||||
onClick={useCallback(() => {
|
||||
call(input)
|
||||
.then(() => generateFollowingUp())
|
||||
.catch(e => {
|
||||
console.error(e);
|
||||
});
|
||||
}, [call, generateFollowingUp, input])}
|
||||
>
|
||||
<SendIcon />
|
||||
|
Loading…
Reference in New Issue
Block a user