SidebarView.swift 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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.isRedditActive && viewModel.selectedNavItem == item
  59. ) {
  60. viewModel.selectNavItem(item)
  61. }
  62. }
  63. }
  64. sidebarSection(title: SidebarSection.settings.rawValue) {
  65. SidebarNavItemView(
  66. item: FrontPageViewModel.settingsItem,
  67. isSelected: viewModel.isSettingsActive
  68. ) {
  69. viewModel.openSettings()
  70. }
  71. }
  72. }
  73. .padding(.horizontal, AppTheme.sidebarContentInset)
  74. .padding(.top, 4)
  75. }
  76. }
  77. private func sidebarSection<Content: View>(
  78. title: String,
  79. @ViewBuilder content: () -> Content
  80. ) -> some View {
  81. VStack(alignment: .leading, spacing: AppTheme.sidebarItemSpacing) {
  82. SidebarSectionHeader(title: title)
  83. content()
  84. }
  85. }
  86. private var upgradeCard: some View {
  87. VStack(spacing: 0) {
  88. Rectangle()
  89. .fill(AppTheme.border)
  90. .frame(height: 1)
  91. VStack(alignment: .center, spacing: 8) {
  92. VStack(spacing: 4) {
  93. Image(systemName: "crown.fill")
  94. .font(.system(size: 14))
  95. .foregroundStyle(AppTheme.accentYellow)
  96. Text(isPremium ? "Reddora Premium" : "Upgrade to Premium")
  97. .font(.system(size: 12, weight: .semibold))
  98. .foregroundStyle(AppTheme.textPrimary)
  99. }
  100. .frame(maxWidth: .infinity, alignment: .center)
  101. Text(
  102. isPremium
  103. ? "You have unlimited AI generations and all premium features."
  104. : "Unlock unlimited AI generations and advanced analytics"
  105. )
  106. .font(.system(size: 10))
  107. .foregroundStyle(AppTheme.textSecondary)
  108. .multilineTextAlignment(.center)
  109. .frame(maxWidth: .infinity, alignment: .center)
  110. .fixedSize(horizontal: false, vertical: true)
  111. .lineSpacing(2)
  112. Button(isPremium ? "Manage Subscription" : "Upgrade Now") {
  113. viewModel.showPaywall()
  114. }
  115. .font(.system(size: 11, weight: .semibold))
  116. .foregroundStyle(.white)
  117. .frame(maxWidth: .infinity)
  118. .padding(.vertical, 7.5)
  119. .background(AppTheme.accentPurple)
  120. .clipShape(RoundedRectangle(cornerRadius: 8))
  121. .buttonStyle(AppPrimaryButtonStyle())
  122. }
  123. .frame(maxWidth: .infinity, minHeight: 105)
  124. .padding(.horizontal, 12)
  125. .padding(.vertical, 12)
  126. .background(
  127. RoundedRectangle(cornerRadius: AppTheme.cornerRadiusSmall)
  128. .fill(AppTheme.cardBackground)
  129. .overlay(
  130. RoundedRectangle(cornerRadius: AppTheme.cornerRadiusSmall)
  131. .stroke(AppTheme.accentPurple.opacity(0.25), lineWidth: 1)
  132. )
  133. )
  134. .padding(.horizontal, AppTheme.sidebarContentInset + 8)
  135. .padding(.top, 12)
  136. .padding(.bottom, 20)
  137. }
  138. }
  139. }