@@ -26,6 +26,8 @@ struct CardView: View {
26
26
private var carouselWidth
27
27
@Environment ( \. homeActions)
28
28
private var homeActions
29
+ @Environment ( \. modelContext)
30
+ private var modelContext
29
31
30
32
@EnvironmentObject private var navigation : HomeNavigation
31
33
@@ -128,11 +130,9 @@ private extension CardView {
128
130
var externalDestination = false
129
131
if let slug = card. slug {
130
132
navigation. navigateTo ( NativeCollectionDestination ( slug: slug, givenURL: card. givenURL) )
131
- } else if let savedItem, // We are legally allowed to open the item in reader view
132
- savedItem. item? . isArticle == true , // except one of the following conditions is met:
133
- savedItem. item? . isVideo == false , // a) the item is not an article (i.e. it was not parseable)
134
- savedItem. item? . isImage == false { // b) the item is an image
135
- navigation. navigateTo ( ReadableDestination ( . saved( card. givenURL) , source: . app) ) // c) the item is a video
133
+ } else if savedItem != nil ,
134
+ isReaderSupported ( ) {
135
+ navigation. navigateTo ( ReadableDestination ( . saved( card. givenURL) , source: . app) )
136
136
} else if card. isSyndicated {
137
137
navigation. navigateTo ( ReadableDestination ( . syndicated( card. givenURL) , source: . app) )
138
138
} else if URL ( string: card. givenURL) != nil {
@@ -151,6 +151,20 @@ private extension CardView {
151
151
}
152
152
}
153
153
154
+ /// We are legally allowed to open the item in reader view except one of the following conditions is met:
155
+ /// a) the item is not an article (i.e. it was not parseable)
156
+ /// b) the item is an image
157
+ /// c) the item is a video
158
+ /// - Returns: true if we can open this item in the reader
159
+ func isReaderSupported( ) -> Bool {
160
+ let givenURL = card. givenURL
161
+ let fetchDescriptor = FetchDescriptor < Item > ( predicate: #Predicate< Item> { $0. givenURL == givenURL } )
162
+ guard let item = try ? modelContext. fetch ( fetchDescriptor) . first else {
163
+ return false
164
+ }
165
+ return item. isArticle == true && item. isImage == false && item. isVideo == false
166
+ }
167
+
154
168
/// Builds a Shared With You card, which is a sized card with an attribution view at the bottom
155
169
/// - Returns: the card view with the attribution view
156
170
func makeSharedWithYouCard( _ urlString: String ) -> some View {
0 commit comments