From 67bf5003ea3671d34184e846ed1702bf80157c18 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Mon, 29 Jul 2024 21:27:49 +0800 Subject: [PATCH] Move reading progress to new system --- .../templates/article/EpubContainer.tsx | 1 - .../templates/article/PdfArticleContainer.tsx | 9 +- .../templates/navMenu/LibraryMenu.tsx | 2 - .../articleReadingProgressMutation.ts | 56 ++++----- .../web/pages/app/[username]/[slug]/index.tsx | 109 ------------------ .../app/[username]/link-request/[id].tsx | 90 --------------- packages/web/pages/app/privacy.tsx | 7 -- packages/web/pages/app/terms.tsx | 7 -- 8 files changed, 34 insertions(+), 247 deletions(-) delete mode 100644 packages/web/pages/app/[username]/[slug]/index.tsx delete mode 100644 packages/web/pages/app/[username]/link-request/[id].tsx delete mode 100644 packages/web/pages/app/privacy.tsx delete mode 100644 packages/web/pages/app/terms.tsx diff --git a/packages/web/components/templates/article/EpubContainer.tsx b/packages/web/components/templates/article/EpubContainer.tsx index ebf2558d8..8990bf558 100644 --- a/packages/web/components/templates/article/EpubContainer.tsx +++ b/packages/web/components/templates/article/EpubContainer.tsx @@ -13,7 +13,6 @@ import { Instance, HighlightAnnotation, List, Annotation, Rect } from 'pspdfkit' import type { Highlight } from '../../../lib/networking/fragments/highlightFragment' import { createHighlightMutation } from '../../../lib/networking/mutations/createHighlightMutation' import { deleteHighlightMutation } from '../../../lib/networking/mutations/deleteHighlightMutation' -import { articleReadingProgressMutation } from '../../../lib/networking/mutations/articleReadingProgressMutation' import { mergeHighlightMutation } from '../../../lib/networking/mutations/mergeHighlightMutation' import { useCanShareNative } from '../../../lib/hooks/useCanShareNative' import { pspdfKitKey } from '../../../lib/appConfig' diff --git a/packages/web/components/templates/article/PdfArticleContainer.tsx b/packages/web/components/templates/article/PdfArticleContainer.tsx index cbe7bf84b..c1c69c80e 100644 --- a/packages/web/components/templates/article/PdfArticleContainer.tsx +++ b/packages/web/components/templates/article/PdfArticleContainer.tsx @@ -1,4 +1,7 @@ -import { ArticleAttributes } from '../../../lib/networking/library_items/useLibraryItems' +import { + ArticleAttributes, + useUpdateItemReadStatus, +} from '../../../lib/networking/library_items/useLibraryItems' import { Box } from '../../elements/LayoutPrimitives' import { v4 as uuidv4 } from 'uuid' import { nanoid } from 'nanoid' @@ -9,7 +12,6 @@ import { Instance, HighlightAnnotation, List, Annotation, Rect } from 'pspdfkit' import type { Highlight } from '../../../lib/networking/fragments/highlightFragment' import { createHighlightMutation } from '../../../lib/networking/mutations/createHighlightMutation' import { deleteHighlightMutation } from '../../../lib/networking/mutations/deleteHighlightMutation' -import { articleReadingProgressMutation } from '../../../lib/networking/mutations/articleReadingProgressMutation' import { mergeHighlightMutation } from '../../../lib/networking/mutations/mergeHighlightMutation' import { pspdfKitKey } from '../../../lib/appConfig' import { HighlightNoteModal } from './HighlightNoteModal' @@ -40,6 +42,7 @@ export default function PdfArticleContainer( number | undefined >(undefined) const highlightsRef = useRef([]) + const updateItemReadStatus = useUpdateItemReadStatus() const annotationOmnivoreId = (annotation: Annotation): string | undefined => { if ( @@ -411,7 +414,7 @@ export default function PdfArticleContainer( 100, Math.max(0, ((pageIndex + 1) / instance.totalPageCount) * 100) ) - await articleReadingProgressMutation({ + await updateItemReadStatus.mutateAsync({ id: props.article.id, force: true, readingProgressPercent: percent, diff --git a/packages/web/components/templates/navMenu/LibraryMenu.tsx b/packages/web/components/templates/navMenu/LibraryMenu.tsx index 000507889..6e4849bba 100644 --- a/packages/web/components/templates/navMenu/LibraryMenu.tsx +++ b/packages/web/components/templates/navMenu/LibraryMenu.tsx @@ -185,8 +185,6 @@ const Shortcuts = (props: LibraryFilterMenuProps): JSX.Element => { initialValue: [], }) - console.log('got shortcuts: ', shortcuts) - // const shortcuts: Shortcut[] = [ // { // id: '12asdfasdf', diff --git a/packages/web/lib/networking/mutations/articleReadingProgressMutation.ts b/packages/web/lib/networking/mutations/articleReadingProgressMutation.ts index 95fd754d7..86a176f1e 100644 --- a/packages/web/lib/networking/mutations/articleReadingProgressMutation.ts +++ b/packages/web/lib/networking/mutations/articleReadingProgressMutation.ts @@ -9,32 +9,32 @@ export type ArticleReadingProgressMutationInput = { readingProgressAnchorIndex?: number } -export async function articleReadingProgressMutation( - input: ArticleReadingProgressMutationInput -): Promise { - const mutation = gql` - mutation SaveArticleReadingProgress( - $input: SaveArticleReadingProgressInput! - ) { - saveArticleReadingProgress(input: $input) { - ... on SaveArticleReadingProgressSuccess { - updatedArticle { - id - readingProgressPercent - readingProgressAnchorIndex - } - } - ... on SaveArticleReadingProgressError { - errorCodes - } - } - } - ` +// export async function articleReadingProgressMutation( +// input: ArticleReadingProgressMutationInput +// ): Promise { +// 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 - } -} +// try { +// await gqlFetcher(mutation, { input }) +// return true +// } catch { +// return false +// } +// } diff --git a/packages/web/pages/app/[username]/[slug]/index.tsx b/packages/web/pages/app/[username]/[slug]/index.tsx deleted file mode 100644 index 744b2a638..000000000 --- a/packages/web/pages/app/[username]/[slug]/index.tsx +++ /dev/null @@ -1,109 +0,0 @@ -import { useGetArticleQuery } from '../../../../lib/networking/queries/useGetArticleQuery' -import { Box, VStack } from './../../../../components/elements/LayoutPrimitives' -import { ArticleContainer } from './../../../../components/templates/article/ArticleContainer' -import { useState, useEffect } from 'react' -import { useRouter } from 'next/router' -import { LoadingView } from '../../../../components/patterns/LoadingView' -import { cookieValue } from '../../../../lib/cookieHelpers' -import { applyStoredTheme } from '../../../../lib/themeUpdater' -import { createHighlightMutation } from '../../../../lib/networking/mutations/createHighlightMutation' -import { deleteHighlightMutation } from '../../../../lib/networking/mutations/deleteHighlightMutation' -import { mergeHighlightMutation } from '../../../../lib/networking/mutations/mergeHighlightMutation' -import { updateHighlightMutation } from '../../../../lib/networking/mutations/updateHighlightMutation' -import { articleReadingProgressMutation } from '../../../../lib/networking/mutations/articleReadingProgressMutation' -import Script from 'next/script' -import { useGetViewerQuery } from '../../../../lib/networking/queries/useGetViewerQuery' - -type AppArticleEmbedContentProps = { - slug: string - username: string - highlightBarDisabled: boolean - fontSize: number - margin: number - fontFamily: string -} - -export default function AppArticleEmbed(): JSX.Element { - applyStoredTheme() - - const router = useRouter() - - const [contentProps, setContentProps] = - useState(undefined) - - useEffect(() => { - if (!router.isReady) return - const highlightBarDisabled = - (router.query.highlightBarDisabled as string | undefined) ?? '' - const articleProps = { - slug: router.query.slug as string, - username: router.query.username as string, - highlightBarDisabled: highlightBarDisabled == 'true', - fontSize: Number(cookieValue('fontSize', document.cookie) ?? '16'), - margin: Number(cookieValue('margin', document.cookie) ?? '0'), - fontFamily: cookieValue('fontFamily', document.cookie) ?? 'inter', - } - setContentProps(articleProps) - }, [ - router.isReady, - router.query.slug, - router.query.username, - router.query.highlightBarDisabled, - ]) - - if (contentProps) { - return - } - - return -} - -function AppArticleEmbedContent( - props: AppArticleEmbedContentProps -): JSX.Element { - const { viewerData } = useGetViewerQuery() - const [showHighlightsModal, setShowHighlightsModal] = useState(false) - - const { articleData } = useGetArticleQuery({ - username: props.username, - slug: props.slug, - includeFriendsHighlights: false, - }) - - if (articleData && viewerData?.me) { - return ( - -