mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
hide webhooks page
This commit is contained in:
parent
0fab3c7904
commit
b2cd43136f
7 changed files with 126 additions and 109 deletions
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
}
|
||||
})
|
||||
: []
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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<integrationsCard>()
|
||||
|
|
@ -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: <Eye size={16} weight={'bold'} />,
|
||||
style: 'ctaWhite',
|
||||
action: () => router.push('/settings/webhooks'),
|
||||
},
|
||||
},
|
||||
// {
|
||||
// icon: '/static/icons/webhooks.svg',
|
||||
// title: 'Webhooks',
|
||||
// subText: `${webhooks.length} Webhooks`,
|
||||
// button: {
|
||||
// text: 'View Webhooks',
|
||||
// icon: <Eye size={16} weight={'bold'} />,
|
||||
// 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 (
|
||||
<SettingsLayout>
|
||||
|
|
|
|||
|
|
@ -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<CheckboxValueType>) => {
|
||||
form.setFieldsValue({ properties: value.map((v) => v.toString()) })
|
||||
}
|
||||
// const onDataChange = (value: Array<CheckboxValueType>) => {
|
||||
// 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 {
|
|||
</Form.Item>
|
||||
|
||||
<Form.Item<FieldType>
|
||||
label="Properties to Export"
|
||||
name="properties"
|
||||
label="Notion Database Id"
|
||||
name="parentDatabaseId"
|
||||
hidden
|
||||
>
|
||||
<Checkbox.Group onChange={onDataChange}>
|
||||
<Checkbox value="highlights">Highlights</Checkbox>
|
||||
</Checkbox.Group>
|
||||
<Input disabled />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item>
|
||||
<Form.Item
|
||||
wrapperCol={{ offset: 6 }}
|
||||
style={{ marginTop: '30px' }}
|
||||
>
|
||||
<Space>
|
||||
<Button type="primary" htmlType="submit">
|
||||
Save
|
||||
|
|
|
|||
Loading…
Reference in a new issue