fix(desktop): reset highlightMotion state after switching entry

This commit is contained in:
Stephen Zhou 2025-05-20 22:07:40 +08:00
parent c4c1b35670
commit 25d1f06fd5
No known key found for this signature in database
4 changed files with 20 additions and 6 deletions

View File

@ -1,6 +1,7 @@
import { isMobile } from "@follow/components/hooks/useMobile.js"
import { FeedViewType, UserRole, views } from "@follow/constants"
import { IN_ELECTRON } from "@follow/shared/constants"
import { doesTextContainHTML } from "@follow/utils/utils"
import { useMemo } from "react"
import { useShowAISummaryAuto, useShowAISummaryOnce } from "~/atoms/ai-summary"
@ -130,10 +131,6 @@ export class EntryActionMenuItem extends MenuItemText {
}
export type EntryActionItem = EntryActionMenuItem | MenuItemSeparator
function hasHTMLTags(text?: string | null): boolean {
return /<[^>]+>/.test(text || "")
}
export const useEntryActions = ({
entryId,
view,
@ -158,7 +155,7 @@ export const useEntryActions = ({
const inList = !!listId
const inbox = useInboxById(entry?.inboxId)
const isInbox = !!inbox
const isContentContainsHTMLTags = hasHTMLTags(entry?.entries.content)
const isContentContainsHTMLTags = doesTextContainHTML(entry?.entries.content)
const isShowSourceContent = useShowSourceContent()
const isShowAISummaryAuto = useShowAISummaryAuto(entry)

View File

@ -73,6 +73,10 @@ export const ActionButton = ({
React.useImperativeHandle(ref, () => buttonRef.current!)
const [shouldHighlightMotion, setShouldHighlightMotion] = useState(highlightMotion)
React.useEffect(() => {
setShouldHighlightMotion(highlightMotion)
}, [highlightMotion])
const [loading, setLoading] = useState(false)
const Trigger = (

View File

@ -1,6 +1,6 @@
import { describe, expect, test } from "vitest"
import { isBizId, omitShallow, toScientificNotation } from "./utils"
import { doesTextContainHTML, isBizId, omitShallow, toScientificNotation } from "./utils"
describe("utils", () => {
test("isBizId", () => {
@ -85,4 +85,12 @@ describe("utils", () => {
expect(omitShallow(void 0)).toEqual(void 0)
expect(omitShallow([1, 2])).toEqual([1, 2])
})
test("does text contain html", () => {
expect(doesTextContainHTML("a<div>b</div>")).toBe(true)
expect(doesTextContainHTML("Test")).toBe(false)
expect(doesTextContainHTML("<p> </p>")).toBe(false)
expect(doesTextContainHTML("Test <p> </p>")).toBe(false)
expect(doesTextContainHTML("Test <br/>")).toBe(false)
})
})

View File

@ -417,3 +417,8 @@ export function combineCleanupFunctions(...fns: Array<Nullable<(() => void) | vo
})
}
}
export function doesTextContainHTML(text?: string | null): boolean {
if (!text) return false
return /<([a-z][a-z0-9]*)\b[^>]*>\s*[^<>\s].*<\/\1>/i.test(text)
}