SidebarView.swift 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import SwiftUI
  2. struct SidebarView: View {
  3. @Bindable var viewModel: FrontPageViewModel
  4. var body: some View {
  5. VStack(spacing: 0) {
  6. header
  7. navigationSections
  8. Spacer(minLength: 0)
  9. upgradeCard
  10. }
  11. .frame(width: AppTheme.sidebarWidth)
  12. .background(AppTheme.sidebarBackground)
  13. .overlay(alignment: .trailing) {
  14. Rectangle()
  15. .fill(AppTheme.border)
  16. .frame(width: 1)
  17. }
  18. }
  19. private var header: some View {
  20. HStack(spacing: AppTheme.sidebarRowSpacing) {
  21. ZStack {
  22. RoundedRectangle(cornerRadius: 10)
  23. .fill(
  24. LinearGradient(
  25. colors: [AppTheme.accentPurpleLight, AppTheme.accentPurple],
  26. startPoint: .topLeading,
  27. endPoint: .bottomTrailing
  28. )
  29. )
  30. .frame(width: AppTheme.iconContainerSize, height: AppTheme.iconContainerSize)
  31. Image(systemName: "brain.head.profile")
  32. .font(.system(size: 14, weight: .semibold))
  33. .foregroundStyle(.white)
  34. }
  35. .frame(width: AppTheme.iconContainerSize, height: AppTheme.iconContainerSize)
  36. VStack(alignment: .leading, spacing: 2) {
  37. Text("Reddora AI")
  38. .font(.system(size: 15, weight: .bold))
  39. .foregroundStyle(AppTheme.textPrimary)
  40. Text("AI Assistant for Reddit")
  41. .font(.system(size: 10))
  42. .foregroundStyle(AppTheme.textSecondary)
  43. }
  44. Spacer(minLength: 0)
  45. }
  46. .padding(.horizontal, AppTheme.sidebarContentInset + AppTheme.sidebarRowPaddingH)
  47. .padding(.top, 20)
  48. .padding(.bottom, 16)
  49. }
  50. private var navigationSections: some View {
  51. ScrollView {
  52. VStack(alignment: .leading, spacing: AppTheme.sidebarSectionSpacing) {
  53. sidebarSection(title: SidebarSection.quickAccess.rawValue) {
  54. SidebarQuickAccessItemView(isSelected: viewModel.isRedditActive) {
  55. viewModel.openReddit()
  56. }
  57. }
  58. sidebarSection(title: SidebarSection.create.rawValue) {
  59. ForEach(viewModel.createItems) { item in
  60. SidebarNavItemView(item: item, isSelected: viewModel.selectedNavItem == item) {
  61. viewModel.selectNavItem(item)
  62. }
  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(alignment: .center, spacing: 8) {
  89. HStack(spacing: 6) {
  90. Image(systemName: "crown.fill")
  91. .font(.system(size: 12))
  92. .foregroundStyle(AppTheme.accentYellow)
  93. Text("Upgrade to Pro")
  94. .font(.system(size: 12, weight: .semibold))
  95. .foregroundStyle(AppTheme.textPrimary)
  96. }
  97. Text("Unlock unlimited AI generations and advanced analytics")
  98. .font(.system(size: 10))
  99. .foregroundStyle(AppTheme.textSecondary)
  100. .multilineTextAlignment(.center)
  101. .fixedSize(horizontal: false, vertical: true)
  102. .lineSpacing(2)
  103. Button("Upgrade Now") {}
  104. .font(.system(size: 11, weight: .semibold))
  105. .foregroundStyle(.white)
  106. .frame(maxWidth: .infinity)
  107. .padding(.vertical, 6)
  108. .background(AppTheme.accentPurple)
  109. .clipShape(RoundedRectangle(cornerRadius: 8))
  110. .buttonStyle(.plain)
  111. }
  112. .frame(maxWidth: .infinity, minHeight: 105)
  113. .padding(.horizontal, 12)
  114. .padding(.vertical, 12)
  115. .background(
  116. RoundedRectangle(cornerRadius: AppTheme.cornerRadiusSmall)
  117. .fill(AppTheme.cardBackground)
  118. .overlay(
  119. RoundedRectangle(cornerRadius: AppTheme.cornerRadiusSmall)
  120. .stroke(AppTheme.accentPurple.opacity(0.25), lineWidth: 1)
  121. )
  122. )
  123. .padding(.horizontal, AppTheme.sidebarContentInset + 8)
  124. .padding(.top, 12)
  125. .padding(.bottom, 20)
  126. .overlay(alignment: .top) {
  127. Rectangle()
  128. .fill(AppTheme.border)
  129. .frame(height: 1)
  130. }
  131. }
  132. }