fetch linked items from coredata when network call fails

This commit is contained in:
Satindar Dhillon
2022-04-23 09:06:03 -07:00
parent a63bf7928e
commit 46da1cd150
16 changed files with 35 additions and 37 deletions

View File

@ -60,6 +60,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
enableThreadSanitizer = "YES"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
@ -76,12 +77,13 @@
ReferencedContainer = "container:Omnivore.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "-com.apple.CoreData.ConcurrencyDebug 1"
<EnvironmentVariables>
<EnvironmentVariable
key = "com.apple.CoreData.ConcurrencyDebug"
value = "1"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
</EnvironmentVariable>
</EnvironmentVariables>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"

View File

@ -57,7 +57,7 @@ import Views
viewModel.loadItems(dataService: dataService, isRefresh: true)
}
}
// TODO: fix this
// TODO: -push-notification fix this
// .onReceive(NotificationCenter.default.publisher(for: Notification.Name("PushFeedItem"))) { notification in
// if let feedItem = notification.userInfo?["feedItem"] as? FeedItemD---ep {
// viewModel.pushFeedItem(item: feedItem)
@ -166,7 +166,11 @@ import Views
)
Button(action: {
withAnimation(.linear(duration: 0.4)) {
viewModel.setLinkArchived(dataService: dataService, linkId: item.unwrappedID, archived: !item.isArchived)
viewModel.setLinkArchived(
dataService: dataService,
linkId: item.unwrappedID,
archived: !item.isArchived
)
}
}, label: {
Label(

View File

@ -1,4 +1,5 @@
import Combine
import CoreData
import Models
import Services
import SwiftUI
@ -71,10 +72,15 @@ import Views
.sink(
receiveCompletion: { [weak self] completion in
guard case .failure = completion else { return }
self?.isLoading = false
// return cachedItems found in CoreData when request fails
// self?.items = dataService.cachedFeedItems() // TODO: fetch items from core data
self?.cursor = nil
dataService.viewContext.perform {
let fetchRequest: NSFetchRequest<Models.LinkedItem> = LinkedItem.fetchRequest()
fetchRequest.sortDescriptors = [NSSortDescriptor(keyPath: \LinkedItem.savedAt, ascending: false)]
if let fetchedItems = try? dataService.viewContext.fetch(fetchRequest) {
self?.items = fetchedItems
self?.cursor = nil
self?.isLoading = false
}
}
},
receiveValue: { [weak self] result in
// Search results aren't guaranteed to return in order so this
@ -200,7 +206,7 @@ import Views
}
func updateLabels(itemID _: String, labels _: [LinkedItemLabel]) {
// TODO: fix
// TODO: -labels fix
// // 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

@ -4,7 +4,7 @@ import Services
import SwiftUI
import Views
// TODO: fix file
// TODO: -labels fix file
final class LabelsViewModel: ObservableObject {
private var hasLoadedInitialLabels = false
@Published var isLoading = false

View File

@ -76,7 +76,7 @@ enum PDFProvider {
let urlRequest = URLRequest.webRequest(
baseURL: dataService.appEnvironment.webAppBaseURL,
urlPath: "/app/\(username)/\(item.slug)",
urlPath: "/app/\(username)/\(item.unwrappedSlug)",
queryParams: ["isAppEmbedView": "true", "highlightBarDisabled": isMacApp ? "false" : "true"]
)

View File

@ -11,7 +11,7 @@ public struct HomeFeedData {
}
}
// TODO: delete this
// TODO: -push-notification delete this?
// Internal model used for parsing a push notification object only
// struct JSONArticle: Decodable {
// let id: String

View File

@ -1 +0,0 @@
// TODO: delete file

View File

@ -47,7 +47,7 @@ public extension DataService {
switch payload.data {
case let .saved(label: label):
// TODO: update CoreData and fix this label thing
// TODO: -labels update CoreData and fix this label thing
// promise(.success(label))
promise(.failure(.message(messageText: "")))
case let .error(errorCode: errorCode):

View File

@ -37,7 +37,7 @@ public extension DataService {
switch payload.data {
case .success:
// TODO: update CoreData
// TODO: -labels update CoreData
promise(.success(true))
case .error:
promise(.failure(.message(messageText: "Error removing label")))

View File

@ -45,7 +45,7 @@ public extension DataService {
switch payload.data {
case let .saved(labels):
// TODO: update CoreData and fix dis
// TODO: -labels update CoreData and fix dis
promise(.failure(.message(messageText: "failed to set labels")))
// promise(.success(labels))
case .error:

View File

@ -5,6 +5,7 @@ import Models
import SwiftGraphQL
public extension DataService {
// swiftlint:disable function_body_length
func updateArticleReadingProgressPublisher(
itemID: String,
readingProgress: Double,

View File

@ -34,7 +34,7 @@ public extension DataService {
case let .success(payload):
switch payload.data {
case let .success(result: result):
// TODO: update CoreData and fix this
// TODO: -labels update CoreData and fix this
// promise(.success(result))
promise(.failure(.unknown))
case .error:

View File

@ -83,20 +83,6 @@ public extension DataService {
.receive(on: DispatchQueue.main)
.eraseToAnyPublisher()
}
// TODO: delete
// func cachedFeedItems() -> [FeedItem---D----ep] {
// var result = [FeedItem------D---ep]()
//
// backgroundContext.performAndWait {
// let fetchRequest: NSFetchRequest<Models.LinkedItem> = LinkedItem.fetchRequest()
// fetchRequest.sortDescriptors = [NSSortDescriptor(keyPath: \LinkedItem.savedAt, ascending: false)]
// let items = (try? backgroundContext.fetch(fetchRequest)) ?? []
// result = items.map { FeedItem-----D----ep.make(from: $0) }
// }
//
// return result
// }
}
let homeFeedItemSelection = Selection.Article {

View File

@ -75,7 +75,7 @@ struct InternalLinkedItem {
}
extension Sequence where Element == InternalLinkedItem {
// TODO: use batch update?
// TODO: -optimization use batch update?
func persist(context: NSManagedObjectContext) -> [LinkedItem]? {
var linkedItems: [LinkedItem]?
context.performAndWait {

View File

@ -32,7 +32,7 @@ public extension NSNotification {
return nil
}
// TODO: re-enable later
// TODO: -push-notification re-enable later
// static func pushFeedItem(feedItem: FeedItem-----D---ep) {
// NotificationCenter.default.post(name: NSNotification.PushFeedItem, object: nil, userInfo: ["feedItem": feedItem])
// }

View File

@ -55,7 +55,7 @@ extension AppDelegate: UNUserNotificationCenterDelegate {
withCompletionHandler completionHandler: @escaping () -> Void
) {
let userInfo = response.notification.request.content.userInfo
// TODO: fix
// TODO: -push-notification fix
// if let linkData = userInfo["link"] as? String {
// guard let jsonData = Data(base64Encoded: linkData) else { return }
// if let item = FeedItem---D--ep.fromJsonArticle(linkData: jsonData) {