2022-03-21 22:28:48 +00:00
|
|
|
import React from 'react'
|
|
|
|
|
import ReactDOM from 'react-dom'
|
2022-03-17 19:20:08 +00:00
|
|
|
import { Box, VStack } from '@omnivore/web/components/elements/LayoutPrimitives'
|
|
|
|
|
import { ArticleContainer } from '@omnivore/web/components/templates/article/ArticleContainer'
|
2022-03-21 22:28:48 +00:00
|
|
|
import { applyStoredTheme } from '@omnivore/web/lib/themeUpdater'
|
2022-03-17 19:20:08 +00:00
|
|
|
import '@omnivore/web/styles/globals.css'
|
|
|
|
|
import '@omnivore/web/styles/articleInnerStyling.css'
|
|
|
|
|
|
2022-03-22 22:25:02 +00:00
|
|
|
const mutation = async (name, input) => {
|
2022-09-23 03:57:29 +00:00
|
|
|
if (window.webkit) {
|
|
|
|
|
// Send iOS a message
|
|
|
|
|
const result =
|
2022-09-26 19:49:10 +00:00
|
|
|
await window?.webkit?.messageHandlers.articleAction?.postMessage({
|
|
|
|
|
actionID: name,
|
|
|
|
|
...input,
|
|
|
|
|
})
|
2022-09-23 03:57:29 +00:00
|
|
|
return result.result
|
|
|
|
|
} else {
|
|
|
|
|
// Send android a message
|
2022-09-26 19:49:10 +00:00
|
|
|
console.log('sending android a message', name, input)
|
|
|
|
|
AndroidWebKitMessenger.handleIdentifiableMessage(
|
|
|
|
|
name,
|
|
|
|
|
JSON.stringify(input)
|
|
|
|
|
)
|
2022-12-06 04:10:42 +00:00
|
|
|
|
|
|
|
|
// TODO: handle errors
|
|
|
|
|
switch (name) {
|
|
|
|
|
case 'createHighlight':
|
|
|
|
|
return input
|
|
|
|
|
case 'deleteHighlight':
|
|
|
|
|
return true
|
|
|
|
|
case 'mergeHighlight':
|
|
|
|
|
return {
|
|
|
|
|
id: input['id'],
|
2024-01-10 03:47:30 +00:00
|
|
|
type: input['type'],
|
2022-12-06 04:10:42 +00:00
|
|
|
shortID: input['shortId'],
|
|
|
|
|
quote: input['quote'],
|
|
|
|
|
patch: input['patch'],
|
|
|
|
|
createdByMe: true,
|
|
|
|
|
labels: [],
|
|
|
|
|
}
|
|
|
|
|
case 'updateHighlight':
|
|
|
|
|
return true
|
|
|
|
|
case 'articleReadingProgress':
|
|
|
|
|
return true
|
|
|
|
|
default:
|
|
|
|
|
return true
|
|
|
|
|
}
|
2022-09-23 03:57:29 +00:00
|
|
|
}
|
2022-03-22 21:13:17 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-17 19:20:08 +00:00
|
|
|
const App = () => {
|
2022-03-22 21:13:17 +00:00
|
|
|
applyStoredTheme(false)
|
2022-03-17 19:20:08 +00:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Box
|
|
|
|
|
css={{
|
2023-04-04 14:21:27 +00:00
|
|
|
// height: '100vh',
|
|
|
|
|
// width: '100vw',
|
2023-02-08 21:54:17 +00:00
|
|
|
paddingTop: window.webkit ? 0 : '48px', // add 48px to android only
|
2022-03-17 19:20:08 +00:00
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<VStack
|
|
|
|
|
alignment="center"
|
|
|
|
|
distribution="center"
|
|
|
|
|
className="disable-webkit-callout"
|
2023-04-06 11:43:58 +00:00
|
|
|
style={{ backgroundColor: 'var(--colors-readerBg)' }}
|
2022-03-17 19:20:08 +00:00
|
|
|
>
|
|
|
|
|
<ArticleContainer
|
2022-03-22 04:55:01 +00:00
|
|
|
article={window.omnivoreArticle}
|
2023-01-31 09:24:50 +00:00
|
|
|
labels={window.omnivoreArticle.labels}
|
2022-03-17 19:20:08 +00:00
|
|
|
isAppleAppEmbed={true}
|
2022-06-30 05:09:52 +00:00
|
|
|
highlightBarDisabled={!window.enableHighlightBar}
|
2022-03-17 19:20:08 +00:00
|
|
|
fontSize={window.fontSize ?? 18}
|
2022-06-03 18:55:18 +00:00
|
|
|
fontFamily={window.fontFamily ?? 'inter'}
|
2022-06-02 00:16:06 +00:00
|
|
|
margin={window.margin}
|
2022-06-13 18:27:21 +00:00
|
|
|
maxWidthPercentage={window.maxWidthPercentage}
|
2022-06-02 00:16:06 +00:00
|
|
|
lineHeight={window.lineHeight}
|
2023-02-09 23:22:39 +00:00
|
|
|
highlightOnRelease={window.highlightOnRelease}
|
2023-03-07 07:36:24 +00:00
|
|
|
highContrastText={window.prefersHighContrastFont ?? true}
|
2023-04-06 14:52:31 +00:00
|
|
|
justifyText={window.justifyText}
|
2022-03-22 21:13:17 +00:00
|
|
|
articleMutations={{
|
2022-06-02 00:16:06 +00:00
|
|
|
createHighlightMutation: (input) =>
|
|
|
|
|
mutation('createHighlight', input),
|
2024-01-08 14:27:48 +00:00
|
|
|
deleteHighlightMutation: (libraryItemId, highlightId) =>
|
|
|
|
|
mutation('deleteHighlight', { libraryItemId, highlightId }),
|
2022-06-02 00:16:06 +00:00
|
|
|
mergeHighlightMutation: (input) =>
|
|
|
|
|
mutation('mergeHighlight', input),
|
|
|
|
|
updateHighlightMutation: (input) =>
|
|
|
|
|
mutation('updateHighlight', input),
|
|
|
|
|
articleReadingProgressMutation: (input) =>
|
|
|
|
|
mutation('articleReadingProgress', input),
|
2022-03-22 21:13:17 +00:00
|
|
|
}}
|
2022-03-17 19:20:08 +00:00
|
|
|
/>
|
|
|
|
|
</VStack>
|
|
|
|
|
</Box>
|
|
|
|
|
</>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-21 22:28:48 +00:00
|
|
|
ReactDOM.render(<App />, document.getElementById('root'))
|