41 lines
961 B
TypeScript
41 lines
961 B
TypeScript
import { gql } from 'graphql-request'
|
|
import { gqlFetcher } from '../networkHelpers'
|
|
|
|
export type ArticleReadingProgressMutationInput = {
|
|
id: string
|
|
force?: boolean
|
|
readingProgressPercent?: number
|
|
readingProgressTopPercent?: number
|
|
readingProgressAnchorIndex?: number
|
|
}
|
|
|
|
export async function articleReadingProgressMutation(
|
|
input: ArticleReadingProgressMutationInput
|
|
): Promise<boolean> {
|
|
const mutation = gql`
|
|
mutation SaveArticleReadingProgress(
|
|
$input: SaveArticleReadingProgressInput!
|
|
) {
|
|
saveArticleReadingProgress(input: $input) {
|
|
... on SaveArticleReadingProgressSuccess {
|
|
updatedArticle {
|
|
id
|
|
readingProgressPercent
|
|
readingProgressAnchorIndex
|
|
}
|
|
}
|
|
... on SaveArticleReadingProgressError {
|
|
errorCodes
|
|
}
|
|
}
|
|
}
|
|
`
|
|
|
|
try {
|
|
await gqlFetcher(mutation, { input })
|
|
return true
|
|
} catch {
|
|
return false
|
|
}
|
|
}
|