mark some models as deprecated

This commit is contained in:
Satindar Dhillon
2022-04-18 17:03:34 -07:00
parent 05d4107fa9
commit a60a5e3991
25 changed files with 74 additions and 74 deletions

View File

@ -17,7 +17,7 @@ public final class PDFViewerViewModel: ObservableObject {
self.feedItem = feedItem
}
public func loadHighlights(completion onComplete: @escaping ([Highlight]) -> Void) {
public func loadHighlights(completion onComplete: @escaping ([HighlightDep]) -> Void) {
guard let username = services.dataService.currentViewer?.username else { return }
services.dataService.pdfHighlightsPublisher(username: username, slug: feedItem.slug).sink(
@ -32,8 +32,8 @@ public final class PDFViewerViewModel: ObservableObject {
.store(in: &subscriptions)
}
private func allHighlights(fetchedHighlights: [Highlight]) -> [Highlight] {
var resultSet = [String: Highlight]()
private func allHighlights(fetchedHighlights: [HighlightDep]) -> [HighlightDep] {
var resultSet = [String: HighlightDep]()
for highlight in services.dataService.cachedHighlights(pdfID: feedItem.id) {
resultSet[highlight.id] = highlight
@ -50,7 +50,7 @@ public final class PDFViewerViewModel: ObservableObject {
public func createHighlight(shortId: String, highlightID: String, quote: String, patch: String) {
services.dataService.persistHighlight(
pdfID: feedItem.id,
highlight: Highlight(
highlight: HighlightDep(
id: highlightID,
shortId: shortId,
quote: quote,
@ -88,7 +88,7 @@ public final class PDFViewerViewModel: ObservableObject {
) {
services.dataService.persistHighlight(
pdfID: feedItem.id,
highlight: Highlight(
highlight: HighlightDep(
id: highlightID,
shortId: shortId,
quote: quote,

View File

@ -12,14 +12,14 @@ import Views
var uncommittedReadingProgressUpdates = [String: Double]()
/// Track label updates to be committed when user navigates back to grid view
var uncommittedLabelUpdates = [String: [FeedItemLabel]]()
var uncommittedLabelUpdates = [String: [FeedItemLabelDep]]()
@Published var items = [FeedItem]()
@Published var isLoading = false
@Published var showPushNotificationPrimer = false
@Published var itemUnderLabelEdit: FeedItem?
@Published var searchTerm = ""
@Published var selectedLabels = [FeedItemLabel]()
@Published var selectedLabels = [FeedItemLabelDep]()
@Published var snoozePresented = false
@Published var itemToSnooze: FeedItem?
@Published var selectedLinkItem: FeedItem?
@ -194,7 +194,7 @@ import Views
}
}
func updateLabels(itemID: String, labels: [FeedItemLabel]) {
func updateLabels(itemID: String, labels: [FeedItemLabelDep]) {
// If item is being being displayed then delay the state update of labels until
// user is no longer reading the item.
if selectedLinkItem != nil {

View File

@ -6,7 +6,7 @@ import Views
struct ApplyLabelsView: View {
enum Mode {
case item(FeedItem)
case list([FeedItemLabel])
case list([FeedItemLabelDep])
var navTitle: String {
switch self {
@ -28,7 +28,7 @@ struct ApplyLabelsView: View {
}
let mode: Mode
let commitLabelChanges: ([FeedItemLabel]) -> Void
let commitLabelChanges: ([FeedItemLabelDep]) -> Void
@EnvironmentObject var dataService: DataService
@Environment(\.presentationMode) private var presentationMode
@ -147,8 +147,8 @@ struct ApplyLabelsView: View {
}
}
private extension Sequence where Element == FeedItemLabel {
func applySearchFilter(_ searchFilter: String) -> [FeedItemLabel] {
private extension Sequence where Element == FeedItemLabelDep {
func applySearchFilter(_ searchFilter: String) -> [FeedItemLabelDep] {
if searchFilter.isEmpty {
return map { $0 } // return the identity of the sequence
}

View File

@ -7,9 +7,9 @@ import Views
final class LabelsViewModel: ObservableObject {
private var hasLoadedInitialLabels = false
@Published var isLoading = false
@Published var selectedLabels = [FeedItemLabel]()
@Published var unselectedLabels = [FeedItemLabel]()
@Published var labels = [FeedItemLabel]()
@Published var selectedLabels = [FeedItemLabelDep]()
@Published var unselectedLabels = [FeedItemLabelDep]()
@Published var labels = [FeedItemLabelDep]()
@Published var showCreateEmailModal = false
var subscriptions = Set<AnyCancellable>()
@ -19,7 +19,7 @@ final class LabelsViewModel: ObservableObject {
/// - dataService: `DataService` reference
/// - item: Optional `FeedItem` for applying labels to a single item
/// - initiallySelectedLabels: Optional `[FeedItemLabel]` for filtering a list of items
func loadLabels(dataService: DataService, item: FeedItem? = nil, initiallySelectedLabels: [FeedItemLabel]? = nil) {
func loadLabels(dataService: DataService, item: FeedItem? = nil, initiallySelectedLabels: [FeedItemLabelDep]? = nil) {
guard !hasLoadedInitialLabels else { return }
isLoading = true
@ -82,7 +82,7 @@ final class LabelsViewModel: ObservableObject {
.store(in: &subscriptions)
}
func saveItemLabelChanges(itemID: String, dataService: DataService, onComplete: @escaping ([FeedItemLabel]) -> Void) {
func saveItemLabelChanges(itemID: String, dataService: DataService, onComplete: @escaping ([FeedItemLabelDep]) -> Void) {
isLoading = true
dataService.updateArticleLabelsPublisher(itemID: itemID, labelIDs: selectedLabels.map(\.id)).sink(
receiveCompletion: { [weak self] _ in
@ -93,12 +93,12 @@ final class LabelsViewModel: ObservableObject {
.store(in: &subscriptions)
}
func addLabelToItem(_ label: FeedItemLabel) {
func addLabelToItem(_ label: FeedItemLabelDep) {
selectedLabels.insert(label, at: 0)
unselectedLabels.removeAll { $0.id == label.id }
}
func removeLabelFromItem(_ label: FeedItemLabel) {
func removeLabelFromItem(_ label: FeedItemLabelDep) {
unselectedLabels.insert(label, at: 0)
selectedLabels.removeAll { $0.id == label.id }
}

View File

@ -6,7 +6,7 @@ import WebKit
#if os(iOS)
struct WebReader: UIViewRepresentable {
let articleContent: ArticleContent
let articleContent: ArticleContentDep
let item: FeedItem
let openLinkAction: (URL) -> Void
let webViewActionHandler: (WKScriptMessage, WKScriptMessageReplyHandler?) -> Void

View File

@ -4,12 +4,12 @@ import Utils
struct WebReaderContent {
let textFontSize: Int
let articleContent: ArticleContent
let articleContent: ArticleContentDep
let item: FeedItem
let themeKey: String
init(
articleContent: ArticleContent,
articleContent: ArticleContentDep,
item: FeedItem,
isDark: Bool,
fontSize: Int

View File

@ -9,14 +9,14 @@ struct SafariWebLink: Identifiable {
let url: URL
}
func encodeHighlightResult(_ highlight: Highlight) -> [String: Any]? {
func encodeHighlightResult(_ highlight: HighlightDep) -> [String: Any]? {
guard let data = try? JSONEncoder().encode(highlight) else { return nil }
return try? JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String: Any]
}
final class WebReaderViewModel: ObservableObject {
@Published var isLoading = false
@Published var articleContent: ArticleContent?
@Published var articleContent: ArticleContentDep?
var slug: String?
var subscriptions = Set<AnyCancellable>()

View File

@ -1,5 +1,17 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="20086" systemVersion="21A559" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="LinkedItemLabel" representedClassName="LinkedItemLabel" syncable="YES" codeGenerationType="class">
<attribute name="color" attributeType="String"/>
<attribute name="createdAt" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="id" attributeType="String"/>
<attribute name="labelDescription" optional="YES" attributeType="String"/>
<attribute name="name" attributeType="String"/>
<uniquenessConstraints>
<uniquenessConstraint>
<constraint value="id"/>
</uniquenessConstraint>
</uniquenessConstraints>
</entity>
<entity name="NewsletterEmail" representedClassName="NewsletterEmail" syncable="YES" codeGenerationType="class">
<attribute name="confirmationCode" optional="YES" attributeType="String"/>
<attribute name="email" attributeType="String"/>
@ -36,19 +48,7 @@
<attribute name="savedAt" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="slug" attributeType="String"/>
<attribute name="title" attributeType="String"/>
<relationship name="labels" toMany="YES" deletionRule="Nullify" destinationEntity="PersistedFeedItemLabel"/>
<uniquenessConstraints>
<uniquenessConstraint>
<constraint value="id"/>
</uniquenessConstraint>
</uniquenessConstraints>
</entity>
<entity name="PersistedFeedItemLabel" representedClassName="PersistedFeedItemLabel" syncable="YES" codeGenerationType="class">
<attribute name="color" attributeType="String"/>
<attribute name="createdAt" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="id" attributeType="String"/>
<attribute name="labelDescription" optional="YES" attributeType="String"/>
<attribute name="name" attributeType="String"/>
<relationship name="labels" toMany="YES" deletionRule="Nullify" destinationEntity="LinkedItemLabel"/>
<uniquenessConstraints>
<uniquenessConstraint>
<constraint value="id"/>
@ -88,7 +88,7 @@
<elements>
<element name="PersistedArticleContent" positionX="9" positionY="108" width="128" height="59"/>
<element name="PersistedFeedItem" positionX="-18" positionY="63" width="128" height="284"/>
<element name="PersistedFeedItemLabel" positionX="-36" positionY="18" width="128" height="104"/>
<element name="LinkedItemLabel" positionX="-36" positionY="18" width="128" height="104"/>
<element name="PersistedHighlight" positionX="27" positionY="225" width="128" height="209"/>
<element name="Viewer" positionX="45" positionY="234" width="128" height="89"/>
<element name="NewsletterEmail" positionX="0" positionY="180" width="128" height="74"/>

View File

@ -1,12 +1,12 @@
import Foundation
public struct ArticleContent {
public struct ArticleContentDep {
public let htmlContent: String
public let highlights: [Highlight]
public let highlights: [HighlightDep]
public init(
htmlContent: String,
highlights: [Highlight]
highlights: [HighlightDep]
) {
self.htmlContent = htmlContent
self.highlights = highlights

View File

@ -28,7 +28,7 @@ public struct FeedItem: Identifiable, Hashable {
public let slug: String
public let isArchived: Bool
public let contentReader: String?
public var labels: [FeedItemLabel]
public var labels: [FeedItemLabelDep]
public init(
id: String,
@ -48,7 +48,7 @@ public struct FeedItem: Identifiable, Hashable {
slug: String,
isArchived: Bool,
contentReader: String?,
labels: [FeedItemLabel]
labels: [FeedItemLabelDep]
) {
self.id = id
self.title = title

View File

@ -1,6 +1,6 @@
import Foundation
public struct FeedItemLabel: Decodable, Hashable {
public struct FeedItemLabelDep: Decodable, Hashable {
public let id: String
public let name: String
public let color: String

View File

@ -1,7 +1,7 @@
import CoreData
import Foundation
public struct Highlight: Identifiable, Hashable, Codable {
public struct HighlightDep: Identifiable, Hashable, Codable {
public let id: String
public let shortId: String
public let quote: String
@ -54,8 +54,8 @@ public struct Highlight: Identifiable, Hashable, Codable {
return persistedHighlight
}
public static func make(from persistedHighlight: PersistedHighlight) -> Highlight {
Highlight(
public static func make(from persistedHighlight: PersistedHighlight) -> HighlightDep {
HighlightDep(
id: persistedHighlight.id ?? "",
shortId: persistedHighlight.shortId ?? "",
quote: persistedHighlight.quote ?? "",

View File

@ -76,13 +76,13 @@ public extension DataService {
}
}
func pageFromCache(slug: String) -> ArticleContent? {
func pageFromCache(slug: String) -> ArticleContentDep? {
let fetchRequest: NSFetchRequest<Models.PersistedArticleContent> = PersistedArticleContent.fetchRequest()
fetchRequest.predicate = NSPredicate(
format: "slug = %@", slug
)
if let htmlContent = try? persistentContainer.viewContext.fetch(fetchRequest).first?.htmlContent {
return ArticleContent(htmlContent: htmlContent, highlights: [])
return ArticleContentDep(htmlContent: htmlContent, highlights: [])
} else {
return nil
}

View File

@ -11,9 +11,9 @@ public extension DataService {
patch: String,
articleId: String,
annotation: String? = nil
) -> AnyPublisher<Highlight, BasicError> {
) -> AnyPublisher<HighlightDep, BasicError> {
enum MutationResult {
case saved(highlight: Highlight)
case saved(highlight: HighlightDep)
case error(errorCode: Enums.CreateHighlightErrorCode)
}

View File

@ -8,9 +8,9 @@ public extension DataService {
name: String,
color: String,
description: String?
) -> AnyPublisher<FeedItemLabel, BasicError> {
) -> AnyPublisher<FeedItemLabelDep, BasicError> {
enum MutationResult {
case saved(label: FeedItemLabel)
case saved(label: FeedItemLabelDep)
case error(errorCode: Enums.CreateLabelErrorCode)
}

View File

@ -12,9 +12,9 @@ public extension DataService {
patch: String,
articleId: String,
overlapHighlightIdList: [String]
) -> AnyPublisher<Highlight, BasicError> {
) -> AnyPublisher<HighlightDep, BasicError> {
enum MutationResult {
case saved(highlight: Highlight)
case saved(highlight: HighlightDep)
case error(errorCode: Enums.MergeHighlightErrorCode)
}

View File

@ -4,9 +4,9 @@ import Models
import SwiftGraphQL
public extension DataService {
func updateArticleLabelsPublisher(itemID: String, labelIDs: [String]) -> AnyPublisher<[FeedItemLabel], BasicError> {
func updateArticleLabelsPublisher(itemID: String, labelIDs: [String]) -> AnyPublisher<[FeedItemLabelDep], BasicError> {
enum MutationResult {
case saved(feedItem: [FeedItemLabel])
case saved(feedItem: [FeedItemLabelDep])
case error(errorCode: Enums.SetLabelsErrorCode)
}

View File

@ -8,9 +8,9 @@ public extension DataService {
highlightID: String,
annotation: String?,
sharedAt: Date?
) -> AnyPublisher<Highlight, BasicError> {
) -> AnyPublisher<HighlightDep, BasicError> {
enum MutationResult {
case saved(highlight: Highlight)
case saved(highlight: HighlightDep)
case error(errorCode: Enums.UpdateHighlightErrorCode)
}

View File

@ -4,14 +4,14 @@ import Models
import SwiftGraphQL
public extension DataService {
func articleContentPublisher(username: String, slug: String) -> AnyPublisher<ArticleContent, ServerError> {
func articleContentPublisher(username: String, slug: String) -> AnyPublisher<ArticleContentDep, ServerError> {
enum QueryResult {
case success(result: ArticleContent)
case success(result: ArticleContentDep)
case error(error: String)
}
let articleSelection = Selection.Article {
ArticleContent(
ArticleContentDep(
htmlContent: try $0.content(),
highlights: try $0.highlights(selection: highlightSelection.list)
)

View File

@ -4,9 +4,9 @@ import Models
import SwiftGraphQL
public extension DataService {
func labelsPublisher() -> AnyPublisher<[FeedItemLabel], ServerError> {
func labelsPublisher() -> AnyPublisher<[FeedItemLabelDep], ServerError> {
enum QueryResult {
case success(result: [FeedItemLabel])
case success(result: [FeedItemLabelDep])
case error(error: String)
}

View File

@ -4,14 +4,14 @@ import Models
import SwiftGraphQL
public extension DataService {
func pdfHighlightsPublisher(username: String, slug: String) -> AnyPublisher<[Highlight], ServerError> {
func pdfHighlightsPublisher(username: String, slug: String) -> AnyPublisher<[HighlightDep], ServerError> {
enum QueryResult {
case success(result: [Highlight])
case success(result: [HighlightDep])
case error(error: String)
}
let highlightSelection = Selection.Highlight {
Highlight(
HighlightDep(
id: try $0.id(),
shortId: try $0.shortId(),
quote: try $0.quote(),

View File

@ -2,7 +2,7 @@ import Models
import SwiftGraphQL
let feedItemLabelSelection = Selection.Label {
FeedItemLabel(
FeedItemLabelDep(
id: try $0.id(),
name: try $0.name(),
color: try $0.color(),

View File

@ -2,7 +2,7 @@ import Models
import SwiftGraphQL
let highlightSelection = Selection.Highlight {
Highlight(
HighlightDep(
id: try $0.id(),
shortId: try $0.shortId(),
quote: try $0.quote(),

View File

@ -4,17 +4,17 @@ import Foundation
import Models
public extension DataService {
func cachedHighlights(pdfID: String) -> [Highlight] {
func cachedHighlights(pdfID: String) -> [HighlightDep] {
let fetchRequest: NSFetchRequest<Models.PersistedHighlight> = PersistedHighlight.fetchRequest()
fetchRequest.predicate = NSPredicate(
format: "associatedItemId = %@ AND markedForDeletion = %@", pdfID, false
)
let highlights = (try? persistentContainer.viewContext.fetch(fetchRequest)) ?? []
return highlights.map { Highlight.make(from: $0) }
return highlights.map { HighlightDep.make(from: $0) }
}
func persistHighlight(pdfID: String, highlight: Highlight) {
func persistHighlight(pdfID: String, highlight: HighlightDep) {
_ = highlight.toManagedObject(
context: persistentContainer.viewContext,
associatedItemID: pdfID

View File

@ -8,7 +8,7 @@ public struct TextChip: View {
self.color = color
}
public init?(feedItemLabel: FeedItemLabel) {
public init?(feedItemLabel: FeedItemLabelDep) {
guard let color = Color(hex: feedItemLabel.color) else { return nil }
self.text = feedItemLabel.name
@ -41,7 +41,7 @@ public struct TextChipButton: View {
}
public static func makeRemovableLabelButton(
feedItemLabel: FeedItemLabel,
feedItemLabel: FeedItemLabelDep,
onTap: @escaping () -> Void
) -> TextChipButton {
TextChipButton(