DashboardWidgetView.swift 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // DashboardWidgetView.swift
  3. // Widget
  4. //
  5. // Created by Marino Faggiana on 20/08/22.
  6. // Copyright © 2022 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import SwiftUI
  24. import WidgetKit
  25. /*
  26. @Environment(\.colorScheme) var colorScheme
  27. var entry: Provider.Entry
  28. var bgColor: some View {
  29. colorScheme == .dark ? Color.red : Color.orange
  30. }
  31. var body: some View {
  32. ZStack {
  33. bgColor
  34. Text(entry.date, style: .time)
  35. }
  36. }
  37. */
  38. struct DashboardWidgetView: View {
  39. var entry: DashboardDataEntry
  40. let date = Date().formatted()
  41. var body: some View {
  42. VStack(alignment: .center) {
  43. Text("\(date)")
  44. .font(.title)
  45. .bold()
  46. VStack {
  47. ForEach(entry.dashboardDatas, id: \.id) { element in
  48. Link(destination: element.url) {
  49. HStack {
  50. Image(element.image)
  51. .resizable()
  52. .aspectRatio(contentMode: .fit)
  53. .frame(width: 40, height: 40)
  54. .clipShape(Circle())
  55. VStack(alignment: .leading) {
  56. Text(element.title)
  57. .font(.headline)
  58. Text(element.subTitle)
  59. .font(.subheadline)
  60. .foregroundColor(Color(white: 0.4745))
  61. }
  62. Spacer()
  63. }
  64. .padding(5)
  65. }
  66. }
  67. }
  68. }.padding(5)
  69. .redacted(reason: entry.isPlaceholder ? .placeholder : [])
  70. }
  71. }
  72. struct NCElementDashboard_Previews: PreviewProvider {
  73. static var previews: some View {
  74. let entry = DashboardDataEntry(date: Date(), dashboardDatas: dashboardDatasTest, isPlaceholder: false)
  75. DashboardWidgetView(entry: entry).previewContext(WidgetPreviewContext(family: .systemLarge))
  76. }
  77. }