ios_app/Shared/Views/Tab/Profile/ProfileContentTabbedGrid.swift
2025-07-16 10:09:02 +03:00

142 lines
5.3 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import SwiftUI
struct ProfileContentTabbedGrid: View {
let isContentLoaded: Bool
@Binding var allPosts: [Post]
@Binding var isLoading: Bool
let onPostTapped: (Post, [Post]) -> Void
@State private var selectedTabIndex = 0
@State private var selectedCategory = "#все"
@State private var searchQuery = ""
@State private var selectedSort = "По дате"
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,
onPostTapped: onPostTapped
)
}
}
// 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)
.padding(.horizontal)
}
.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)
.padding(.horizontal)
}
.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)
.padding(.horizontal)
}
.frame(maxWidth: .infinity)
.onTapGesture {
selectedTabIndex = index
}
}
}