Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

feat(core): delete all readwise highlights when disconnect (#10975)

CatsJuicefbcb313de8c4
diff --git a/packages/frontend/core/src/desktop/dialogs/setting/workspace-setting/integration/readwise/connected.tsx b/packages/frontend/core/src/desktop/dialogs/setting/workspace-setting/integration/readwise/connected.tsx
index bf223bdaf6..3af093653e 100644
--- a/packages/frontend/core/src/desktop/dialogs/setting/workspace-setting/integration/readwise/connected.tsx
+++ b/packages/frontend/core/src/desktop/dialogs/setting/workspace-setting/integration/readwise/connected.tsx
@@ -1,4 +1,5 @@
import { Button, Modal } from '@affine/component';
+import { useAsyncCallback } from '@affine/core/components/hooks/affine-async-hooks';
import { IntegrationService } from '@affine/core/modules/integration';
import { useI18n } from '@affine/i18n';
import { useService } from '@toeverything/infra';
@@ -22,9 +23,11 @@ export const DisconnectDialog = ({ onClose }: { onClose: () => void }) => {
readwise.disconnect();
onClose();
}, [onClose, readwise]);
- // const handleDelete = useAsyncCallback(async () => {
- // // TODO
- // }, []);
+ const handleDelete = useAsyncCallback(async () => {
+ await readwise.deleteAll();
+ readwise.disconnect();
+ onClose();
+ }, [onClose, readwise]);
return (
<Modal
@@ -41,7 +44,7 @@ export const DisconnectDialog = ({ onClose }: { onClose: () => void }) => {
<footer className={styles.footer}>
<Button onClick={handleCancel}>{t['Cancel']()}</Button>
<div className={styles.actions}>
- <Button variant="error">
+ <Button variant="error" onClick={handleDelete}>
{t['com.affine.integration.readwise.disconnect.delete']()}
</Button>
<Button variant="primary" onClick={handleKeep}>
diff --git a/packages/frontend/core/src/desktop/dialogs/setting/workspace-setting/integration/readwise/import-dialog.tsx b/packages/frontend/core/src/desktop/dialogs/setting/workspace-setting/integration/readwise/import-dialog.tsx
index ee21e42896..4e916188f2 100644
--- a/packages/frontend/core/src/desktop/dialogs/setting/workspace-setting/integration/readwise/import-dialog.tsx
+++ b/packages/frontend/core/src/desktop/dialogs/setting/workspace-setting/integration/readwise/import-dialog.tsx
@@ -103,6 +103,7 @@ export const ImportDialog = ({ onClose }: { onClose: () => void }) => {
}, []);
const handleRetryCrawl = useCallback(() => {
+ crawler.abort();
crawler.crawl();
}, [crawler]);
@@ -144,6 +145,7 @@ export const ImportDialog = ({ onClose }: { onClose: () => void }) => {
highlights={highlights}
onClose={onClose}
onConfirm={handleConfirmImport}
+ onResetLastImportedAt={handleRetryCrawl}
/>
)
) : (
@@ -167,11 +169,13 @@ const SelectStage = ({
highlights,
onClose,
onConfirm,
+ onResetLastImportedAt,
}: {
loading: boolean;
highlights: ReadwiseHighlight[];
onClose: () => void;
onConfirm: (ids: ReadwiseHighlight['id'][]) => void;
+ onResetLastImportedAt: () => void;
}) => {
const t = useI18n();
const readwise = useService(IntegrationService).readwise;
@@ -181,7 +185,8 @@ const SelectStage = ({
const handleResetLastImportedAt = useCallback(() => {
readwise.updateSetting('lastImportedAt', undefined);
- }, [readwise]);
+ onResetLastImportedAt();
+ }, [onResetLastImportedAt, readwise]);
const handleConfirmImport = useCallback(() => {
onConfirm(selected);
diff --git a/packages/frontend/core/src/modules/integration/entities/readwise.ts b/packages/frontend/core/src/modules/integration/entities/readwise.ts
index b60a2693a2..ba6825397b 100644
--- a/packages/frontend/core/src/modules/integration/entities/readwise.ts
+++ b/packages/frontend/core/src/modules/integration/entities/readwise.ts
@@ -224,6 +224,23 @@ export class ReadwiseIntegration extends Entity<{ writer: IntegrationWriter }> {
token: undefined,
updateStrategy: undefined,
syncNewHighlights: undefined,
+ lastImportedAt: undefined,
});
}
+
+ /**
+ * Delete all highlights of current user in current workspace
+ */
+ async deleteAll() {
+ const refs = await this.getRefs();
+ await Promise.all(
+ refs.map(ref => {
+ const doc = this.docsService.list.doc$(ref.id).value;
+ if (doc) {
+ doc.moveToTrash();
+ }
+ return this.integrationRefStore.deleteRef(ref.id);
+ })
+ );
+ }
}