SidebarView.swift 6.4 KB

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