SettingsView.swift 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import SwiftUI
  2. struct SettingsView: View {
  3. @Bindable var viewModel: SettingsViewModel
  4. @Environment(AppearanceManager.self) private var appearance
  5. private enum Layout {
  6. static let horizontalPadding: CGFloat = 24
  7. }
  8. var body: some View {
  9. VStack(spacing: 0) {
  10. header
  11. ScrollView {
  12. VStack(alignment: .leading, spacing: 12) {
  13. appearanceSection
  14. shareSection
  15. linksSection
  16. }
  17. .frame(maxWidth: .infinity, alignment: .leading)
  18. .padding(.horizontal, Layout.horizontalPadding)
  19. .padding(.top, 12)
  20. .padding(.bottom, 24)
  21. }
  22. }
  23. .background(AppTheme.background)
  24. }
  25. private var header: some View {
  26. HStack(spacing: 14) {
  27. ModernSidebarIconView(kind: .settings, size: 40)
  28. VStack(alignment: .leading, spacing: 2) {
  29. Text("Settings")
  30. .font(.system(size: 18, weight: .semibold))
  31. .foregroundStyle(AppTheme.textPrimary)
  32. Text("Manage app preferences")
  33. .font(.system(size: 11))
  34. .foregroundStyle(AppTheme.textSecondary)
  35. }
  36. Spacer()
  37. }
  38. .padding(.horizontal, 24)
  39. .padding(.vertical, 16)
  40. .overlay(alignment: .bottom) {
  41. Rectangle()
  42. .fill(AppTheme.border)
  43. .frame(height: 1)
  44. }
  45. }
  46. private var appearanceSection: some View {
  47. PostFormCard(
  48. title: "Appearance",
  49. subtitle: "Customize how the app looks"
  50. ) {
  51. SettingsToggleRow(
  52. icon: "moon.fill",
  53. title: "Dark Mode",
  54. subtitle: appearance.isDarkMode ? "On" : "Off",
  55. isOn: Binding(
  56. get: { appearance.isDarkMode },
  57. set: { appearance.isDarkMode = $0 }
  58. )
  59. )
  60. }
  61. }
  62. private var shareSection: some View {
  63. PostFormCard(
  64. title: "Share",
  65. subtitle: "Spread the word about \(AppLinks.appName)"
  66. ) {
  67. SettingsShareAppButton(
  68. message: viewModel.shareMessage,
  69. url: viewModel.shareURL
  70. )
  71. }
  72. }
  73. private var linksSection: some View {
  74. PostFormCard(
  75. title: "About",
  76. subtitle: "Website, legal, and help resources"
  77. ) {
  78. VStack(spacing: 8) {
  79. SettingsLinkRow(
  80. icon: "globe",
  81. title: "Website",
  82. subtitle: AppLinks.website.host
  83. ) {
  84. viewModel.openWebsite()
  85. }
  86. SettingsLinkRow(
  87. icon: "hand.raised.fill",
  88. title: "Privacy Policy",
  89. subtitle: "How we handle your data"
  90. ) {
  91. viewModel.openPrivacyPolicy()
  92. }
  93. SettingsLinkRow(
  94. icon: "doc.text.fill",
  95. title: "Terms & Conditions",
  96. subtitle: "Terms of service"
  97. ) {
  98. viewModel.openTermsAndConditions()
  99. }
  100. SettingsLinkRow(
  101. icon: "lifepreserver.fill",
  102. title: "Support",
  103. subtitle: "Get help or send feedback"
  104. ) {
  105. viewModel.openSupport()
  106. }
  107. }
  108. }
  109. }
  110. }
  111. #Preview {
  112. SettingsView(viewModel: SettingsViewModel())
  113. .environment(AppearanceManager.shared)
  114. .frame(width: 800, height: 600)
  115. }