146 lines
5.3 KiB
Swift
146 lines
5.3 KiB
Swift
import SwiftUI
|
||
|
||
struct ProfileContentTabbedGrid: View {
|
||
let isContentLoaded: Bool
|
||
@State private var selectedTabIndex = 0
|
||
@State private var selectedCategory = "#все"
|
||
@State private var searchQuery = ""
|
||
@State private var selectedSort = "По дате"
|
||
@State private var allPosts: [Post] = []
|
||
@State private var isLoading = true
|
||
|
||
var body: some View {
|
||
VStack(spacing: 0) {
|
||
// Вкладки профиля
|
||
HStack(spacing: 32) {
|
||
menuTab(index: 0)
|
||
tabButton(index: 1, systemIcon: "lock")
|
||
tabButton(index: 2, systemIcon: "bookmark")
|
||
tabButton(index: 3, systemIcon: "heart")
|
||
}
|
||
.padding(.vertical, 2)
|
||
|
||
// Фильтры
|
||
HStack {
|
||
if selectedTabIndex == 0 {
|
||
Menu {
|
||
Button("#все") { selectedCategory = "#все" }
|
||
Button("#влог") { selectedCategory = "#влог" }
|
||
Button("#игры") { selectedCategory = "#игры" }
|
||
} label: {
|
||
Label(selectedCategory, systemImage: "tag")
|
||
.font(.subheadline)
|
||
.padding(8)
|
||
.background(Color.gray.opacity(0.2))
|
||
.cornerRadius(8)
|
||
}
|
||
|
||
TextField("Поиск", text: $searchQuery)
|
||
.padding(.horizontal, 10)
|
||
.padding(.vertical, 6)
|
||
.background(Color.gray.opacity(0.15))
|
||
.cornerRadius(8)
|
||
.font(.subheadline)
|
||
|
||
Button {
|
||
// Создать пост
|
||
} label: {
|
||
Label("Создать", systemImage: "plus")
|
||
.font(.subheadline)
|
||
.padding(8)
|
||
.background(Color.blue.opacity(0.2))
|
||
.cornerRadius(8)
|
||
}
|
||
} else {
|
||
TextField("Поиск", text: $searchQuery)
|
||
.padding(.horizontal, 10)
|
||
.padding(.vertical, 6)
|
||
.background(Color.gray.opacity(0.15))
|
||
.cornerRadius(8)
|
||
.font(.subheadline)
|
||
}
|
||
}
|
||
.padding(.horizontal)
|
||
.padding(.vertical, 12)
|
||
|
||
// Контент с табами
|
||
ProfileContentGrid(
|
||
isContentLoaded: isContentLoaded,
|
||
selectedTabIndex: selectedTabIndex,
|
||
searchQuery: searchQuery,
|
||
selectedCategory: selectedCategory,
|
||
allPosts: allPosts,
|
||
isLoading: isLoading
|
||
)
|
||
}
|
||
.onAppear {
|
||
if allPosts.isEmpty {
|
||
isLoading = true
|
||
PostService.shared.fetchAllPosts { result in
|
||
self.allPosts = result
|
||
self.isLoading = false
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// MARK: - Вкладка с меню
|
||
@ViewBuilder
|
||
func menuTab(index: Int) -> some View {
|
||
if selectedTabIndex == index {
|
||
Menu {
|
||
Button("По дате") { selectedSort = "По дате" }
|
||
Button("По популярности") { selectedSort = "По популярности" }
|
||
} label: {
|
||
VStack(spacing: 4) {
|
||
HStack(spacing: 4) {
|
||
Image(systemName: "rectangle.grid.3x2")
|
||
.font(.system(size: 18, weight: .medium))
|
||
.foregroundColor(.primary)
|
||
Image(systemName: "chevron.down")
|
||
.font(.system(size: 10))
|
||
.foregroundColor(.gray)
|
||
}
|
||
Rectangle()
|
||
.frame(height: 2)
|
||
.foregroundColor(.primary)
|
||
}
|
||
.frame(maxWidth: .infinity)
|
||
}
|
||
} else {
|
||
Button {
|
||
selectedTabIndex = index
|
||
} label: {
|
||
VStack(spacing: 4) {
|
||
HStack(spacing: 4) {
|
||
Image(systemName: "rectangle.grid.3x2")
|
||
.font(.system(size: 18, weight: .medium))
|
||
.foregroundColor(.gray)
|
||
}
|
||
Rectangle()
|
||
.frame(height: 2)
|
||
.foregroundColor(.clear)
|
||
}
|
||
.frame(maxWidth: .infinity)
|
||
}
|
||
}
|
||
}
|
||
|
||
// MARK: - Остальные вкладки
|
||
@ViewBuilder
|
||
func tabButton(index: Int, systemIcon: String) -> some View {
|
||
VStack(spacing: 4) {
|
||
Image(systemName: systemIcon)
|
||
.font(.system(size: 18, weight: .medium))
|
||
.foregroundColor(selectedTabIndex == index ? .primary : .gray)
|
||
Rectangle()
|
||
.frame(height: 2)
|
||
.foregroundColor(selectedTabIndex == index ? .primary : .clear)
|
||
}
|
||
.frame(maxWidth: .infinity)
|
||
.onTapGesture {
|
||
selectedTabIndex = index
|
||
}
|
||
}
|
||
}
|