SidebarView.swift 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import SwiftUI
  2. struct SidebarView: View {
  3. @Environment(\.requirePremiumAccess) private var requirePremiumAccess
  4. @EnvironmentObject private var subscriptions: SubscriptionManager
  5. @Bindable var viewModel: FrontPageViewModel
  6. var isPremium: Bool
  7. var body: some View {
  8. VStack(spacing: 0) {
  9. header
  10. navigationSections
  11. Spacer(minLength: 0)
  12. upgradeCard
  13. }
  14. .frame(width: AppTheme.sidebarWidth)
  15. .frame(maxHeight: .infinity, alignment: .top)
  16. .background(AppTheme.sidebarBackground)
  17. }
  18. private var header: some View {
  19. HStack(spacing: AppTheme.sidebarRowSpacing) {
  20. Image("AppLogo")
  21. .resizable()
  22. .interpolation(.high)
  23. .scaledToFit()
  24. .frame(width: AppTheme.iconContainerSize, height: AppTheme.iconContainerSize)
  25. VStack(alignment: .leading, spacing: 2) {
  26. Text("Reddora AI")
  27. .font(.system(size: 15, weight: .bold))
  28. .foregroundStyle(AppTheme.textPrimary)
  29. Text("AI Assistant for Reddit")
  30. .font(.system(size: 10))
  31. .foregroundStyle(AppTheme.textSecondary)
  32. }
  33. Spacer(minLength: 0)
  34. }
  35. .padding(.horizontal, AppTheme.sidebarContentInset + AppTheme.sidebarRowPaddingH)
  36. .padding(.top, 20)
  37. .padding(.bottom, 16)
  38. }
  39. private var navigationSections: some View {
  40. ScrollView {
  41. VStack(alignment: .leading, spacing: AppTheme.sidebarSectionSpacing) {
  42. sidebarSection(title: SidebarSection.quickAccess.rawValue) {
  43. SidebarQuickAccessItemView(isSelected: viewModel.isRedditActive) {
  44. guard requirePremiumAccess() else { return }
  45. viewModel.openReddit()
  46. }
  47. }
  48. sidebarSection(title: SidebarSection.create.rawValue) {
  49. ForEach(viewModel.createItems) { item in
  50. SidebarNavItemView(
  51. item: item,
  52. isSelected: !viewModel.isSettingsActive && !viewModel.isHistoryActive && !viewModel.isRedditActive && viewModel.selectedNavItem == item
  53. ) {
  54. viewModel.selectNavItem(item)
  55. }
  56. }
  57. }
  58. sidebarSection(title: SidebarSection.history.rawValue) {
  59. SidebarNavItemView(
  60. item: FrontPageViewModel.historyItem,
  61. isSelected: viewModel.isHistoryActive
  62. ) {
  63. viewModel.openHistory()
  64. }
  65. }
  66. sidebarSection(title: SidebarSection.settings.rawValue) {
  67. SidebarNavItemView(
  68. item: FrontPageViewModel.settingsItem,
  69. isSelected: viewModel.isSettingsActive
  70. ) {
  71. viewModel.openSettings()
  72. }
  73. }
  74. }
  75. .padding(.horizontal, AppTheme.sidebarContentInset)
  76. .padding(.top, 4)
  77. }
  78. }
  79. private func sidebarSection<Content: View>(
  80. title: String,
  81. @ViewBuilder content: () -> Content
  82. ) -> some View {
  83. VStack(alignment: .leading, spacing: AppTheme.sidebarItemSpacing) {
  84. SidebarSectionHeader(title: title)
  85. content()
  86. }
  87. }
  88. private var upgradeCard: some View {
  89. VStack(spacing: 0) {
  90. Rectangle()
  91. .fill(AppTheme.border)
  92. .frame(height: 1)
  93. VStack(alignment: .center, spacing: 8) {
  94. VStack(spacing: 4) {
  95. Image(systemName: "crown.fill")
  96. .font(.system(size: 14))
  97. .foregroundStyle(AppTheme.accentYellow)
  98. Text(isPremium ? "Reddora Premium" : "Upgrade to Premium")
  99. .font(.system(size: 12, weight: .semibold))
  100. .foregroundStyle(AppTheme.textPrimary)
  101. }
  102. .frame(maxWidth: .infinity, alignment: .center)
  103. Text(
  104. isPremium
  105. ? "You have unlimited AI generations and all premium features."
  106. : "Unlock unlimited AI generations and advanced analytics"
  107. )
  108. .font(.system(size: 10))
  109. .foregroundStyle(AppTheme.textSecondary)
  110. .multilineTextAlignment(.center)
  111. .frame(maxWidth: .infinity, alignment: .center)
  112. .fixedSize(horizontal: false, vertical: true)
  113. .lineSpacing(2)
  114. Button(isPremium ? "Manage Subscription" : "Upgrade Now") {
  115. if isPremium, subscriptions.hasLifetimeAccess {
  116. subscriptions.openSubscriptionManagement()
  117. } else {
  118. viewModel.showPaywall()
  119. }
  120. }
  121. .font(.system(size: 11, weight: .semibold))
  122. .foregroundStyle(.white)
  123. .frame(maxWidth: .infinity)
  124. .padding(.vertical, 7.5)
  125. .background(AppTheme.accentPurple)
  126. .clipShape(RoundedRectangle(cornerRadius: 8))
  127. .buttonStyle(AppPrimaryButtonStyle())
  128. }
  129. .frame(maxWidth: .infinity, minHeight: 105)
  130. .padding(.horizontal, 12)
  131. .padding(.vertical, 12)
  132. .background(
  133. RoundedRectangle(cornerRadius: AppTheme.cornerRadiusSmall)
  134. .fill(AppTheme.cardBackground)
  135. .overlay(
  136. RoundedRectangle(cornerRadius: AppTheme.cornerRadiusSmall)
  137. .stroke(AppTheme.accentPurple.opacity(0.25), lineWidth: 1)
  138. )
  139. )
  140. .padding(.horizontal, AppTheme.sidebarContentInset + 8)
  141. .padding(.top, 12)
  142. .padding(.bottom, 20)
  143. }
  144. }
  145. }