Skip to content

Commit

Permalink
Merge pull request #95 from omnivore-app/highlights-title
Browse files Browse the repository at this point in the history
fix: add a title block for highlights and add note as a variable in the highlight template
  • Loading branch information
sywhb authored May 11, 2023
2 parents f8c89c8 + 33b37ca commit 670e83b
Show file tree
Hide file tree
Showing 5 changed files with 474 additions and 197 deletions.
32 changes: 19 additions & 13 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export enum UpdateReason {
export interface UpdatesSinceResponse {
data: {
updatesSince: {
edges: { updateReason: UpdateReason; node: { slug: string } }[]
edges: { updateReason: UpdateReason; node: Article }[]
pageInfo: {
hasNextPage: boolean
}
Expand All @@ -33,10 +33,13 @@ export enum PageType {
Profile = 'PROFILE',
Unknown = 'UNKNOWN',
Website = 'WEBSITE',
Highlights = 'HIGHLIGHTS',
Tweet = 'TWEET',
Video = 'VIDEO',
Image = 'IMAGE',
}

export interface Article {
id: string
title: string
siteName?: string
originalArticleUrl: string
Expand All @@ -51,6 +54,9 @@ export interface Article {
content: string
publishedAt?: string
readAt?: string
readingProgressPercent: number
isArchived: boolean
wordsCount?: number
}

export interface Label {
Expand All @@ -74,13 +80,6 @@ export interface Highlight {
highlightPositionPercent?: number
}

export interface DeletedArticle {
updateReason: UpdateReason
node: {
slug: string
}
}

const ENDPOINT = 'https://api-prod.omnivore.app/api/graphql'
const requestHeaders = (apiKey: string) => ({
'Content-Type': 'application/json',
Expand All @@ -107,6 +106,7 @@ export const getOmnivoreArticles = async (
... on SearchSuccess {
edges {
node {
id
title
slug
siteName
Expand Down Expand Up @@ -135,6 +135,9 @@ export const getOmnivoreArticles = async (
labels {
name
}
isArchived
readingProgressPercent
wordsCount
}
}
pageInfo {
Expand Down Expand Up @@ -171,7 +174,7 @@ export const getDeletedOmnivoreArticles = async (
first = 10,
updatedAt = '',
endpoint = ENDPOINT
): Promise<[DeletedArticle[], boolean]> => {
): Promise<[Article[], boolean]> => {
const res = await fetch(endpoint, {
headers: requestHeaders(apiKey),
body: JSON.stringify({
Expand All @@ -182,7 +185,10 @@ export const getDeletedOmnivoreArticles = async (
edges {
updateReason
node {
id
slug
title
savedAt
}
}
pageInfo {
Expand All @@ -204,9 +210,9 @@ export const getDeletedOmnivoreArticles = async (
})

const jsonRes = (await res.json()) as UpdatesSinceResponse
const deletedArticles = jsonRes.data.updatesSince.edges.filter(
(edge) => edge.updateReason === UpdateReason.DELETED
)
const deletedArticles = jsonRes.data.updatesSince.edges
.filter((edge) => edge.updateReason === UpdateReason.DELETED)
.map((edge) => edge.node)

return [deletedArticles, jsonRes.data.updatesSince.pageInfo.hasNextPage]
}
Loading

0 comments on commit 670e83b

Please sign in to comment.