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

close AF-2306
This commit is contained in:
CatsJuice
2025-03-20 23:20:58 +00:00
parent e37328c83b
commit fbcb313de8
3 changed files with 30 additions and 5 deletions

View File

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

View File

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

View File

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