Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: view source content in app #655

Merged
merged 13 commits into from
Sep 29, 2024
Merged
Prev Previous commit
Next Next commit
refactor: show source content in modal in social media and video
  • Loading branch information
lawvs committed Sep 28, 2024
commit dbc47e2c659803aee4e4e7ffc601e6d997f6cb8d
9 changes: 0 additions & 9 deletions apps/renderer/src/atoms/source-content.ts

This file was deleted.

31 changes: 31 additions & 0 deletions apps/renderer/src/atoms/source-content.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { atom } from "jotai"
import { useCallback } from "react"

import { useModalStack } from "~/components/ui/modal"
import { createAtomHooks } from "~/lib/jotai"

export const [, , useShowSourceContent, , getShowSourceContent, setShowSourceContent] =
createAtomHooks(atom<boolean>(false))

export const toggleShowSourceContent = () => setShowSourceContent(!getShowSourceContent())
export const resetShowSourceContent = () => setShowSourceContent(false)

export const useSourceContentModal = () => {
const { present } = useModalStack()

return useCallback(
({ title, src }: { title?: string; src: string }) => {
const ViewTag = window.electron ? "webview" : "iframe"
present({
id: src,
title,
content: () => <ViewTag src={src} style={{ width: "100%", height: "100%" }} />,
resizeable: true,
clickOutsideToDismiss: true,
// The number was picked arbitrarily
resizeDefaultSize: { width: 900, height: 900 },
})
},
[present],
)
}
20 changes: 18 additions & 2 deletions apps/renderer/src/hooks/biz/useEntryActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import {
} from "~/atoms/readability"
import { useIntegrationSettingKey } from "~/atoms/settings/integration"
import {
getShowSourceContent,
setShowSourceContent,
toggleShowSourceContent,
useShowSourceContent,
useSourceContentModal,
} from "~/atoms/source-content"
import { whoami } from "~/atoms/user"
import { mountLottie } from "~/components/ui/lottie-container"
Expand All @@ -28,6 +29,7 @@ import {
import { shortcuts } from "~/constants/shortcuts"
import { tipcClient } from "~/lib/client"
import { nextFrame } from "~/lib/dom"
import { FeedViewType } from "~/lib/enum"
import { getOS } from "~/lib/utils"
import StarAnimationUri from "~/lottie/star.lottie?url"
import type { CombinedEntryModel } from "~/models"
Expand Down Expand Up @@ -155,6 +157,9 @@ export const useEntryActions = ({
entryId: populatedEntry?.entries.id ?? undefined,
})

const showSourceContent = useShowSourceContent()
const showSourceContentModal = useSourceContentModal()

const collect = useCollect(populatedEntry)
const uncollect = useUnCollect(populatedEntry)
const read = useRead()
Expand Down Expand Up @@ -362,8 +367,16 @@ export const useEntryActions = ({
// shortcut: shortcuts.entry.openInBrowser.key,
className: "i-mgc-world-2-cute-re",
hide: !populatedEntry.entries.url,
active: getShowSourceContent(),
active: showSourceContent,
onClick: () => {
if (!populatedEntry.entries.url) return
if (view === FeedViewType.SocialMedia || view === FeedViewType.Videos) {
showSourceContentModal({
title: populatedEntry.entries.title ?? undefined,
src: populatedEntry.entries.url,
})
return
}
if (type === "toolbar") {
toggleShowSourceContent()
return
Expand Down Expand Up @@ -428,9 +441,12 @@ export const useEntryActions = ({
instapaperPassword,
instapaperUsername,
feed?.ownerUserId,
type,
showSourceContent,
openTipModal,
collect,
uncollect,
showSourceContentModal,
read,
unread,
])
Expand Down