SidebarView.swift 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. .overlay(alignment: .trailing) {
  15. Rectangle()
  16. .fill(AppTheme.border)
  17. .frame(width: 1)
  18. }
  19. }
  20. private var header: some View {
  21. HStack(spacing: AppTheme.sidebarRowSpacing) {
  22. ZStack {
  23. RoundedRectangle(cornerRadius: 10)
  24. .fill(
  25. LinearGradient(
  26. colors: [AppTheme.accentPurpleLight, AppTheme.accentPurple],
  27. startPoint: .topLeading,
  28. endPoint: .bottomTrailing
  29. )
  30. )
  31. .frame(width: AppTheme.iconContainerSize, height: AppTheme.iconContainerSize)
  32. Image(systemName: "brain.head.profile")
  33. .font(.system(size: 14, weight: .semibold))
  34. .foregroundStyle(.white)
  35. }
  36. .frame(width: AppTheme.iconContainerSize, height: AppTheme.iconContainerSize)
  37. VStack(alignment: .leading, spacing: 2) {
  38. Text("Reddora AI")
  39. .font(.system(size: 15, weight: .bold))
  40. .foregroundStyle(AppTheme.textPrimary)
  41. Text("AI Assistant for Reddit")
  42. .font(.system(size: 10))
  43. .foregroundStyle(AppTheme.textSecondary)
  44. }
  45. Spacer(minLength: 0)
  46. }
  47. .padding(.horizontal, AppTheme.sidebarContentInset + AppTheme.sidebarRowPaddingH)
  48. .padding(.top, 20)
  49. .padding(.bottom, 16)
  50. }
  51. private var navigationSections: some View {
  52. ScrollView {
  53. VStack(alignment: .leading, spacing: AppTheme.sidebarSectionSpacing) {
  54. sidebarSection(title: SidebarSection.quickAccess.rawValue) {
  55. SidebarQuickAccessItemView(isSelected: viewModel.isRedditActive) {
  56. viewModel.openReddit()
  57. }
  58. }
  59. sidebarSection(title: SidebarSection.create.rawValue) {
  60. ForEach(viewModel.createItems) { item in
  61. SidebarNavItemView(
  62. item: item,
  63. isSelected: !viewModel.isSettingsActive && !viewModel.isRedditActive && viewModel.selectedNavItem == item
  64. ) {
  65. viewModel.selectNavItem(item)
  66. }
  67. }
  68. }
  69. sidebarSection(title: SidebarSection.settings.rawValue) {
  70. SidebarNavItemView(
  71. item: FrontPageViewModel.settingsItem,
  72. isSelected: viewModel.isSettingsActive
  73. ) {
  74. viewModel.openSettings()
  75. }
  76. }
  77. }
  78. .padding(.horizontal, AppTheme.sidebarContentInset)
  79. .padding(.top, 4)
  80. }
  81. }
  82. private func sidebarSection<Content: View>(
  83. title: String,
  84. @ViewBuilder content: () -> Content
  85. ) -> some View {
  86. VStack(alignment: .leading, spacing: AppTheme.sidebarItemSpacing) {
  87. SidebarSectionHeader(title: title)
  88. content()
  89. }
  90. }
  91. private var upgradeCard: some View {
  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. .overlay(alignment: .top) {
  139. Rectangle()
  140. .fill(AppTheme.border)
  141. .frame(height: 1)
  142. }
  143. }
  144. }