make readingProgress required in the elastic page data (#253)
* make readingProgress required in the elastic page data * delete readingProgress from function_resolvers because we have stored them in elastic
This commit is contained in:
@ -166,6 +166,7 @@ export const createPage = async (
|
||||
...page,
|
||||
updatedAt: new Date(),
|
||||
createdAt: new Date(),
|
||||
savedAt: new Date(),
|
||||
},
|
||||
refresh: ctx.refresh,
|
||||
})
|
||||
|
||||
@ -132,8 +132,8 @@ export interface Page {
|
||||
originalHtml?: string | null
|
||||
slug: string
|
||||
labels?: Label[]
|
||||
readingProgressPercent?: number
|
||||
readingProgressAnchorIndex?: number
|
||||
readingProgressPercent: number
|
||||
readingProgressAnchorIndex: number
|
||||
createdAt: Date
|
||||
updatedAt?: Date
|
||||
publishedAt?: Date
|
||||
|
||||
@ -272,6 +272,8 @@ export const createArticleResolver = authorized<
|
||||
createdAt: saveTime,
|
||||
savedAt: saveTime,
|
||||
siteName: parsedContent?.siteName,
|
||||
readingProgressPercent: 0,
|
||||
readingProgressAnchorIndex: 0,
|
||||
}
|
||||
|
||||
let archive = false
|
||||
|
||||
@ -386,47 +386,6 @@ export const functionResolvers = {
|
||||
? ContentReader.Pdf
|
||||
: ContentReader.Web
|
||||
},
|
||||
async readingProgressPercent(
|
||||
article: { id: string; readingProgressPercent?: number },
|
||||
_: unknown,
|
||||
ctx: WithDataSourcesContext & { claims: Claims }
|
||||
) {
|
||||
// != used here to check for null or undefined
|
||||
if (article.readingProgressPercent != null) {
|
||||
return article.readingProgressPercent
|
||||
}
|
||||
console.log(
|
||||
'looking up reading progress for article',
|
||||
article.id,
|
||||
article
|
||||
)
|
||||
return (
|
||||
(
|
||||
await getPageByParam({
|
||||
userId: ctx.claims.uid,
|
||||
_id: article.id,
|
||||
})
|
||||
)?.readingProgressPercent || 0
|
||||
)
|
||||
},
|
||||
async readingProgressAnchorIndex(
|
||||
article: { id: string; readingProgressAnchorIndex?: number },
|
||||
_: unknown,
|
||||
ctx: WithDataSourcesContext & { claims: Claims }
|
||||
) {
|
||||
// != used here to check for null or undefined
|
||||
if (article.readingProgressAnchorIndex != null) {
|
||||
return article.readingProgressAnchorIndex
|
||||
}
|
||||
return (
|
||||
(
|
||||
await getPageByParam({
|
||||
userId: ctx.claims.uid,
|
||||
_id: article.id,
|
||||
})
|
||||
)?.readingProgressAnchorIndex || 0
|
||||
)
|
||||
},
|
||||
async highlights(
|
||||
article: { id: string; userId?: string },
|
||||
_: { input: ArticleHighlightsInput },
|
||||
|
||||
@ -155,6 +155,8 @@ export function pdfAttachmentsRouter() {
|
||||
slug: generateSlug(title),
|
||||
id: '',
|
||||
createdAt: new Date(),
|
||||
readingProgressPercent: 0,
|
||||
readingProgressAnchorIndex: 0,
|
||||
}
|
||||
|
||||
const pageId = await createPage(articleToSave, {
|
||||
|
||||
@ -63,6 +63,8 @@ export const saveEmail = async (
|
||||
publishedAt: validatedDate(parseResult.parsedContent?.publishedDate),
|
||||
slug: slug,
|
||||
createdAt: new Date(),
|
||||
readingProgressAnchorIndex: 0,
|
||||
readingProgressPercent: 0,
|
||||
}
|
||||
|
||||
const page = await getPageByParam({ url: articleToSave.url })
|
||||
|
||||
@ -106,6 +106,8 @@ export const saveFile = async (
|
||||
userId: saver.id,
|
||||
id: '',
|
||||
createdAt: new Date(),
|
||||
readingProgressPercent: 0,
|
||||
readingProgressAnchorIndex: 0,
|
||||
},
|
||||
ctx
|
||||
)
|
||||
|
||||
@ -101,6 +101,8 @@ export const savePage = async (
|
||||
image: parseResult.parsedContent?.previewImage,
|
||||
publishedAt: validatedDate(parseResult.parsedContent?.publishedDate),
|
||||
createdAt: new Date(),
|
||||
readingProgressPercent: 0,
|
||||
readingProgressAnchorIndex: 0,
|
||||
}
|
||||
|
||||
const existingPage = await getPageByParam({
|
||||
|
||||
@ -571,6 +571,8 @@ describe('Article API', () => {
|
||||
createdAt: new Date(),
|
||||
url: 'https://blog.omnivore.app/setBookmarkArticle',
|
||||
slug: 'test-with-omnivore',
|
||||
readingProgressPercent: 0,
|
||||
readingProgressAnchorIndex: 0,
|
||||
}
|
||||
const newPageId = await createPage(page, ctx)
|
||||
if (newPageId) {
|
||||
|
||||
@ -50,6 +50,8 @@ export const createTestElasticPage = async (
|
||||
url: 'https://example.com/test-url',
|
||||
slug: 'test-with-omnivore',
|
||||
labels: labels,
|
||||
readingProgressPercent: 0,
|
||||
readingProgressAnchorIndex: 0,
|
||||
}
|
||||
|
||||
const pageId = await createPage(page, {
|
||||
|
||||
Reference in New Issue
Block a user