SidebarView.swift 6.2 KB

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