From b2cd43136f284af0adc3ad41d8b40f1cd393cebe Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Sun, 24 Mar 2024 10:42:29 +0800 Subject: [PATCH] hide webhooks page --- packages/api/package.json | 4 +- packages/api/src/services/highlights.ts | 4 + .../api/src/services/integrations/notion.ts | 87 +++++++++-------- .../api/src/services/integrations/readwise.ts | 5 +- packages/api/src/services/library_item.ts | 3 + packages/web/pages/settings/integrations.tsx | 93 +++++++++++-------- .../pages/settings/integrations/notion.tsx | 39 ++++---- 7 files changed, 126 insertions(+), 109 deletions(-) diff --git a/packages/api/package.json b/packages/api/package.json index 3b694314d..c3ec7bd1b 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -4,8 +4,8 @@ "license": "UNLICENSED", "scripts": { "build": "tsc", - "dev": "ts-node-dev --debounce 100 --respawn --transpile-only src/server.ts", - "dev_qp": "ts-node-dev --debounce 100 --respawn --transpile-only src/queue-processor.ts", + "dev": "ts-node-dev --respawn --transpile-only src/server.ts", + "dev_qp": "ts-node-dev --respawn --transpile-only src/queue-processor.ts", "start": "node dist/src/server.js", "start_queue_processor": "node dist/src/queue-processor.js", "lint": "eslint src --ext ts,js,tsx,jsx", diff --git a/packages/api/src/services/highlights.ts b/packages/api/src/services/highlights.ts index b774b8e5d..531ba640e 100644 --- a/packages/api/src/services/highlights.ts +++ b/packages/api/src/services/highlights.ts @@ -165,6 +165,10 @@ export const updateHighlight = async ( EntityType.HIGHLIGHT, { id: libraryItemId, + originalUrl: updatedHighlight.libraryItem.originalUrl, + title: updatedHighlight.libraryItem.title, + author: updatedHighlight.libraryItem.author, + thumbnail: updatedHighlight.libraryItem.thumbnail, highlights: [ { ...highlight, diff --git a/packages/api/src/services/integrations/notion.ts b/packages/api/src/services/integrations/notion.ts index 9fbb6fe5a..150ec881e 100644 --- a/packages/api/src/services/integrations/notion.ts +++ b/packages/api/src/services/integrations/notion.ts @@ -6,7 +6,7 @@ import { env } from '../../env' import { Merge } from '../../util' import { logger } from '../../utils/logger' import { getHighlightUrl } from '../highlights' -import { ItemEvent } from '../library_item' +import { getItemUrl, ItemEvent } from '../library_item' import { IntegrationClient } from './integration' type AnnotationColor = @@ -229,7 +229,7 @@ export class NotionClient implements IntegrationClient { } : undefined, 'Omnivore URL': { - url: `${env.client.url}/me/${item.id}`, + url: getItemUrl(item.id), }, 'Saved At': item.savedAt ? { @@ -253,52 +253,51 @@ export class NotionClient implements IntegrationClient { } : undefined, }, - children: - settings.properties?.includes('highlights') && item.highlights - ? item.highlights - .filter( - (highlight) => - highlight.highlightType === HighlightType.Highlight && - (!lastSync || - new Date(highlight.updatedAt as string) > lastSync) // only new highlights - ) - .map((highlight) => ({ - paragraph: { - rich_text: [ - { - text: { - content: highlight.quote || '', - link: { - url: getHighlightUrl( - item.slug || item.id, - highlight.id - ), - }, - }, - annotations: { - code: true, - color: highlight.color as AnnotationColor, + children: item.highlights + ? item.highlights + .filter( + (highlight) => + highlight.highlightType === HighlightType.Highlight && + (!lastSync || + new Date(highlight.updatedAt as string) > lastSync) // only new highlights + ) + .map((highlight) => ({ + paragraph: { + rich_text: [ + { + text: { + content: highlight.quote || '', + link: { + url: getHighlightUrl( + item.slug || item.id, + highlight.id + ), }, }, - ], - children: highlight.annotation - ? [ - { - paragraph: { - rich_text: [ - { - text: { - content: highlight.annotation || '', - }, + annotations: { + code: true, + color: highlight.color as AnnotationColor, + }, + }, + ], + children: highlight.annotation + ? [ + { + paragraph: { + rich_text: [ + { + text: { + content: highlight.annotation || '', }, - ], - }, + }, + ], }, - ] - : undefined, - }, - })) - : undefined, + }, + ] + : undefined, + }, + })) + : undefined, } } diff --git a/packages/api/src/services/integrations/readwise.ts b/packages/api/src/services/integrations/readwise.ts index c43e28774..2a6ea2fd7 100644 --- a/packages/api/src/services/integrations/readwise.ts +++ b/packages/api/src/services/integrations/readwise.ts @@ -2,7 +2,7 @@ import axios from 'axios' import { HighlightType } from '../../entity/highlight' import { logger } from '../../utils/logger' import { getHighlightUrl } from '../highlights' -import { ItemEvent } from '../library_item' +import { getItemUrl, ItemEvent } from '../library_item' import { IntegrationClient } from './integration' interface ReadwiseHighlight { @@ -71,7 +71,6 @@ export class ReadwiseClient implements IntegrationClient { let result = true const highlights = items.flatMap(this._itemToReadwiseHighlight) - logger.info(`Exporting ${highlights.length} highlights to Readwise`) // If there are no highlights, we will skip the sync if (highlights.length > 0) { @@ -108,7 +107,7 @@ export class ReadwiseClient implements IntegrationClient { location_type: 'order', note: highlight.annotation || undefined, source_type: 'omnivore', - source_url: item.originalUrl, + source_url: getItemUrl(item.id), } }) : [] diff --git a/packages/api/src/services/library_item.ts b/packages/api/src/services/library_item.ts index 4169ddc76..a65961f74 100644 --- a/packages/api/src/services/library_item.ts +++ b/packages/api/src/services/library_item.ts @@ -14,6 +14,7 @@ import { EntityLabel } from '../entity/entity_label' import { Highlight } from '../entity/highlight' import { Label } from '../entity/label' import { LibraryItem, LibraryItemState } from '../entity/library_item' +import { env } from '../env' import { BulkActionType, InputMaybe, SortParams } from '../generated/graphql' import { createPubSubClient, EntityEvent, EntityType } from '../pubsub' import { redisDataSource } from '../redis_data_source' @@ -138,6 +139,8 @@ interface Select { const readingProgressDataSource = new ReadingProgressDataSource() +export const getItemUrl = (id: string) => `${env.client.url}/me/${id}` + const markItemAsRead = async (libraryItemId: string, userId: string) => { return await readingProgressDataSource.updateReadingProgress( userId, diff --git a/packages/web/pages/settings/integrations.tsx b/packages/web/pages/settings/integrations.tsx index 409f02ad3..57e3e6219 100644 --- a/packages/web/pages/settings/integrations.tsx +++ b/packages/web/pages/settings/integrations.tsx @@ -1,8 +1,8 @@ import { styled } from '@stitches/react' import Image from 'next/image' import { useRouter } from 'next/router' -import { DownloadSimple, Eye, Link, Spinner } from 'phosphor-react' -import { useEffect, useMemo, useState } from 'react' +import { DownloadSimple, Link, Spinner } from 'phosphor-react' +import { useCallback, useEffect, useMemo, useState } from 'react' import { Toaster } from 'react-hot-toast' import { Button } from '../../components/elements/Button' import { @@ -29,7 +29,6 @@ import { useGetIntegrationsQuery, } from '../../lib/networking/queries/useGetIntegrationsQuery' import { useGetViewerQuery } from '../../lib/networking/queries/useGetViewerQuery' -import { useGetWebhooksQuery } from '../../lib/networking/queries/useGetWebhooksQuery' import { showErrorToast, showSuccessToast } from '../../lib/toastHelpers' // Styles const Header = styled(Box, { @@ -78,7 +77,7 @@ export default function Integrations(): JSX.Element { const { viewerData } = useGetViewerQuery() const { integrations, revalidate } = useGetIntegrationsQuery() - const { webhooks } = useGetWebhooksQuery() + // const { webhooks } = useGetWebhooksQuery() const [integrationsArray, setIntegrationsArray] = useState( Array() @@ -91,29 +90,38 @@ export default function Integrations(): JSX.Element { const pocketConnected = useMemo(() => { return integrations.find((i) => i.name == 'POCKET' && i.type == 'IMPORT') }, [integrations]) - const isConnected = (name: string) => { - return integrations.find((i) => i.name == name)?.enabled - } + const isConnected = useCallback( + (name: string) => { + return integrations.find((i) => i.name == name)?.enabled + }, + [integrations] + ) - const deleteIntegration = async (id: string) => { - try { - await deleteIntegrationMutation(id) - revalidate() - showSuccessToast('Integration Removed') - } catch (err) { - showErrorToast('Error: ' + err) - } - } + const deleteIntegration = useCallback( + async (id: string) => { + try { + await deleteIntegrationMutation(id) + revalidate() + showSuccessToast('Integration Removed') + } catch (err) { + showErrorToast('Error: ' + err) + } + }, + [revalidate] + ) - const importFromIntegration = async (id: string) => { - try { - await importFromIntegrationMutation(id) - revalidate() - showSuccessToast('Import started') - } catch (err) { - showErrorToast('Error: ' + err) - } - } + const importFromIntegration = useCallback( + async (id: string) => { + try { + await importFromIntegrationMutation(id) + revalidate() + showSuccessToast('Import started') + } catch (err) { + showErrorToast('Error: ' + err) + } + }, + [revalidate] + ) const redirectToIntegration = ( name: string, @@ -178,7 +186,7 @@ export default function Integrations(): JSX.Element { token, name: 'NOTION', type: 'EXPORT', - enabled: false, + enabled: true, }) showSuccessToast('Connected with Notion.') @@ -201,7 +209,7 @@ export default function Integrations(): JSX.Element { if (router.query.code) { connectWithNotion() } - }, [router]) + }, [importFromIntegration, pocketConnected, revalidate, router]) useEffect(() => { const integrationsArray = [ @@ -269,17 +277,17 @@ export default function Integrations(): JSX.Element { ], }, }, - { - icon: '/static/icons/webhooks.svg', - title: 'Webhooks', - subText: `${webhooks.length} Webhooks`, - button: { - text: 'View Webhooks', - icon: , - style: 'ctaWhite', - action: () => router.push('/settings/webhooks'), - }, - }, + // { + // icon: '/static/icons/webhooks.svg', + // title: 'Webhooks', + // subText: `${webhooks.length} Webhooks`, + // button: { + // text: 'View Webhooks', + // icon: , + // style: 'ctaWhite', + // action: () => router.push('/settings/webhooks'), + // }, + // }, { icon: '/static/icons/readwise.svg', title: 'Readwise', @@ -317,7 +325,14 @@ export default function Integrations(): JSX.Element { }) setIntegrationsArray(integrationsArray) - }, [pocketConnected, readwiseConnected, webhooks, integrations]) + }, [ + pocketConnected, + readwiseConnected, + integrations, + isConnected, + router, + deleteIntegration, + ]) return ( diff --git a/packages/web/pages/settings/integrations/notion.tsx b/packages/web/pages/settings/integrations/notion.tsx index 6a402deaa..769758c21 100644 --- a/packages/web/pages/settings/integrations/notion.tsx +++ b/packages/web/pages/settings/integrations/notion.tsx @@ -1,15 +1,5 @@ -import { - Button, - Checkbox, - Form, - FormProps, - Input, - message, - Space, - Spin, -} from 'antd' +import { Button, Form, FormProps, Input, message, Space, Spin } from 'antd' import 'antd/dist/antd.compact.css' -import { CheckboxValueType } from 'antd/lib/checkbox/Group' import Image from 'next/image' import { useRouter } from 'next/router' import { useCallback, useEffect, useState } from 'react' @@ -109,9 +99,9 @@ export default function Notion(): JSX.Element { console.log('Failed:', errorInfo) } - const onDataChange = (value: Array) => { - form.setFieldsValue({ properties: value.map((v) => v.toString()) }) - } + // const onDataChange = (value: Array) => { + // form.setFieldsValue({ properties: value.map((v) => v.toString()) }) + // } const exportToNotion = useCallback(async () => { if (exporting) { @@ -119,6 +109,11 @@ export default function Notion(): JSX.Element { return } + if (!notion.settings?.parentPageId) { + messageApi.error('Please set the Notion page id first.') + return + } + try { const task = await exportToIntegrationMutation(notion.id) // long polling to check the status of the task in every 10 seconds @@ -142,7 +137,7 @@ export default function Notion(): JSX.Element { } catch (error) { messageApi.error('There was an error exporting to Notion.') } - }, [exporting, messageApi, notion.id]) + }, [exporting, messageApi, notion]) return ( <> @@ -222,15 +217,17 @@ export default function Notion(): JSX.Element { - label="Properties to Export" - name="properties" + label="Notion Database Id" + name="parentDatabaseId" + hidden > - - Highlights - + - +