fix(desktop): apply custom content style for social media and video, close #3630
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { useMemo } from "react"
|
||||
|
||||
import { useUISettingKey } from "~/atoms/settings/ui"
|
||||
|
||||
export function useRenderStyle({
|
||||
baseFontSize = 16,
|
||||
baseLineHeight = 1.75,
|
||||
}: { baseFontSize?: number; baseLineHeight?: number } = {}) {
|
||||
const contentLineHeight = useUISettingKey("contentLineHeight")
|
||||
const contentFontSize = useUISettingKey("contentFontSize")
|
||||
const readerFontFamily = useUISettingKey("readerFontFamily")
|
||||
|
||||
return useMemo(() => {
|
||||
const css = {} as React.CSSProperties
|
||||
if (readerFontFamily) {
|
||||
css.fontFamily = readerFontFamily
|
||||
}
|
||||
if (contentLineHeight) {
|
||||
css.lineHeight = contentLineHeight * (baseLineHeight / 1.5)
|
||||
}
|
||||
if (contentFontSize) {
|
||||
css.fontSize = contentFontSize * (baseFontSize / 16)
|
||||
}
|
||||
|
||||
return css
|
||||
}, [readerFontFamily, contentLineHeight, contentFontSize, baseFontSize, baseLineHeight])
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import { Media } from "~/components/ui/media"
|
||||
import { usePreviewMedia } from "~/components/ui/media/hooks"
|
||||
import { useEntryIsRead } from "~/hooks/biz/useAsRead"
|
||||
import { useSortedEntryActions } from "~/hooks/biz/useEntryActions"
|
||||
import { useRenderStyle } from "~/hooks/biz/useRenderStyle"
|
||||
import { jotaiStore } from "~/lib/jotai"
|
||||
import { parseSocialMedia } from "~/lib/parsers"
|
||||
import { COMMAND_ID } from "~/modules/command/commands/id"
|
||||
@@ -54,6 +55,7 @@ export const SocialMediaItem: EntryListItemFC = ({ entryId, entryPreview, transl
|
||||
}
|
||||
}, [])
|
||||
const autoExpandLongSocialMedia = useGeneralSettingKey("autoExpandLongSocialMedia")
|
||||
const renderStyle = useRenderStyle({ baseFontSize: 14, baseLineHeight: 1.625 })
|
||||
|
||||
const titleRef = useRef<HTMLDivElement>(null)
|
||||
if (!entry || !feed) return null
|
||||
@@ -111,6 +113,7 @@ export const SocialMediaItem: EntryListItemFC = ({ entryId, entryPreview, transl
|
||||
"prose-blockquote:mt-0 cursor-auto select-text text-sm leading-relaxed",
|
||||
)}
|
||||
noMedia
|
||||
style={renderStyle}
|
||||
>
|
||||
{translation?.content || content}
|
||||
</HTML>
|
||||
|
||||
@@ -17,6 +17,7 @@ import type { ModalContentComponent } from "~/components/ui/modal"
|
||||
import { FixedModalCloseButton } from "~/components/ui/modal/components/close"
|
||||
import { PlainModal } from "~/components/ui/modal/stacked/custom-modal"
|
||||
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
|
||||
import { useRenderStyle } from "~/hooks/biz/useRenderStyle"
|
||||
import { useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
|
||||
import { FeedIcon } from "~/modules/feed/feed-icon"
|
||||
import { FeedTitle } from "~/modules/feed/feed-title"
|
||||
@@ -152,6 +153,8 @@ const PreviewVideoModalContent: ModalContentComponent<{
|
||||
const translation = useEntryTranslation({ entry, extraFields: ["content"] })
|
||||
const content = translation.data?.content || entry?.entries.content
|
||||
const currentAudioPlayerIsPlay = useRef(AudioPlayer.get().status === "playing")
|
||||
|
||||
const renderStyle = useRenderStyle()
|
||||
useEffect(() => {
|
||||
const currentValue = currentAudioPlayerIsPlay.current
|
||||
if (currentValue) {
|
||||
@@ -179,7 +182,12 @@ const PreviewVideoModalContent: ModalContentComponent<{
|
||||
<ViewTag src={src} className="size-full" />
|
||||
{!!content && (
|
||||
<div className="bg-background p-10 pt-5 backdrop-blur-sm">
|
||||
<HTML as="div" className="prose dark:prose-invert !max-w-full" noMedia>
|
||||
<HTML
|
||||
as="div"
|
||||
className="prose dark:prose-invert !max-w-full"
|
||||
noMedia
|
||||
style={renderStyle}
|
||||
>
|
||||
{content}
|
||||
</HTML>
|
||||
</div>
|
||||
|
||||
@@ -18,6 +18,7 @@ import { useUISettingKey } from "~/atoms/settings/ui"
|
||||
import { ShadowDOM } from "~/components/common/ShadowDOM"
|
||||
import type { TocRef } from "~/components/ui/markdown/components/Toc"
|
||||
import { useInPeekModal } from "~/components/ui/modal/inspire/InPeekModal"
|
||||
import { useRenderStyle } from "~/hooks/biz/useRenderStyle"
|
||||
import { useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
|
||||
import { useAuthQuery } from "~/hooks/common"
|
||||
import { useFeedSafeUrl } from "~/hooks/common/useFeedSafeUrl"
|
||||
@@ -237,25 +238,9 @@ const Renderer: React.FC<{
|
||||
),
|
||||
)
|
||||
|
||||
const contentLineHeight = useUISettingKey("contentLineHeight")
|
||||
const contentFontSize = useUISettingKey("contentFontSize")
|
||||
const readerFontFamily = useUISettingKey("readerFontFamily")
|
||||
const readerRenderInlineStyle = useUISettingKey("readerRenderInlineStyle")
|
||||
|
||||
const stableRenderStyle = useMemo(() => {
|
||||
const css = {} as React.CSSProperties
|
||||
if (readerFontFamily) {
|
||||
css.fontFamily = readerFontFamily
|
||||
}
|
||||
if (contentLineHeight) {
|
||||
css.lineHeight = contentLineHeight
|
||||
}
|
||||
if (contentFontSize) {
|
||||
css.fontSize = contentFontSize
|
||||
}
|
||||
|
||||
return css
|
||||
}, [readerFontFamily, contentLineHeight, contentFontSize])
|
||||
const stableRenderStyle = useRenderStyle()
|
||||
const isInPeekModal = useInPeekModal()
|
||||
|
||||
const tocRef = useRef<TocRef | null>(null)
|
||||
|
||||
@@ -11,6 +11,7 @@ import { useAudioPlayerAtomSelector } from "~/atoms/player"
|
||||
import { useUISettingKey } from "~/atoms/settings/ui"
|
||||
import { ShadowDOM } from "~/components/common/ShadowDOM"
|
||||
import { useNavigateEntry } from "~/hooks/biz/useNavigateEntry"
|
||||
import { useRenderStyle } from "~/hooks/biz/useRenderStyle"
|
||||
import { useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
|
||||
import { useAuthQuery, usePreventOverscrollBounce } from "~/hooks/common"
|
||||
import { WrappedElementProvider } from "~/providers/wrapped-element-provider"
|
||||
@@ -104,21 +105,7 @@ export const EntryContent: Component<{
|
||||
|
||||
const contentTranslated = useEntryTranslation({ entry, extraFields: ["content"] })
|
||||
|
||||
const contentLineHeight = useUISettingKey("contentLineHeight")
|
||||
const contentFontSize = useUISettingKey("contentFontSize")
|
||||
|
||||
const stableRenderStyle = useMemo(() => {
|
||||
const css = {} as React.CSSProperties
|
||||
|
||||
if (contentLineHeight) {
|
||||
css.lineHeight = contentLineHeight
|
||||
}
|
||||
if (contentFontSize) {
|
||||
css.fontSize = contentFontSize
|
||||
}
|
||||
|
||||
return css
|
||||
}, [contentLineHeight, contentFontSize])
|
||||
const stableRenderStyle = useRenderStyle()
|
||||
|
||||
if (!entry) return null
|
||||
|
||||
|
||||
Reference in New Issue
Block a user