mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
add lables to feedItem type
This commit is contained in:
parent
ef4e243f87
commit
caefa364a8
4 changed files with 114 additions and 9 deletions
|
|
@ -28,6 +28,7 @@ public struct FeedItem: Identifiable, Hashable, Decodable {
|
|||
public let slug: String
|
||||
public let isArchived: Bool
|
||||
public let contentReader: String?
|
||||
public let labels: [FeedItemLabel]
|
||||
|
||||
public init(
|
||||
id: String,
|
||||
|
|
@ -46,7 +47,8 @@ public struct FeedItem: Identifiable, Hashable, Decodable {
|
|||
publishDate: Date?,
|
||||
slug: String,
|
||||
isArchived: Bool,
|
||||
contentReader: String?
|
||||
contentReader: String?,
|
||||
labels: [FeedItemLabel]
|
||||
) {
|
||||
self.id = id
|
||||
self.title = title
|
||||
|
|
@ -65,10 +67,12 @@ public struct FeedItem: Identifiable, Hashable, Decodable {
|
|||
self.slug = slug
|
||||
self.isArchived = isArchived
|
||||
self.contentReader = contentReader
|
||||
self.labels = labels
|
||||
}
|
||||
|
||||
// swiftlint:disable:next line_length
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case id, title, createdAt, savedAt, image, isArchived, readingProgressPercent, readingProgressAnchorIndex, slug, contentReader, url
|
||||
case id, title, createdAt, savedAt, image, isArchived, readingProgressPercent, readingProgressAnchorIndex, slug, contentReader, url, labels
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
|
|
@ -85,6 +89,7 @@ public struct FeedItem: Identifiable, Hashable, Decodable {
|
|||
contentReader = try container.decode(String.self, forKey: .contentReader)
|
||||
pageURLString = try container.decode(String.self, forKey: .url)
|
||||
isArchived = try container.decode(Bool.self, forKey: .isArchived)
|
||||
labels = try container.decode([FeedItemLabel].self, forKey: .labels)
|
||||
|
||||
self.onDeviceImageURLString = nil
|
||||
self.documentDirectoryPath = nil
|
||||
|
|
|
|||
23
apple/OmnivoreKit/Sources/Models/FeedItemLabel.swift
Normal file
23
apple/OmnivoreKit/Sources/Models/FeedItemLabel.swift
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import Foundation
|
||||
|
||||
public struct FeedItemLabel: Decodable, Hashable {
|
||||
public let id: String
|
||||
public let name: String
|
||||
public let color: String
|
||||
public let createdAt: Date?
|
||||
public let description: String?
|
||||
|
||||
public init(
|
||||
id: String,
|
||||
name: String,
|
||||
color: String,
|
||||
createdAt: Date?,
|
||||
description: String?
|
||||
) {
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.color = color
|
||||
self.createdAt = createdAt
|
||||
self.description = description
|
||||
}
|
||||
}
|
||||
|
|
@ -2970,8 +2970,11 @@ extension Objects {
|
|||
let savedByViewer: [String: Bool]
|
||||
let shareInfo: [String: Objects.LinkShareInfo]
|
||||
let sharedComment: [String: String]
|
||||
let siteIcon: [String: String]
|
||||
let siteName: [String: String]
|
||||
let slug: [String: String]
|
||||
let title: [String: String]
|
||||
let uploadFileId: [String: String]
|
||||
let url: [String: String]
|
||||
|
||||
enum TypeName: String, Codable {
|
||||
|
|
@ -3088,6 +3091,14 @@ extension Objects.Article: Decodable {
|
|||
if let value = try container.decode(String?.self, forKey: codingKey) {
|
||||
map.set(key: field, hash: alias, value: value as Any)
|
||||
}
|
||||
case "siteIcon":
|
||||
if let value = try container.decode(String?.self, forKey: codingKey) {
|
||||
map.set(key: field, hash: alias, value: value as Any)
|
||||
}
|
||||
case "siteName":
|
||||
if let value = try container.decode(String?.self, forKey: codingKey) {
|
||||
map.set(key: field, hash: alias, value: value as Any)
|
||||
}
|
||||
case "slug":
|
||||
if let value = try container.decode(String?.self, forKey: codingKey) {
|
||||
map.set(key: field, hash: alias, value: value as Any)
|
||||
|
|
@ -3096,6 +3107,10 @@ extension Objects.Article: Decodable {
|
|||
if let value = try container.decode(String?.self, forKey: codingKey) {
|
||||
map.set(key: field, hash: alias, value: value as Any)
|
||||
}
|
||||
case "uploadFileId":
|
||||
if let value = try container.decode(String?.self, forKey: codingKey) {
|
||||
map.set(key: field, hash: alias, value: value as Any)
|
||||
}
|
||||
case "url":
|
||||
if let value = try container.decode(String?.self, forKey: codingKey) {
|
||||
map.set(key: field, hash: alias, value: value as Any)
|
||||
|
|
@ -3134,8 +3149,11 @@ extension Objects.Article: Decodable {
|
|||
savedByViewer = map["savedByViewer"]
|
||||
shareInfo = map["shareInfo"]
|
||||
sharedComment = map["sharedComment"]
|
||||
siteIcon = map["siteIcon"]
|
||||
siteName = map["siteName"]
|
||||
slug = map["slug"]
|
||||
title = map["title"]
|
||||
uploadFileId = map["uploadFileId"]
|
||||
url = map["url"]
|
||||
}
|
||||
}
|
||||
|
|
@ -3587,6 +3605,51 @@ extension Fields where TypeLock == Objects.Article {
|
|||
return selection.mock()
|
||||
}
|
||||
}
|
||||
|
||||
func uploadFileId() throws -> String? {
|
||||
let field = GraphQLField.leaf(
|
||||
name: "uploadFileId",
|
||||
arguments: []
|
||||
)
|
||||
select(field)
|
||||
|
||||
switch response {
|
||||
case let .decoding(data):
|
||||
return data.uploadFileId[field.alias!]
|
||||
case .mocking:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func siteName() throws -> String? {
|
||||
let field = GraphQLField.leaf(
|
||||
name: "siteName",
|
||||
arguments: []
|
||||
)
|
||||
select(field)
|
||||
|
||||
switch response {
|
||||
case let .decoding(data):
|
||||
return data.siteName[field.alias!]
|
||||
case .mocking:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func siteIcon() throws -> String? {
|
||||
let field = GraphQLField.leaf(
|
||||
name: "siteIcon",
|
||||
arguments: []
|
||||
)
|
||||
select(field)
|
||||
|
||||
switch response {
|
||||
case let .decoding(data):
|
||||
return data.siteIcon[field.alias!]
|
||||
case .mocking:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Selection where TypeLock == Never, Type == Never {
|
||||
|
|
@ -10784,7 +10847,7 @@ extension Fields where TypeLock == Objects.Label {
|
|||
}
|
||||
}
|
||||
|
||||
func createdAt() throws -> DateTime {
|
||||
func createdAt() throws -> DateTime? {
|
||||
let field = GraphQLField.leaf(
|
||||
name: "createdAt",
|
||||
arguments: []
|
||||
|
|
@ -10793,12 +10856,9 @@ extension Fields where TypeLock == Objects.Label {
|
|||
|
||||
switch response {
|
||||
case let .decoding(data):
|
||||
if let data = data.createdAt[field.alias!] {
|
||||
return data
|
||||
}
|
||||
throw HttpError.badpayload
|
||||
return data.createdAt[field.alias!]
|
||||
case .mocking:
|
||||
return DateTime.mockValue
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -16779,6 +16839,10 @@ extension Enums {
|
|||
/// SortBy
|
||||
enum SortBy: String, CaseIterable, Codable {
|
||||
case updatedTime = "UPDATED_TIME"
|
||||
|
||||
case score = "SCORE"
|
||||
|
||||
case savedAt = "SAVED_AT"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -16956,6 +17020,8 @@ extension Enums {
|
|||
case payloadTooLarge = "PAYLOAD_TOO_LARGE"
|
||||
|
||||
case uploadFileMissing = "UPLOAD_FILE_MISSING"
|
||||
|
||||
case elasticError = "ELASTIC_ERROR"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -143,7 +143,18 @@ let homeFeedItemSelection = Selection.Article {
|
|||
publishDate: try $0.publishedAt()?.value,
|
||||
slug: try $0.slug(),
|
||||
isArchived: try $0.isArchived(),
|
||||
contentReader: try $0.contentReader().rawValue
|
||||
contentReader: try $0.contentReader().rawValue,
|
||||
labels: try $0.labels(selection: feedItemLabelSelection.list.nullable) ?? []
|
||||
)
|
||||
}
|
||||
|
||||
private let feedItemLabelSelection = Selection.Label {
|
||||
FeedItemLabel(
|
||||
id: try $0.id(),
|
||||
name: try $0.name(),
|
||||
color: try $0.color(),
|
||||
createdAt: try $0.createdAt()?.value,
|
||||
description: try $0.description()
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue