Skip to content

Commit 3c0d668

Browse files
committed
Code clean up
1 parent 5b33b7f commit 3c0d668

File tree

2 files changed

+0
-100
lines changed

2 files changed

+0
-100
lines changed

PG5602_H24-4/Views/ArticleDetailedView.swift

-3
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,12 @@ struct ArticleDetailView: View {
166166
if let category = selectedCategory {
167167
category.articles.append(storedArticle);
168168
modelContext.insert(category);
169-
print("Saved article in category: \(category.name)")
170-
print("Category now has \(category.articles.count) articles.")
171169
}
172170

173171
modelContext.insert(storedArticle)
174172
do {
175173
try modelContext.save()
176174
isArticleSaved = true
177-
saveMessasge = "Article saved successfully with category!"
178175
} catch {
179176
saveMessasge = "Failed to save article: \(error.localizedDescription)"
180177
}

PG5602_H24-4/Views/ArticlesView.swift

-97
Original file line numberDiff line numberDiff line change
@@ -8,103 +8,6 @@
88
import SwiftUI
99
import SwiftData
1010

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-
10811
struct ArticlesView: View {
10912
@Environment(\.modelContext) var modelContext
11013
@Query(sort: \Article.savedDate, order: .reverse) var storedArticles: [Article]

0 commit comments

Comments
 (0)