diff --git a/packages/api/src/jobs/integration/export_all_items.ts b/packages/api/src/jobs/integration/export_all_items.ts index 930a4c8df..ad687d226 100644 --- a/packages/api/src/jobs/integration/export_all_items.ts +++ b/packages/api/src/jobs/integration/export_all_items.ts @@ -1,5 +1,5 @@ import { IntegrationType } from '../../entity/integration' -import { findIntegration } from '../../services/integrations' +import { findIntegration, updateIntegration } from '../../services/integrations' import { findRecentLibraryItems } from '../../services/library_item' import { findActiveUser } from '../../services/user' import { enqueueExportItem } from '../../utils/createTask' @@ -39,8 +39,8 @@ export const exportAllItems = async (jobData: ExportAllItemsJobData) => { return } - const maxItems = 1000 - const limit = 100 + const maxItems = 100 + const limit = 10 let offset = 0 // get max 1000 most recent items from the database while (offset < maxItems) { @@ -72,4 +72,12 @@ export const exportAllItems = async (jobData: ExportAllItemsJobData) => { integrationId, }) } + + logger.info('exported all items', { + userId, + integrationId, + }) + + // clear task name in integration + await updateIntegration(integration.id, { taskName: null }, userId) } diff --git a/packages/api/src/resolvers/integrations/index.ts b/packages/api/src/resolvers/integrations/index.ts index 1e3388517..fec1a9a82 100644 --- a/packages/api/src/resolvers/integrations/index.ts +++ b/packages/api/src/resolvers/integrations/index.ts @@ -93,6 +93,11 @@ export const setIntegrationResolver = authorized< // save integration const integration = await saveIntegration(integrationToSave, uid) + if (integration.name.toLowerCase() === 'readwise') { + // create a task to export all the items for readwise temporarily + await enqueueExportToIntegration(integration.id, uid) + } + analytics.capture({ distinctId: uid, event: 'integration_set', diff --git a/packages/web/pages/settings/integrations/notion.tsx b/packages/web/pages/settings/integrations/notion.tsx index eb8b56a3b..ba7dbe746 100644 --- a/packages/web/pages/settings/integrations/notion.tsx +++ b/packages/web/pages/settings/integrations/notion.tsx @@ -13,7 +13,7 @@ import 'antd/dist/antd.compact.css' import { CheckboxValueType } from 'antd/lib/checkbox/Group' import Image from 'next/image' import { useRouter } from 'next/router' -import { useEffect, useState } from 'react' +import { useCallback, useEffect, useState } from 'react' import { HStack, VStack } from '../../../components/elements/LayoutPrimitives' import { PageMetaData } from '../../../components/patterns/PageMetaData' import { Beta } from '../../../components/templates/Beta' @@ -46,7 +46,7 @@ export default function Notion(): JSX.Element { const [form] = Form.useForm() const [messageApi, contextHolder] = message.useMessage() - const [exporting, setExporting] = useState(false) + const [exporting, setExporting] = useState(!!notion.taskName) useEffect(() => { form.setFieldsValue({ @@ -97,7 +97,12 @@ export default function Notion(): JSX.Element { form.setFieldsValue({ properties: value.map((v) => v.toString()) }) } - const exportToNotion = async () => { + const exportToNotion = useCallback(async () => { + if (exporting) { + messageApi.warning('Exporting process is already running.') + return + } + try { const task = await exportToIntegrationMutation(notion.id) // long polling to check the status of the task in every 10 seconds @@ -121,7 +126,7 @@ export default function Notion(): JSX.Element { } catch (error) { messageApi.error('There was an error exporting to Notion.') } - } + }, [exporting, messageApi, notion.id]) return ( <> @@ -170,6 +175,7 @@ export default function Notion(): JSX.Element { label="Notion Page Id" name="parentPageId" + help="The id of the Notion page where the items will be exported to. You can find it in the URL of the page." rules={[ { required: true, @@ -192,6 +198,7 @@ export default function Notion(): JSX.Element { label="Automatic Sync" name="enabled" valuePropName="checked" + help="Once connected all new items will be exported to Notion" > @@ -222,7 +229,7 @@ export default function Notion(): JSX.Element { onClick={exportToNotion} disabled={exporting} > - {exporting ? 'Exporting' : 'Export most recent items to Notion'} + {exporting ? 'Exporting' : 'Export last 100 items'}