mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
memoize feed entry content because Interweave is costly
This commit is contained in:
@@ -1,12 +1,13 @@
|
|||||||
import { Box, createStyles, Mark, TypographyStylesProvider } from "@mantine/core"
|
import { Box, createStyles, Mark, TypographyStylesProvider } from "@mantine/core"
|
||||||
import { Constants } from "app/constants"
|
import { Constants } from "app/constants"
|
||||||
import { useAppSelector } from "app/store"
|
|
||||||
import { calculatePlaceholderSize } from "app/utils"
|
import { calculatePlaceholderSize } from "app/utils"
|
||||||
import { ImageWithPlaceholderWhileLoading } from "components/ImageWithPlaceholderWhileLoading"
|
import { ImageWithPlaceholderWhileLoading } from "components/ImageWithPlaceholderWhileLoading"
|
||||||
import { ChildrenNode, Interweave, Matcher, MatchResponse, Node, TransformCallback } from "interweave"
|
import { ChildrenNode, Interweave, Matcher, MatchResponse, Node, TransformCallback } from "interweave"
|
||||||
|
import React from "react"
|
||||||
|
|
||||||
export interface ContentProps {
|
export interface ContentProps {
|
||||||
content: string
|
content: string
|
||||||
|
highlight?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const useStyles = createStyles(theme => ({
|
const useStyles = createStyles(theme => ({
|
||||||
@@ -82,10 +83,10 @@ class HighlightMatcher extends Matcher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Content(props: ContentProps) {
|
// memoize component because Interweave is costly
|
||||||
|
const Content = React.memo((props: ContentProps) => {
|
||||||
const { classes } = useStyles()
|
const { classes } = useStyles()
|
||||||
const search = useAppSelector(state => state.entries.search)
|
const matchers = props.highlight ? [new HighlightMatcher(props.highlight)] : []
|
||||||
const matchers = search ? [new HighlightMatcher(search)] : []
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TypographyStylesProvider>
|
<TypographyStylesProvider>
|
||||||
@@ -94,4 +95,6 @@ export function Content(props: ContentProps) {
|
|||||||
</Box>
|
</Box>
|
||||||
</TypographyStylesProvider>
|
</TypographyStylesProvider>
|
||||||
)
|
)
|
||||||
}
|
})
|
||||||
|
|
||||||
|
export { Content }
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Box } from "@mantine/core"
|
import { Box } from "@mantine/core"
|
||||||
|
import { useAppSelector } from "app/store"
|
||||||
import { Entry } from "app/types"
|
import { Entry } from "app/types"
|
||||||
import { Content } from "./Content"
|
import { Content } from "./Content"
|
||||||
import { Enclosure } from "./Enclosure"
|
import { Enclosure } from "./Enclosure"
|
||||||
@@ -9,10 +10,11 @@ export interface FeedEntryBodyProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function FeedEntryBody(props: FeedEntryBodyProps) {
|
export function FeedEntryBody(props: FeedEntryBodyProps) {
|
||||||
|
const search = useAppSelector(state => state.entries.search)
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
<Box>
|
<Box>
|
||||||
<Content content={props.entry.content} />
|
<Content content={props.entry.content} highlight={search} />
|
||||||
</Box>
|
</Box>
|
||||||
{props.entry.enclosureType && props.entry.enclosureUrl && (
|
{props.entry.enclosureType && props.entry.enclosureUrl && (
|
||||||
<Box pt="md">
|
<Box pt="md">
|
||||||
|
|||||||
Reference in New Issue
Block a user