From a110bbae4f1b9aba287f675380d2d576eaa27128 Mon Sep 17 00:00:00 2001 From: Stephen Zhou <38493346+hyoban@users.noreply.github.com> Date: Mon, 10 Mar 2025 11:20:20 +0800 Subject: [PATCH] refactor(mobile): rename sourceContent to readabilityContent (#3013) * refactor(mobile): rename sourceContent to readabilityContent * update --- .../native/webview/EntryContentWebView.tsx | 14 ++++----- apps/mobile/src/database/schemas/index.ts | 2 +- .../EntryContentHeaderRightActions.tsx | 20 ++++++------ apps/mobile/src/modules/entry-content/ctx.ts | 2 +- apps/mobile/src/morph/hono.ts | 4 +-- .../(stack)/entries/[entryId]/index.tsx | 10 +++--- apps/mobile/src/store/entry/store.ts | 31 ++++++++++--------- apps/mobile/web-app/html-renderer/src/App.tsx | 10 +++--- .../web-app/html-renderer/src/atoms/index.ts | 2 +- .../web-app/html-renderer/types/index.ts | 2 +- 10 files changed, 50 insertions(+), 47 deletions(-) diff --git a/apps/mobile/src/components/native/webview/EntryContentWebView.tsx b/apps/mobile/src/components/native/webview/EntryContentWebView.tsx index e58bae93d..442f4369e 100644 --- a/apps/mobile/src/components/native/webview/EntryContentWebView.tsx +++ b/apps/mobile/src/components/native/webview/EntryContentWebView.tsx @@ -25,7 +25,7 @@ const NativeView: React.ComponentType< type EntryContentWebViewProps = { entry: EntryModel noMedia?: boolean - showSource?: boolean + showReadability?: boolean } const setCodeTheme = (light: string, dark: string) => { @@ -49,8 +49,8 @@ const setReaderRenderInlineStyle = (value: boolean) => { SharedWebViewModule.evaluateJavaScript(`setReaderRenderInlineStyle(${value})`) } -const setShowSource = (value: boolean) => { - SharedWebViewModule.evaluateJavaScript(`setShowSource(${value})`) +const setShowReadability = (value: boolean) => { + SharedWebViewModule.evaluateJavaScript(`setShowReadability(${value})`) } export function EntryContentWebView(props: EntryContentWebViewProps) { @@ -59,13 +59,13 @@ export function EntryContentWebView(props: EntryContentWebViewProps) { const codeThemeLight = useUISettingKey("codeHighlightThemeLight") const codeThemeDark = useUISettingKey("codeHighlightThemeDark") const readerRenderInlineStyle = useUISettingKey("readerRenderInlineStyle") - const { entry, noMedia, showSource } = props + const { entry, noMedia, showReadability } = props const [mode, setMode] = React.useState<"normal" | "debug">("normal") useEffect(() => { - setShowSource(!!showSource) - }, [showSource]) + setShowReadability(!!showReadability) + }, [showReadability]) useEffect(() => { setNoMedia(!!noMedia) @@ -106,7 +106,7 @@ export function EntryContentWebView(props: EntryContentWebViewProps) { - {(showSource ? !entry.sourceContent : !entry.content) && ( + {(showReadability ? !entry.readabilityContent : !entry.content) && ( diff --git a/apps/mobile/src/database/schemas/index.ts b/apps/mobile/src/database/schemas/index.ts index 2dd40847b..0a3eab07a 100644 --- a/apps/mobile/src/database/schemas/index.ts +++ b/apps/mobile/src/database/schemas/index.ts @@ -72,7 +72,7 @@ export const entriesTable = sqliteTable("entries", { title: text("title"), url: text("url"), content: text("content"), - sourceContent: text("source_content"), + readabilityContent: text("source_content"), description: text("description"), guid: text("guid").notNull(), author: text("author"), diff --git a/apps/mobile/src/modules/entry-content/EntryContentHeaderRightActions.tsx b/apps/mobile/src/modules/entry-content/EntryContentHeaderRightActions.tsx index c89bf5e72..d7ca89e18 100644 --- a/apps/mobile/src/modules/entry-content/EntryContentHeaderRightActions.tsx +++ b/apps/mobile/src/modules/entry-content/EntryContentHeaderRightActions.tsx @@ -54,9 +54,9 @@ const HeaderRightActionsImpl = ({ }: HeaderRightActionsProps) => { const labelColor = useColor("label") const isStarred = useIsEntryStarred(entryId) - const { showAISummaryAtom, showSourceAtom } = useEntryContentContext() + const { showAISummaryAtom, showReadabilityAtom } = useEntryContentContext() const [showAISummary, setShowAISummary] = useAtom(showAISummaryAtom) - const [showSource, setShowSource] = useAtom(showSourceAtom) + const [showReadability, setShowReadability] = useAtom(showReadabilityAtom) const [extraActionContainerWidth, setExtraActionContainerWidth] = useState(0) const entry = useEntry( @@ -108,10 +108,10 @@ const HeaderRightActionsImpl = ({ }) } - const handleShowSource = useCallback(() => { - entrySyncServices.fetchEntrySourceContent(entryId) - setShowSource((prev) => !prev) - }, [entryId, setShowSource]) + const handleShowReadability = useCallback(() => { + entrySyncServices.fetchEntryReadabilityContent(entryId) + setShowReadability((prev) => !prev) + }, [entryId, setShowReadability]) const handleCopyLink = () => { if (!entry?.url) return @@ -143,12 +143,12 @@ const HeaderRightActionsImpl = ({ iconColor: isStarred ? "#facc15" : undefined, }, { - key: "ShowSource", - title: "Show Source", + key: "ShowReadability", + title: "Show Readability", icon: , iconIOS: { name: "doc.text" }, - onPress: handleShowSource, - active: showSource, + onPress: handleShowReadability, + active: showReadability, isCheckbox: true, }, { diff --git a/apps/mobile/src/modules/entry-content/ctx.ts b/apps/mobile/src/modules/entry-content/ctx.ts index 0195f6107..00bad707c 100644 --- a/apps/mobile/src/modules/entry-content/ctx.ts +++ b/apps/mobile/src/modules/entry-content/ctx.ts @@ -3,7 +3,7 @@ import { createContext, useContext } from "react" interface EntryContentContextType { showAISummaryAtom: PrimitiveAtom - showSourceAtom: PrimitiveAtom + showReadabilityAtom: PrimitiveAtom } export const EntryContentContext = createContext(null!) export const useEntryContentContext = () => { diff --git a/apps/mobile/src/morph/hono.ts b/apps/mobile/src/morph/hono.ts index e403cb0a1..6aa302363 100644 --- a/apps/mobile/src/morph/hono.ts +++ b/apps/mobile/src/morph/hono.ts @@ -107,7 +107,7 @@ class Morph { title: item.entries.title, url: item.entries.url, content: null, - sourceContent: null, + readabilityContent: null, description: item.entries.description, guid: item.entries.guid, author: item.entries.author, @@ -162,7 +162,7 @@ class Morph { title: data.entries.title, url: data.entries.url, content: data.entries.content, - sourceContent: null, + readabilityContent: null, description: data.entries.description, guid: data.entries.guid, author: data.entries.author, diff --git a/apps/mobile/src/screens/(stack)/entries/[entryId]/index.tsx b/apps/mobile/src/screens/(stack)/entries/[entryId]/index.tsx index 7f3a7d708..b4d01ece3 100644 --- a/apps/mobile/src/screens/(stack)/entries/[entryId]/index.tsx +++ b/apps/mobile/src/screens/(stack)/entries/[entryId]/index.tsx @@ -37,14 +37,14 @@ export default function EntryDetailPage() { const ctxValue = useMemo( () => ({ showAISummaryAtom: atom(entry?.settings?.summary || false), - showSourceAtom: atom(entry?.settings?.readability || false), + showReadabilityAtom: atom(entry?.settings?.readability || false), }), [entry?.settings?.readability, entry?.settings?.summary], ) useEffect(() => { if (entry?.settings?.readability) { - entrySyncServices.fetchEntrySourceContent(entryId) + entrySyncServices.fetchEntryReadabilityContent(entryId) } }, [entry?.settings?.readability, entryId]) @@ -102,9 +102,9 @@ export default function EntryDetailPage() { } const EntryContentWebViewWithContext = ({ entry }: { entry: EntryModel }) => { - const { showSourceAtom } = useEntryContentContext() - const showSource = useAtomValue(showSourceAtom) - return + const { showReadabilityAtom } = useEntryContentContext() + const showReadability = useAtomValue(showReadabilityAtom) + return } const EntryInfo = ({ entryId }: { entryId: string }) => { diff --git a/apps/mobile/src/store/entry/store.ts b/apps/mobile/src/store/entry/store.ts index 28e9ddba9..291fea8f9 100644 --- a/apps/mobile/src/store/entry/store.ts +++ b/apps/mobile/src/store/entry/store.ts @@ -225,11 +225,11 @@ class EntryActions { updateEntryContentInSession({ entryId, content, - sourceContent, + readabilityContent, }: { entryId: EntryId content?: string - sourceContent?: string + readabilityContent?: string }) { immerSet((draft) => { const entry = draft.data[entryId] @@ -237,8 +237,8 @@ class EntryActions { if (content) { entry.content = content } - if (sourceContent) { - entry.sourceContent = sourceContent + if (readabilityContent) { + entry.readabilityContent = readabilityContent } }) } @@ -246,15 +246,15 @@ class EntryActions { async updateEntryContent({ entryId, content, - sourceContent, + readabilityContent, }: { entryId: EntryId content?: string - sourceContent?: string + readabilityContent?: string }) { const tx = createTransaction() tx.store(() => { - this.updateEntryContentInSession({ entryId, content, sourceContent }) + this.updateEntryContentInSession({ entryId, content, readabilityContent }) }) tx.persist(() => { @@ -262,8 +262,8 @@ class EntryActions { EntryService.patch({ id: entryId, content }) } - if (sourceContent) { - EntryService.patch({ id: entryId, sourceContent }) + if (readabilityContent) { + EntryService.patch({ id: entryId, readabilityContent }) } }) @@ -376,7 +376,7 @@ class EntrySyncServices { const entryInDB = entriesInDB.find((e) => e.id === entry.id) if (entryInDB) { entry.content = entryInDB.content - entry.sourceContent = entryInDB.sourceContent + entry.readabilityContent = entryInDB.readabilityContent } } @@ -438,13 +438,16 @@ class EntrySyncServices { return entry } - async fetchEntrySourceContent(entryId: EntryId) { + async fetchEntryReadabilityContent(entryId: EntryId) { const entry = getEntry(entryId) - if (entry?.url && !entry?.sourceContent) { + if (entry?.url && !entry?.readabilityContent) { const contentByFetch = await readability(entry.url) - if (contentByFetch?.content && entry?.sourceContent !== contentByFetch.content) { - await entryActions.updateEntryContent({ entryId, sourceContent: contentByFetch.content }) + if (contentByFetch?.content && entry?.readabilityContent !== contentByFetch.content) { + await entryActions.updateEntryContent({ + entryId, + readabilityContent: contentByFetch.content, + }) } } return entry diff --git a/apps/mobile/web-app/html-renderer/src/App.tsx b/apps/mobile/web-app/html-renderer/src/App.tsx index 2f1efd497..ae65d452f 100644 --- a/apps/mobile/web-app/html-renderer/src/App.tsx +++ b/apps/mobile/web-app/html-renderer/src/App.tsx @@ -7,7 +7,7 @@ import { entryAtom, noMediaAtom, readerRenderInlineStyleAtom, - showSourceAtom, + showReadabilityAtom, } from "./atoms" import { HTML } from "./HTML" @@ -28,8 +28,8 @@ Object.assign(window, { setNoMedia(value: boolean) { store.set(noMediaAtom, value) }, - setShowSource(value: boolean) { - store.set(showSourceAtom, value) + setShowReadability(value: boolean) { + store.set(showReadabilityAtom, value) }, reset() { store.set(entryAtom, null) @@ -41,12 +41,12 @@ export const App = () => { const entry = useAtomValue(entryAtom, { store }) const readerRenderInlineStyle = useAtomValue(readerRenderInlineStyleAtom, { store }) const noMedia = useAtomValue(noMediaAtom, { store }) - const showSource = useAtomValue(showSourceAtom, { store }) + const showReadability = useAtomValue(showReadabilityAtom, { store }) return ( diff --git a/apps/mobile/web-app/html-renderer/src/atoms/index.ts b/apps/mobile/web-app/html-renderer/src/atoms/index.ts index 84c1745a9..d0e20acda 100644 --- a/apps/mobile/web-app/html-renderer/src/atoms/index.ts +++ b/apps/mobile/web-app/html-renderer/src/atoms/index.ts @@ -8,4 +8,4 @@ export const codeThemeLightAtom = atom(null) export const codeThemeDarkAtom = atom(null) export const readerRenderInlineStyleAtom = atom(false) export const noMediaAtom = atom(false) -export const showSourceAtom = atom(false) +export const showReadabilityAtom = atom(false) diff --git a/apps/mobile/web-app/html-renderer/types/index.ts b/apps/mobile/web-app/html-renderer/types/index.ts index d7cb4342f..50fb2045c 100644 --- a/apps/mobile/web-app/html-renderer/types/index.ts +++ b/apps/mobile/web-app/html-renderer/types/index.ts @@ -9,7 +9,7 @@ export interface MediaModel { export interface EntryModel { content?: string - sourceContent?: string + readabilityContent?: string title?: string media?: MediaModel[] }