import { ArticleAttributes } from '../../../lib/networking/queries/useGetArticleQuery' import { Article } from './../../../components/templates/article/Article' import { Box, SpanBox, VStack } from './../../elements/LayoutPrimitives' import { StyledText } from './../../elements/StyledText' import { ArticleSubtitle } from './../../patterns/ArticleSubtitle' import { theme, ThemeId } from './../../tokens/stitches.config' import { HighlightsLayer } from '../../templates/article/HighlightsLayer' import { Button } from '../../elements/Button' import { MutableRefObject, useEffect, useState } from 'react' import { ReportIssuesModal } from './ReportIssuesModal' import { reportIssueMutation } from '../../../lib/networking/mutations/reportIssueMutation' import { ArticleHeaderToolbar } from './ArticleHeaderToolbar' import { userPersonalizationMutation } from '../../../lib/networking/mutations/userPersonalizationMutation' import { updateThemeLocally } from '../../../lib/themeUpdater' import { ArticleMutations } from '../../../lib/articleActions' import { LabelChip } from '../../elements/LabelChip' import { Label } from '../../../lib/networking/fragments/labelFragment' import { HighlightsModal } from './HighlightsModal' type ArticleContainerProps = { article: ArticleAttributes labels: Label[] articleMutations: ArticleMutations scrollElementRef: MutableRefObject isAppleAppEmbed: boolean highlightBarDisabled: boolean highlightsBaseURL: string margin?: number fontSize?: number fontFamily?: string lineHeight?: number showHighlightsModal?: boolean setShowHighlightsModal?: (show: boolean) => void } export function ArticleContainer(props: ArticleContainerProps): JSX.Element { const [showShareModal, setShowShareModal] = useState(false) const [showHighlightsModal, setShowHighlightsModal] = useState(false) const [showReportIssuesModal, setShowReportIssuesModal] = useState(false) const [fontSize, setFontSize] = useState(props.fontSize ?? 20) const updateFontSize = async (newFontSize: number) => { if (fontSize !== newFontSize) { setFontSize(newFontSize) await userPersonalizationMutation({ fontSize: newFontSize }) } } useEffect(() => { updateFontSize(props.fontSize ?? 20) }, [props.fontSize]) // Listen for font size and color mode change events sent from host apps (ios, macos...) useEffect(() => { const increaseFontSize = async () => { await updateFontSize(Math.min(fontSize + 2, 28)) } const decreaseFontSize = async () => { await updateFontSize(Math.max(fontSize - 2, 10)) } const switchToDarkMode = () => { updateThemeLocally(ThemeId.Dark) } const switchToLightMode = () => { updateThemeLocally(ThemeId.Light) } document.addEventListener('increaseFontSize', increaseFontSize) document.addEventListener('decreaseFontSize', decreaseFontSize) document.addEventListener('switchToDarkMode', switchToDarkMode) document.addEventListener('switchToLightMode', switchToLightMode) return () => { document.removeEventListener('increaseFontSize', increaseFontSize) document.removeEventListener('decreaseFontSize', decreaseFontSize) document.removeEventListener('switchToDarkMode', switchToDarkMode) document.removeEventListener('switchToLightMode', switchToLightMode) } }) useEffect(() => { window.analytics?.track('link_read', { link: props.article.id, slug: props.article.slug, url: props.article.originalArticleUrl, }) }, [props.article]) const styles = { fontSize, margin: props.margin ?? 360, lineHeight: props.lineHeight ?? 150, fontFamily: props.fontFamily ?? 'inter', readerFontColor: theme.colors.readerFont.toString(), readerFontColorTransparent: theme.colors.readerFontTransparent.toString(), readerTableHeaderColor: theme.colors.readerTableHeader.toString(), readerHeadersColor: theme.colors.readerHeader.toString(), } return ( <> {props.article.title} {props.labels ? ( {props.labels?.map((label) => )} ) : null} 0} />
{showReportIssuesModal ? ( { reportIssueMutation({ pageId: props.article.id, itemUrl: props.article.url, reportTypes: ['CONTENT_DISPLAY'], reportComment: comment, }) }} onOpenChange={(open: boolean) => setShowReportIssuesModal(open)} /> ) : null} {/* {showShareModal && ( setShowShareModal(open)} /> )} */} ) }