34 lines
		
	
	
		
			964 B
		
	
	
	
		
			Swift
		
	
	
	
	
	
			
		
		
	
	
			34 lines
		
	
	
		
			964 B
		
	
	
	
		
			Swift
		
	
	
	
	
	
import SwiftUI
 | 
						|
 | 
						|
struct HomeTab: View {
 | 
						|
    @State private var posts: [Post] = []
 | 
						|
    @State private var isLoading = true
 | 
						|
 | 
						|
    var body: some View {
 | 
						|
        NavigationView {
 | 
						|
            VStack {
 | 
						|
                if isLoading {
 | 
						|
                    ProgressView("Загрузка ленты...")
 | 
						|
                } else {
 | 
						|
                    ScrollView {
 | 
						|
                        LazyVStack(spacing: 24) {
 | 
						|
                            ForEach(posts) { post in
 | 
						|
                                PostDetailView(post: post)
 | 
						|
                            }
 | 
						|
                        }
 | 
						|
                    }
 | 
						|
                }
 | 
						|
            }
 | 
						|
            .navigationTitle("Лента")
 | 
						|
            .onAppear {
 | 
						|
                if posts.isEmpty {
 | 
						|
                    PostService.shared.fetchAllPosts { fetchedPosts in
 | 
						|
                        self.posts = fetchedPosts
 | 
						|
                        self.isLoading = false
 | 
						|
                    }
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |