pass highlights into webreader
This commit is contained in:
@ -5,7 +5,7 @@ import Views
|
||||
import WebKit
|
||||
|
||||
struct WebReader: UIViewRepresentable {
|
||||
let htmlContent: String
|
||||
let articleContent: ArticleContent
|
||||
let item: FeedItem
|
||||
let openLinkAction: (URL) -> Void
|
||||
let webViewActionHandler: (WKScriptMessage) -> Void
|
||||
@ -33,7 +33,7 @@ struct WebReader: UIViewRepresentable {
|
||||
|
||||
webView.loadHTMLString(
|
||||
WebReaderContent(
|
||||
htmlContent: htmlContent,
|
||||
articleContent: articleContent,
|
||||
item: item,
|
||||
authToken: authToken,
|
||||
isDark: UITraitCollection.current.userInterfaceStyle == .dark,
|
||||
|
||||
@ -13,7 +13,7 @@ struct SafariWebLink: Identifiable {
|
||||
// TODO: load highlights
|
||||
final class WebReaderViewModel: ObservableObject {
|
||||
@Published var isLoading = false
|
||||
@Published var htmlContent: String?
|
||||
@Published var articleContent: ArticleContent?
|
||||
|
||||
var subscriptions = Set<AnyCancellable>()
|
||||
|
||||
@ -27,8 +27,8 @@ final class WebReaderViewModel: ObservableObject {
|
||||
guard case .failure = completion else { return }
|
||||
self?.isLoading = false
|
||||
},
|
||||
receiveValue: { [weak self] htmlContent in
|
||||
self?.htmlContent = htmlContent
|
||||
receiveValue: { [weak self] articleContent in
|
||||
self?.articleContent = articleContent
|
||||
}
|
||||
)
|
||||
.store(in: &subscriptions)
|
||||
@ -189,9 +189,9 @@ struct WebReaderContainerView: View {
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
if let htmlContent = viewModel.htmlContent {
|
||||
if let articleContent = viewModel.articleContent {
|
||||
WebReader(
|
||||
htmlContent: htmlContent,
|
||||
articleContent: articleContent,
|
||||
item: item,
|
||||
openLinkAction: {
|
||||
#if os(macOS)
|
||||
|
||||
@ -4,14 +4,14 @@ import Utils
|
||||
|
||||
struct WebReaderContent {
|
||||
let textFontSize: Int
|
||||
let content: String
|
||||
let articleContent: ArticleContent
|
||||
let item: FeedItem
|
||||
let themeKey: String
|
||||
let authToken: String
|
||||
let appEnv: AppEnvironment
|
||||
|
||||
init(
|
||||
htmlContent: String,
|
||||
articleContent: ArticleContent,
|
||||
item: FeedItem,
|
||||
authToken: String,
|
||||
isDark: Bool,
|
||||
@ -19,7 +19,7 @@ struct WebReaderContent {
|
||||
appEnv: AppEnvironment
|
||||
) {
|
||||
self.textFontSize = fontSize
|
||||
self.content = htmlContent
|
||||
self.articleContent = articleContent
|
||||
self.item = item
|
||||
self.themeKey = isDark ? "Gray" : "LightGray"
|
||||
self.authToken = authToken
|
||||
@ -53,12 +53,12 @@ struct WebReaderContent {
|
||||
savedAt: new Date().toISOString(),
|
||||
url: "https://example.com",
|
||||
title: `\(item.title)`,
|
||||
content: `\(content)`,
|
||||
content: `\(articleContent.htmlContent)`,
|
||||
originalArticleUrl: "https://example.com",
|
||||
contentReader: "WEB",
|
||||
readingProgressPercent: \(item.readingProgress),
|
||||
readingProgressAnchorIndex: \(item.readingProgressAnchor),
|
||||
highlights: [],
|
||||
highlights: \(articleContent.highlightsJSONString),
|
||||
}
|
||||
|
||||
window.fontSize = \(textFontSize)
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import Foundation
|
||||
|
||||
public struct Highlight: Identifiable, Hashable {
|
||||
public struct Highlight: Identifiable, Hashable, Codable {
|
||||
public let id: String
|
||||
public let shortId: String
|
||||
public let quote: String
|
||||
@ -8,6 +8,8 @@ public struct Highlight: Identifiable, Hashable {
|
||||
public let suffix: String?
|
||||
public let patch: String
|
||||
public let annotation: String?
|
||||
public let createdAt: Date?
|
||||
public let updatedAt: Date?
|
||||
|
||||
public init(
|
||||
id: String,
|
||||
@ -16,7 +18,9 @@ public struct Highlight: Identifiable, Hashable {
|
||||
prefix: String?,
|
||||
suffix: String?,
|
||||
patch: String,
|
||||
annotation: String?
|
||||
annotation: String?,
|
||||
createdAt: Date? = nil,
|
||||
updatedAt: Date? = nil
|
||||
) {
|
||||
self.id = id
|
||||
self.shortId = shortId
|
||||
@ -25,5 +29,7 @@ public struct Highlight: Identifiable, Hashable {
|
||||
self.suffix = suffix
|
||||
self.patch = patch
|
||||
self.annotation = annotation
|
||||
self.createdAt = createdAt
|
||||
self.updatedAt = updatedAt
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,14 +4,29 @@ import Models
|
||||
import SwiftGraphQL
|
||||
|
||||
public extension DataService {
|
||||
func articleContentPublisher(username: String, slug: String) -> AnyPublisher<String, ServerError> {
|
||||
func articleContentPublisher(username: String, slug: String) -> AnyPublisher<ArticleContent, ServerError> {
|
||||
enum QueryResult {
|
||||
case success(result: String)
|
||||
case success(result: ArticleContent)
|
||||
case error(error: String)
|
||||
}
|
||||
|
||||
let highlightSelection = Selection.Highlight {
|
||||
Highlight(
|
||||
id: try $0.id(),
|
||||
shortId: try $0.shortId(),
|
||||
quote: try $0.quote(),
|
||||
prefix: try $0.prefix(),
|
||||
suffix: try $0.suffix(),
|
||||
patch: try $0.patch(),
|
||||
annotation: try $0.annotation()
|
||||
)
|
||||
}
|
||||
|
||||
let articleSelection = Selection.Article {
|
||||
try $0.content()
|
||||
ArticleContent(
|
||||
htmlContent: try $0.content(),
|
||||
highlights: try $0.highlights(selection: highlightSelection.list)
|
||||
)
|
||||
}
|
||||
|
||||
let selection = Selection<QueryResult, Unions.ArticleResult> {
|
||||
|
||||
@ -121,7 +121,9 @@ public struct WebAppWrapperView: View {
|
||||
self.url = url
|
||||
}
|
||||
|
||||
public func makeUIViewController(context _: UIViewControllerRepresentableContext<SafariView>) -> SFSafariViewController {
|
||||
public func makeUIViewController(
|
||||
context _: UIViewControllerRepresentableContext<SafariView>
|
||||
) -> SFSafariViewController {
|
||||
SFSafariViewController(url: url)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user