SidebarView.swift 5.9 KB

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