SidebarView.swift 5.7 KB

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