Explorar el Código

add reacted

Signed-off-by: marinofaggiana <marino.faggiana@nextcloud.com>
marinofaggiana hace 2 años
padre
commit
c7461c9bd7

+ 1 - 0
Widget/DashboardData.swift

@@ -34,4 +34,5 @@ struct DashboardData: Identifiable, Codable, Hashable {
 struct DashboardDataEntry: TimelineEntry {
     let date: Date
     let dashboardDatas: [DashboardData]
+    let isPlaceholder: Bool
 }

+ 8 - 8
Widget/DashboardNetworking.swift

@@ -25,18 +25,18 @@ import Foundation
 import NextcloudKit
 
 let dashboardDatasTest: [DashboardData] = [
-    .init(id: 0, image: "nextcloud", title: "title 1", subTitle: "subTitle 1", url: URL(string: "https://nextcloud.com/")!),
-    .init(id: 1, image: "nextcloud", title: "title 2", subTitle: "subTitle 2", url: URL(string: "https://nextcloud.com/")!),
-    .init(id: 2, image: "nextcloud", title: "title 3", subTitle: "subTitle 3", url: URL(string: "https://nextcloud.com/")!),
-    .init(id: 3, image: "nextcloud", title: "title 4", subTitle: "subTitle 4", url: URL(string: "https://nextcloud.com/")!),
-    .init(id: 4, image: "nextcloud", title: "title 5", subTitle: "subTitle 5", url: URL(string: "https://nextcloud.com/")!)
+    .init(id: 0, image: "nextcloud", title: "title 1", subTitle: "subTitle - description 1", url: URL(string: "https://nextcloud.com/")!),
+    .init(id: 1, image: "nextcloud", title: "title 2", subTitle: "subTitle - description 2", url: URL(string: "https://nextcloud.com/")!),
+    .init(id: 2, image: "nextcloud", title: "title 3", subTitle: "subTitle - description 3", url: URL(string: "https://nextcloud.com/")!),
+    .init(id: 3, image: "nextcloud", title: "title 4", subTitle: "subTitle - description 4", url: URL(string: "https://nextcloud.com/")!),
+    .init(id: 4, image: "nextcloud", title: "title 5", subTitle: "subTitle - description 5", url: URL(string: "https://nextcloud.com/")!)
 ]
 
-func readDashboard(completion: @escaping (_ dashboardData: [DashboardData]) -> Void) {
+func readDashboard(completion: @escaping (_ dashboardData: [DashboardData], _ isPlaceholder: Bool) -> Void) {
 
     guard let activeAccount = NCManageDatabase.shared.getActiveAccount() else {
-        return completion(dashboardDatasTest)
+        return completion(dashboardDatasTest, true)
     }
 
-    completion(dashboardDatasTest)
+    completion(dashboardDatasTest, false)
 }

+ 2 - 40
Widget/DashboardWidgetView.swift

@@ -43,47 +43,8 @@ import WidgetKit
 
 struct DashboardWidgetView: View {
     var entry: DashboardDataEntry
-    var placeholderColor = Color(red: 0.9, green: 0.9, blue: 0.92)
     let date = Date().formatted()
-
     var body: some View {
-        switch entry.dashboardDatas.isEmpty {
-        case true:
-            emptyDasboardView
-        case false:
-            bodyDasboardView
-        }
-    }
-
-    var emptyDasboardView: some View {
-        VStack(alignment: .center) {
-            Text("")
-                .frame(maxWidth: 280, minHeight: 20)
-                .background(placeholderColor)
-                .padding(5)
-            VStack {
-                ForEach(1...5, id: \.self) { _ in
-                    HStack {
-                        Image(systemName: "circle.fill")
-                            .font(.system(size: 40.0))
-                            .foregroundColor(placeholderColor)
-                        VStack(alignment: .leading, spacing: 5) {
-                            Text("")
-                                .frame(maxWidth: .infinity)
-                                .background(placeholderColor)
-                            Text("")
-                                .frame(maxWidth: .infinity)
-                                .background(placeholderColor)
-                        }
-                        Spacer()
-                    }
-                    .padding(5)
-                }
-            }
-        }.padding(5)
-    }
-
-    var bodyDasboardView: some View {
         VStack(alignment: .center) {
             Text("\(date)")
                 .font(.title)
@@ -111,12 +72,13 @@ struct DashboardWidgetView: View {
                 }
             }
         }.padding(5)
+            .redacted(reason: entry.isPlaceholder ? .placeholder : [])
     }
 }
 
 struct NCElementDashboard_Previews: PreviewProvider {
     static var previews: some View {
-        let entry = DashboardDataEntry(date: Date(), dashboardDatas: []) // dashboardDatasTest
+        let entry = DashboardDataEntry(date: Date(), dashboardDatas: dashboardDatasTest, isPlaceholder: false)
         DashboardWidgetView(entry: entry).previewContext(WidgetPreviewContext(family: .systemLarge))
     }
 }

+ 6 - 22
Widget/Widget.swift

@@ -29,34 +29,18 @@ struct Provider: TimelineProvider {
     typealias Entry = DashboardDataEntry
 
     func placeholder(in context: Context) -> Entry {
-        return Entry(date: Date(), dashboardDatas: [])
+        return Entry(date: Date(), dashboardDatas: [], isPlaceholder: true)
     }
 
     func getSnapshot(in context: Context, completion: @escaping (Entry) -> Void) {
-        readDashboard { dashboardDatas in
-            completion(Entry(date: Date(), dashboardDatas: dashboardDatas))
+        readDashboard { dashboardDatas, isPlaceholder in
+            completion(Entry(date: Date(), dashboardDatas: dashboardDatas, isPlaceholder: isPlaceholder))
         }
     }
 
-    /*
-     func getTimeline(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
-                 var entries = [SimpleEntry]()
-                 let currentDate = Date()
-                 let midnight = Calendar.current.startOfDay(for: currentDate)
-                 let nextMidnight = Calendar.current.date(byAdding: .day, value: 1, to: midnight)!
-                 for offset in 0 ..< 60 * 24 {
-                     let entryDate = Calendar.current.date(byAdding: .minute, value: offset, to: midnight)!
-                     entries.append(SimpleEntry(date: entryDate))
-                 }
-
-                 let timeline = Timeline(entries: entries, policy: .after(nextMidnight))
-                 completion(timeline)
-             }
-     */
-    
     func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> Void) {
-        readDashboard { dashboardDatas in
-            let timeLine = Timeline(entries: [Entry(date: Date(), dashboardDatas: dashboardDatas)], policy: .atEnd)
+        readDashboard { dashboardDatas, isPlaceholder in
+            let timeLine = Timeline(entries: [Entry(date: Date(), dashboardDatas: dashboardDatas, isPlaceholder: isPlaceholder)], policy: .atEnd)
             completion(timeLine)
         }
     }
@@ -79,7 +63,7 @@ struct DashboardWidget: Widget {
 struct DashboardWidget_Previews: PreviewProvider {
 
     static var previews: some View {
-        let entry = DashboardDataEntry(date: Date(), dashboardDatas: dashboardDatasTest)
+        let entry = DashboardDataEntry(date: Date(), dashboardDatas: dashboardDatasTest, isPlaceholder: false)
         DashboardWidgetView(entry: entry).previewContext(WidgetPreviewContext(family: .systemLarge))
     }
 }