From cbdd40fe74c14f6347871ff4a0d65c282512711b Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Fri, 30 Aug 2024 13:01:12 +0800 Subject: [PATCH] Allow deleted articles to be read and restored from the article page --- packages/api/src/resolvers/article/index.ts | 2 +- .../templates/article/ArticleContainer.tsx | 71 ++++++++++++++++--- 2 files changed, 62 insertions(+), 11 deletions(-) diff --git a/packages/api/src/resolvers/article/index.ts b/packages/api/src/resolvers/article/index.ts index adde391a44..a2f6fb75f5 100644 --- a/packages/api/src/resolvers/article/index.ts +++ b/packages/api/src/resolvers/article/index.ts @@ -405,7 +405,7 @@ export const getArticleResolver = authorized< ? qb.andWhere('libraryItem.id = :id', { id: slug }) : qb.andWhere('libraryItem.slug = :slug', { slug }) - return qb.andWhere('libraryItem.deleted_at IS NULL').getOne() + return qb.getOne() }, { replicationMode: 'replica', diff --git a/packages/web/components/templates/article/ArticleContainer.tsx b/packages/web/components/templates/article/ArticleContainer.tsx index 5ceabb2b6e..d4c1bf6bc9 100644 --- a/packages/web/components/templates/article/ArticleContainer.tsx +++ b/packages/web/components/templates/article/ArticleContainer.tsx @@ -19,10 +19,13 @@ import { ArticleAttributes, Recommendation, TextDirection, + useRestoreItem, useUpdateItemReadStatus, } from '../../../lib/networking/library_items/useLibraryItems' import { Avatar } from '../../elements/Avatar' import { UserBasicData } from '../../../lib/networking/queries/useGetViewerQuery' +import { State } from '../../../lib/networking/fragments/articleFragment' +import { showErrorToast, showSuccessToast } from '../../../lib/toastHelpers' type ArticleContainerProps = { viewer: UserBasicData @@ -123,16 +126,21 @@ export function ArticleContainer(props: ArticleContainerProps): JSX.Element { props.highlightOnRelease ) // iOS app embed can overide the original margin and line height - const [maxWidthPercentageOverride, setMaxWidthPercentageOverride] = - useState(null) - const [lineHeightOverride, setLineHeightOverride] = - useState(null) - const [fontFamilyOverride, setFontFamilyOverride] = - useState(null) - const [highContrastTextOverride, setHighContrastTextOverride] = - useState(undefined) - const [justifyTextOverride, setJustifyTextOverride] = - useState(undefined) + const [maxWidthPercentageOverride, setMaxWidthPercentageOverride] = useState< + number | null + >(null) + const [lineHeightOverride, setLineHeightOverride] = useState( + null + ) + const [fontFamilyOverride, setFontFamilyOverride] = useState( + null + ) + const [highContrastTextOverride, setHighContrastTextOverride] = useState< + boolean | undefined + >(undefined) + const [justifyTextOverride, setJustifyTextOverride] = useState< + boolean | undefined + >(undefined) const highlightHref = useRef( window.location.hash ? window.location.hash.split('#')[1] : null ) @@ -140,6 +148,8 @@ export function ArticleContainer(props: ArticleContainerProps): JSX.Element { props.textDirection ?? 'LTR' ) + const restoreItem = useRestoreItem() + const updateFontSize = useCallback( (newFontSize: number) => { setFontSize(newFontSize) @@ -476,6 +486,47 @@ export function ArticleContainer(props: ArticleContainerProps): JSX.Element { recommendationsWithNotes={recommendationsWithNotes} /> )} + {!props.isAppleAppEmbed && + props.article && + props.article.state == State.DELETED && ( + + This item has been deleted. To access all the highlights and + content you can restore it. If you do not restore this item it + will be removed from your trash after two weeks or when you + manually empty your trash. + + + )} {/* {userHasFeature(props.viewer, 'ai-summaries') && (