Skip to content

Commit

Permalink
Merge pull request omnivore-app#4353 from omnivore-app/fix/web-restor…
Browse files Browse the repository at this point in the history
…e-articles

Allow deleted articles to be read and restored from the article page
  • Loading branch information
jacksonh authored Aug 30, 2024
2 parents f3e3d57 + cbdd40f commit 88fe867
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/api/src/resolvers/article/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
71 changes: 61 additions & 10 deletions packages/web/components/templates/article/ArticleContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -123,23 +126,30 @@ export function ArticleContainer(props: ArticleContainerProps): JSX.Element {
props.highlightOnRelease
)
// iOS app embed can overide the original margin and line height
const [maxWidthPercentageOverride, setMaxWidthPercentageOverride] =
useState<number | null>(null)
const [lineHeightOverride, setLineHeightOverride] =
useState<number | null>(null)
const [fontFamilyOverride, setFontFamilyOverride] =
useState<string | null>(null)
const [highContrastTextOverride, setHighContrastTextOverride] =
useState<boolean | undefined>(undefined)
const [justifyTextOverride, setJustifyTextOverride] =
useState<boolean | undefined>(undefined)
const [maxWidthPercentageOverride, setMaxWidthPercentageOverride] = useState<
number | null
>(null)
const [lineHeightOverride, setLineHeightOverride] = useState<number | null>(
null
)
const [fontFamilyOverride, setFontFamilyOverride] = useState<string | null>(
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
)
const [textDirection, setTextDirection] = useState(
props.textDirection ?? 'LTR'
)

const restoreItem = useRestoreItem()

const updateFontSize = useCallback(
(newFontSize: number) => {
setFontSize(newFontSize)
Expand Down Expand Up @@ -476,6 +486,47 @@ export function ArticleContainer(props: ArticleContainerProps): JSX.Element {
recommendationsWithNotes={recommendationsWithNotes}
/>
)}
{!props.isAppleAppEmbed &&
props.article &&
props.article.state == State.DELETED && (
<VStack
css={{
borderRadius: '6px',
m: '20px',
p: '20px',
gap: '10px',
width: '100%',
marginTop: '24px',
bg: 'color(display-p3 0.996 0.71 0 / 0.11)',
lineHeight: '2.0',
}}
alignment="start"
distribution="start"
>
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.
<Button
style="ctaBlue"
onClick={async (event) => {
try {
const item = await restoreItem.mutateAsync({
itemId: props.article.id,
slug: props.article.slug,
})
console.log('restored: ', item)
showSuccessToast('Item restored')
} catch (err) {
console.log('error restoring item: ', err)
showErrorToast('Error restoring item')
}
}}
>
Restore item
</Button>
</VStack>
)}
{/* {userHasFeature(props.viewer, 'ai-summaries') && (
<AISummary
libraryItemId={props.article.id}
Expand Down

0 comments on commit 88fe867

Please sign in to comment.