refactor(mobile): rename sourceContent to readabilityContent (#3013)
* refactor(mobile): rename sourceContent to readabilityContent * update
This commit is contained in:
@@ -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) {
|
||||
</View>
|
||||
|
||||
<Portal>
|
||||
{(showSource ? !entry.sourceContent : !entry.content) && (
|
||||
{(showReadability ? !entry.readabilityContent : !entry.content) && (
|
||||
<View className="absolute inset-0 items-center justify-center">
|
||||
<ActivityIndicator />
|
||||
</View>
|
||||
|
||||
@@ -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"),
|
||||
|
||||
@@ -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: <DocmentCuteReIcon />,
|
||||
iconIOS: { name: "doc.text" },
|
||||
onPress: handleShowSource,
|
||||
active: showSource,
|
||||
onPress: handleShowReadability,
|
||||
active: showReadability,
|
||||
isCheckbox: true,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@ import { createContext, useContext } from "react"
|
||||
|
||||
interface EntryContentContextType {
|
||||
showAISummaryAtom: PrimitiveAtom<boolean>
|
||||
showSourceAtom: PrimitiveAtom<boolean>
|
||||
showReadabilityAtom: PrimitiveAtom<boolean>
|
||||
}
|
||||
export const EntryContentContext = createContext<EntryContentContextType>(null!)
|
||||
export const useEntryContentContext = () => {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 <EntryContentWebView entry={entry} showSource={showSource} />
|
||||
const { showReadabilityAtom } = useEntryContentContext()
|
||||
const showReadability = useAtomValue(showReadabilityAtom)
|
||||
return <EntryContentWebView entry={entry} showReadability={showReadability} />
|
||||
}
|
||||
|
||||
const EntryInfo = ({ entryId }: { entryId: string }) => {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 (
|
||||
<Provider store={store}>
|
||||
<HTML
|
||||
children={showSource ? entry?.sourceContent : entry?.content}
|
||||
children={showReadability ? entry?.readabilityContent : entry?.content}
|
||||
renderInlineStyle={readerRenderInlineStyle}
|
||||
noMedia={noMedia}
|
||||
/>
|
||||
|
||||
@@ -8,4 +8,4 @@ export const codeThemeLightAtom = atom<string | null>(null)
|
||||
export const codeThemeDarkAtom = atom<string | null>(null)
|
||||
export const readerRenderInlineStyleAtom = atom<boolean>(false)
|
||||
export const noMediaAtom = atom<boolean>(false)
|
||||
export const showSourceAtom = atom<boolean>(false)
|
||||
export const showReadabilityAtom = atom<boolean>(false)
|
||||
|
||||
@@ -9,7 +9,7 @@ export interface MediaModel {
|
||||
|
||||
export interface EntryModel {
|
||||
content?: string
|
||||
sourceContent?: string
|
||||
readabilityContent?: string
|
||||
title?: string
|
||||
media?: MediaModel[]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user