SidebarView.swift 6.3 KB

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