SidebarView.swift 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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: .center, 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. Text(
  99. isPremium
  100. ? "You have unlimited AI generations and all premium features."
  101. : "Unlock unlimited AI generations and advanced analytics"
  102. )
  103. .font(.system(size: 10))
  104. .foregroundStyle(AppTheme.textSecondary)
  105. .multilineTextAlignment(.center)
  106. .fixedSize(horizontal: false, vertical: true)
  107. .lineSpacing(2)
  108. Button(isPremium ? "Manage Subscription" : "Upgrade Now") {
  109. viewModel.showPaywall()
  110. }
  111. .font(.system(size: 11, weight: .semibold))
  112. .foregroundStyle(.white)
  113. .frame(maxWidth: .infinity)
  114. .padding(.vertical, 6)
  115. .background(AppTheme.accentPurple)
  116. .clipShape(RoundedRectangle(cornerRadius: 8))
  117. .buttonStyle(.plain)
  118. }
  119. .frame(maxWidth: .infinity, minHeight: 105)
  120. .padding(.horizontal, 12)
  121. .padding(.vertical, 12)
  122. .background(
  123. RoundedRectangle(cornerRadius: AppTheme.cornerRadiusSmall)
  124. .fill(AppTheme.cardBackground)
  125. .overlay(
  126. RoundedRectangle(cornerRadius: AppTheme.cornerRadiusSmall)
  127. .stroke(AppTheme.accentPurple.opacity(0.25), lineWidth: 1)
  128. )
  129. )
  130. .padding(.horizontal, AppTheme.sidebarContentInset + 8)
  131. .padding(.top, 12)
  132. .padding(.bottom, 20)
  133. .overlay(alignment: .top) {
  134. Rectangle()
  135. .fill(AppTheme.border)
  136. .frame(height: 1)
  137. }
  138. }
  139. }