mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
feat: add new rule for floating promise (#2726)
Co-authored-by: Himself65 <himself65@outlook.com>
This commit is contained in:
@@ -46,7 +46,9 @@ export const LocalAdapter: WorkspaceAdapter<WorkspaceFlavour.LOCAL> = {
|
||||
});
|
||||
setEditorFlags(blockSuiteWorkspace);
|
||||
if (config.enablePreloading) {
|
||||
initPageWithPreloading(page);
|
||||
initPageWithPreloading(page).catch(err => {
|
||||
logger.error('init page with preloading failed', err);
|
||||
});
|
||||
} else {
|
||||
initEmptyPage(page);
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ export class AffineErrorBoundary extends Component<
|
||||
pageId: error.workspace.meta.pageMetas[0].id,
|
||||
},
|
||||
})
|
||||
.then(() => {
|
||||
.finally(() => {
|
||||
this.setState({ error: null });
|
||||
});
|
||||
}}
|
||||
|
||||
@@ -95,7 +95,7 @@ export const WorkspaceSettingDetail: React.FC<
|
||||
const workspaceId = workspace.id;
|
||||
useEffect(() => {
|
||||
if (isAffine && isOwner) {
|
||||
preload([QueryKey.getMembers, workspaceId], fetcher);
|
||||
preload([QueryKey.getMembers, workspaceId], fetcher).catch(console.error);
|
||||
}
|
||||
}, [isAffine, isOwner, workspaceId]);
|
||||
const containerRef = useRef<HTMLDivElement | null>(null);
|
||||
|
||||
@@ -46,8 +46,8 @@ const PublishPanelAffine: React.FC<PublishPanelAffineProps> = ({
|
||||
const shareUrl = origin + '/public-workspace/' + workspace.id;
|
||||
const t = useAFFiNEI18N();
|
||||
const publishWorkspace = useToggleWorkspacePublish(workspace);
|
||||
const copyUrl = useCallback(() => {
|
||||
navigator.clipboard.writeText(shareUrl);
|
||||
const copyUrl = useCallback(async () => {
|
||||
await navigator.clipboard.writeText(shareUrl);
|
||||
toast(t['Copied link to clipboard']());
|
||||
}, [shareUrl, t]);
|
||||
|
||||
|
||||
@@ -16,12 +16,12 @@ export const usePageHelper = (blockSuiteWorkspace: BlockSuiteWorkspace) => {
|
||||
|
||||
const createPageAndOpen = () => {
|
||||
const page = createPage();
|
||||
openPage(blockSuiteWorkspace.id, page.id);
|
||||
return openPage(blockSuiteWorkspace.id, page.id);
|
||||
};
|
||||
const createEdgelessAndOpen = () => {
|
||||
const page = createPage();
|
||||
setPreferredMode(page.id, 'edgeless');
|
||||
openPage(blockSuiteWorkspace.id, page.id);
|
||||
return openPage(blockSuiteWorkspace.id, page.id);
|
||||
};
|
||||
const importFileAndOpen = async () => {
|
||||
const { showImportModal } = await import('@blocksuite/blocks');
|
||||
|
||||
@@ -10,7 +10,9 @@ export const EditPage = () => {
|
||||
const { jumpToPage } = useRouterHelper(router);
|
||||
const onClickPage = useCallback(() => {
|
||||
if (workspaceId && pageId) {
|
||||
jumpToPage(workspaceId, pageId);
|
||||
jumpToPage(workspaceId, pageId).catch(error => {
|
||||
console.error(error);
|
||||
});
|
||||
}
|
||||
}, [jumpToPage, pageId, workspaceId]);
|
||||
return (
|
||||
|
||||
@@ -9,7 +9,7 @@ const LanguageMenuContent: FC = () => {
|
||||
const i18n = useI18N();
|
||||
const changeLanguage = useCallback(
|
||||
(event: string) => {
|
||||
i18n.changeLanguage(event);
|
||||
void i18n.changeLanguage(event);
|
||||
},
|
||||
[i18n]
|
||||
);
|
||||
|
||||
@@ -96,8 +96,8 @@ const LocalHeaderShareMenu: React.FC<BaseHeaderProps> = props => {
|
||||
onClose={() => {
|
||||
setOpen(false);
|
||||
}}
|
||||
onConform={() => {
|
||||
onTransformWorkspace(
|
||||
onConform={async () => {
|
||||
await onTransformWorkspace(
|
||||
WorkspaceFlavour.LOCAL,
|
||||
WorkspaceFlavour.AFFINE,
|
||||
props.workspace as LocalWorkspace
|
||||
|
||||
@@ -138,17 +138,14 @@ export const SyncUser = () => {
|
||||
workspace as LocalWorkspace
|
||||
);
|
||||
// fixme(himself65): refactor this
|
||||
router
|
||||
.replace({
|
||||
pathname: `/workspace/[workspaceId]/all`,
|
||||
query: {
|
||||
workspaceId: id,
|
||||
},
|
||||
})
|
||||
.then(() => {
|
||||
router.reload();
|
||||
});
|
||||
await router.replace({
|
||||
pathname: `/workspace/[workspaceId]/all`,
|
||||
query: {
|
||||
workspaceId: id,
|
||||
},
|
||||
});
|
||||
setOpen(false);
|
||||
router.reload();
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
|
||||
@@ -63,9 +63,10 @@ export const TrashButtonGroup = () => {
|
||||
workspaceId: workspace.id,
|
||||
},
|
||||
})
|
||||
.then(() => {
|
||||
blockSuiteWorkspace.removePage(pageId);
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
});
|
||||
blockSuiteWorkspace.removePage(pageId);
|
||||
}}
|
||||
onCancel={() => {
|
||||
setOpen(false);
|
||||
|
||||
@@ -43,7 +43,7 @@ export const MessageCenter: FC = memo(function MessageCenter() {
|
||||
})
|
||||
.catch(() => {
|
||||
setPopup(false);
|
||||
onLogout();
|
||||
return onLogout();
|
||||
});
|
||||
} else {
|
||||
toast(Messages[event.detail.code].message);
|
||||
|
||||
@@ -64,9 +64,11 @@ export const PublishedResults: FC<PublishedResultsProps> = ({
|
||||
<Command.Item
|
||||
key={result.id}
|
||||
onSelect={() => {
|
||||
router.push(
|
||||
`/public-workspace/${router.query.workspaceId}/${result.id}`
|
||||
);
|
||||
router
|
||||
.push(
|
||||
`/public-workspace/${router.query.workspaceId}/${result.id}`
|
||||
)
|
||||
.catch(err => console.error(err));
|
||||
onClose();
|
||||
}}
|
||||
value={result.id}
|
||||
|
||||
@@ -71,7 +71,9 @@ export const Results: FC<ResultsProps> = ({
|
||||
value={page.id}
|
||||
onSelect={() => {
|
||||
onClose();
|
||||
jumpToPage(blockSuiteWorkspace.id, page.id);
|
||||
jumpToPage(blockSuiteWorkspace.id, page.id).catch(
|
||||
console.error
|
||||
);
|
||||
}}
|
||||
>
|
||||
<StyledListItem>
|
||||
@@ -95,7 +97,7 @@ export const Results: FC<ResultsProps> = ({
|
||||
value={link.title}
|
||||
onSelect={() => {
|
||||
onClose();
|
||||
router.push(link.href);
|
||||
router.push(link.href).catch(console.error);
|
||||
}}
|
||||
>
|
||||
<StyledListItem>
|
||||
@@ -133,7 +135,9 @@ export const Results: FC<ResultsProps> = ({
|
||||
onSelect={() => {
|
||||
onClose();
|
||||
assertExists(blockSuiteWorkspace.id);
|
||||
jumpToPage(blockSuiteWorkspace.id, result.id);
|
||||
jumpToPage(blockSuiteWorkspace.id, result.id).catch(error =>
|
||||
console.error(error)
|
||||
);
|
||||
}}
|
||||
value={result.id}
|
||||
>
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import type { BlobManager } from '@blocksuite/store';
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
|
||||
import type { BlockSuiteWorkspace } from '../shared';
|
||||
|
||||
const logger = new DebugLogger('useWorkspaceBlob');
|
||||
|
||||
export function useWorkspaceBlob(
|
||||
blockSuiteWorkspace: BlockSuiteWorkspace
|
||||
): BlobManager {
|
||||
@@ -21,14 +24,19 @@ export function useWorkspaceBlobImage(
|
||||
setBlob(null);
|
||||
return;
|
||||
}
|
||||
blobManager?.get(key).then(blob => {
|
||||
if (controller.signal.aborted) {
|
||||
return;
|
||||
}
|
||||
if (blob) {
|
||||
setBlob(blob);
|
||||
}
|
||||
});
|
||||
blobManager
|
||||
?.get(key)
|
||||
.then(blob => {
|
||||
if (controller.signal.aborted) {
|
||||
return;
|
||||
}
|
||||
if (blob) {
|
||||
setBlob(blob);
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
logger.error('Failed to get blob', err);
|
||||
});
|
||||
return () => {
|
||||
controller.abort();
|
||||
};
|
||||
|
||||
@@ -204,7 +204,9 @@ export const WorkspaceLayout: FC<PropsWithChildren> =
|
||||
useEffect(() => {
|
||||
document.documentElement.lang = i18n.language;
|
||||
// todo(himself65): this is a hack, we should use a better way to set the language
|
||||
setUpLanguage(i18n);
|
||||
setUpLanguage(i18n)?.catch(error => {
|
||||
console.error(error);
|
||||
});
|
||||
}, [i18n]);
|
||||
useTrackRouterHistoryEffect();
|
||||
const currentWorkspaceId = useAtomValue(rootCurrentWorkspaceIdAtom);
|
||||
@@ -247,7 +249,9 @@ export const WorkspaceLayout: FC<PropsWithChildren> =
|
||||
logger.info('mount first data:', items);
|
||||
}
|
||||
|
||||
fetch();
|
||||
fetch().catch(e => {
|
||||
logger.error('fetch error:', e);
|
||||
});
|
||||
return () => {
|
||||
controller.abort();
|
||||
logger.info('unmount');
|
||||
|
||||
@@ -34,7 +34,7 @@ export const NotfoundPage = () => {
|
||||
<Button
|
||||
shape="round"
|
||||
onClick={() => {
|
||||
router.push('/');
|
||||
router.push('/').catch(err => console.error(err));
|
||||
}}
|
||||
>
|
||||
{t['Back Home']()}
|
||||
|
||||
@@ -44,7 +44,7 @@ const InvitePage: NextPageWithLayout = () => {
|
||||
inviteData.workspace_id,
|
||||
WorkspaceSubPath.ALL,
|
||||
RouteLogic.REPLACE
|
||||
);
|
||||
).catch(err => console.error(err));
|
||||
}}
|
||||
>
|
||||
Go to Workspace
|
||||
@@ -64,7 +64,7 @@ const InvitePage: NextPageWithLayout = () => {
|
||||
<Button
|
||||
shape="round"
|
||||
onClick={() => {
|
||||
router.replace(`/`);
|
||||
router.replace(`/`).catch(err => console.error(err));
|
||||
}}
|
||||
>
|
||||
Back to Home
|
||||
|
||||
@@ -26,7 +26,7 @@ const AllPage: NextPageWithLayout = () => {
|
||||
if (newTab) {
|
||||
window.open(`/workspace/${currentWorkspace?.id}/${pageId}`, '_blank');
|
||||
} else {
|
||||
jumpToPage(currentWorkspace.id, pageId);
|
||||
jumpToPage(currentWorkspace.id, pageId).catch(console.error);
|
||||
}
|
||||
},
|
||||
[currentWorkspace, jumpToPage]
|
||||
|
||||
@@ -23,7 +23,7 @@ const SharedPages: NextPageWithLayout = () => {
|
||||
if (newTab) {
|
||||
window.open(`/workspace/${currentWorkspace?.id}/${pageId}`, '_blank');
|
||||
} else {
|
||||
jumpToPage(currentWorkspace.id, pageId);
|
||||
jumpToPage(currentWorkspace.id, pageId).catch(console.error);
|
||||
}
|
||||
},
|
||||
[currentWorkspace, jumpToPage]
|
||||
|
||||
@@ -24,7 +24,9 @@ const TrashPage: NextPageWithLayout = () => {
|
||||
if (newTab) {
|
||||
window.open(`/workspace/${currentWorkspace?.id}/${pageId}`, '_blank');
|
||||
} else {
|
||||
jumpToPage(currentWorkspace.id, pageId);
|
||||
jumpToPage(currentWorkspace.id, pageId).catch(error => {
|
||||
console.error(error);
|
||||
});
|
||||
}
|
||||
},
|
||||
[currentWorkspace, jumpToPage]
|
||||
|
||||
@@ -129,7 +129,9 @@ export const AllWorkspaceModals = (): ReactElement => {
|
||||
workspace => {
|
||||
setOpenWorkspacesModal(false);
|
||||
setCurrentWorkspaceId(workspace.id);
|
||||
jumpToSubPath(workspace.id, WorkspaceSubPath.ALL);
|
||||
jumpToSubPath(workspace.id, WorkspaceSubPath.ALL).catch(error => {
|
||||
console.error(error);
|
||||
});
|
||||
},
|
||||
[jumpToSubPath, setCurrentWorkspaceId, setOpenWorkspacesModal]
|
||||
)}
|
||||
@@ -137,7 +139,11 @@ export const AllWorkspaceModals = (): ReactElement => {
|
||||
workspace => {
|
||||
setOpenWorkspacesModal(false);
|
||||
setCurrentWorkspaceId(workspace.id);
|
||||
jumpToSubPath(workspace.id, WorkspaceSubPath.SETTING);
|
||||
jumpToSubPath(workspace.id, WorkspaceSubPath.SETTING).catch(
|
||||
error => {
|
||||
console.error(error);
|
||||
}
|
||||
);
|
||||
},
|
||||
[jumpToSubPath, setCurrentWorkspaceId, setOpenWorkspacesModal]
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user