From 8cf0a6ecb27f63477babe20d129848bd76708ad4 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Fri, 10 Mar 2023 16:47:02 +0800 Subject: [PATCH] Simplify top positioning --- .../components/templates/article/Article.tsx | 4 + .../templates/article/ArticleContainer.tsx | 1 + .../lib/hooks/useReadingProgressAnchor.tsx | 85 ++----------------- .../networking/fragments/articleFragment.ts | 2 + .../web/lib/networking/queries/search.tsx | 7 +- .../networking/queries/useGetArticleQuery.tsx | 1 + .../queries/useGetLibraryItemsQuery.tsx | 1 + 7 files changed, 20 insertions(+), 81 deletions(-) diff --git a/packages/web/components/templates/article/Article.tsx b/packages/web/components/templates/article/Article.tsx index e54402b18..5e672dc39 100644 --- a/packages/web/components/templates/article/Article.tsx +++ b/packages/web/components/templates/article/Article.tsx @@ -1,6 +1,7 @@ import { Box } from '../../elements/LayoutPrimitives' import { getTopOmnivoreAnchorElement, + parseDomTree, useReadingProgressAnchor, } from '../../../lib/hooks/useReadingProgressAnchor' import { @@ -18,6 +19,7 @@ export type ArticleProps = { content: string initialAnchorIndex: number initialReadingProgress?: number + initialReadingProgressTop?: number highlightHref: MutableRefObject articleMutations: ArticleMutations } @@ -93,6 +95,8 @@ export function Article(props: ArticleProps): JSX.Element { setShouldScrollToInitialPosition(false) + parseDomTree(articleContentRef.current) + // If we are scrolling to a highlight, dont scroll to read position if (props.highlightHref.current) { return diff --git a/packages/web/components/templates/article/ArticleContainer.tsx b/packages/web/components/templates/article/ArticleContainer.tsx index ee10a0f34..d4e425542 100644 --- a/packages/web/components/templates/article/ArticleContainer.tsx +++ b/packages/web/components/templates/article/ArticleContainer.tsx @@ -366,6 +366,7 @@ export function ArticleContainer(props: ArticleContainerProps): JSX.Element { content={props.article.content} highlightHref={highlightHref} initialAnchorIndex={props.article.readingProgressAnchorIndex} + initialReadingProgressTop={props.article.readingProgressTopPercent} articleMutations={props.articleMutations} />