|
8 | 8 | import SwiftUI
|
9 | 9 | import SwiftData
|
10 | 10 |
|
11 |
| -//struct ArticlesView: View { |
12 |
| -// @Environment(\.modelContext) var modelContext |
13 |
| -// @Query(sort: \Article.savedDate, order: .reverse) var storedArticles: [Article] |
14 |
| -// @State var selectedArticle: NewsArticle? |
15 |
| -// @State var selectedCategory = "All" |
16 |
| -// let defaultCategories = ["Technology", "Economy", "Politics", "Sports", "News"] |
17 |
| -// |
18 |
| -// @AppStorage("tickerPosition") var tickerPosition = "Top" |
19 |
| -// @AppStorage("isTickerActive") var isTickerActive = false |
20 |
| -// |
21 |
| -// var filteredArticles: [Article] { |
22 |
| -// if selectedCategory == "All" { |
23 |
| -// return storedArticles |
24 |
| -// } |
25 |
| -// return storedArticles.filter { article in |
26 |
| -// if let categoryName = article.category?.name { |
27 |
| -// return categoryName == selectedCategory |
28 |
| -// } |
29 |
| -// return false |
30 |
| -// } |
31 |
| -// } |
32 |
| -// |
33 |
| -// var body: some View { |
34 |
| -// |
35 |
| -// NavigationView { |
36 |
| -// if storedArticles.isEmpty { |
37 |
| -// VStack { |
38 |
| -// Image(systemName: "square.stack.3d.up.slash") |
39 |
| -// .resizable() |
40 |
| -// .frame(width: 70, height: 70) |
41 |
| -// .padding() |
42 |
| -// |
43 |
| -// Text("No articles are saved.") |
44 |
| -// .font(.title) |
45 |
| -// .fontWeight(.bold) |
46 |
| -// .foregroundStyle(.primary) |
47 |
| -// .padding(.bottom, 2) |
48 |
| -// |
49 |
| -// Text("Please go to search and fetch articles and news from the internet.") |
50 |
| -// .font(.body) |
51 |
| -// .foregroundStyle(.secondary) |
52 |
| -// .multilineTextAlignment(.center) |
53 |
| -// .padding(.horizontal, 30) |
54 |
| -// } |
55 |
| -// .frame(maxWidth: .infinity, maxHeight: .infinity) |
56 |
| -// .background(Color(UIColor.systemBackground)) |
57 |
| -// } else { |
58 |
| -// List { |
59 |
| -// ForEach(storedArticles) { article in |
60 |
| -// NavigationLink(destination: ArticleDetailView(article: article.toNewsArticle())) { |
61 |
| -// VStack(alignment: .leading) { |
62 |
| -// Text(article.title) |
63 |
| -// .font(.headline) |
64 |
| -// if let description = article.articleDescription { |
65 |
| -// Text(description) |
66 |
| -// .font(.subheadline) |
67 |
| -// .foregroundStyle(.secondary) |
68 |
| -// } |
69 |
| -// } |
70 |
| -// } |
71 |
| -// } |
72 |
| -// .onDelete(perform: deleteArticle) |
73 |
| -// } |
74 |
| -// .navigationTitle("Your stored articles") |
75 |
| -// .toolbar { |
76 |
| -// ToolbarItem(placement: .navigationBarTrailing) { |
77 |
| -// Menu { |
78 |
| -// ForEach(defaultCategories, id: \.self) { category in |
79 |
| -// Button(action: { |
80 |
| -// selectedCategory = category |
81 |
| -// }) |
82 |
| -// { Text(category) |
83 |
| -// if selectedCategory == category { |
84 |
| -// Image(systemName: "checkmark") |
85 |
| -// } |
86 |
| -// } |
87 |
| -// } |
88 |
| -// } |
89 |
| -// label: { |
90 |
| -// Image(systemName: "ellipsis.circle") |
91 |
| -// .imageScale(.large) |
92 |
| -// } |
93 |
| -// } |
94 |
| -// } |
95 |
| -// } |
96 |
| -// } |
97 |
| -// } |
98 |
| -// |
99 |
| -// func deleteArticle(at offsets: IndexSet) { |
100 |
| -// for index in offsets { |
101 |
| -// let article = storedArticles[index] |
102 |
| -// article.deleteFromDatabase(context: modelContext) |
103 |
| -// } |
104 |
| -// } |
105 |
| -//} |
106 |
| - |
107 |
| - |
108 | 11 | struct ArticlesView: View {
|
109 | 12 | @Environment(\.modelContext) var modelContext
|
110 | 13 | @Query(sort: \Article.savedDate, order: .reverse) var storedArticles: [Article]
|
|
0 commit comments