From cca9dd3ce327f5694d187c2b3c1215f6d5d61f47 Mon Sep 17 00:00:00 2001 From: cheykrym Date: Wed, 16 Jul 2025 07:14:30 +0300 Subject: [PATCH] post update --- Shared/Models/Post.swift | 1 + Shared/Network/PostService.swift | 4 +- Shared/Views/Tab/Profile/PostDetailView.swift | 129 ++++++++++-------- .../Tab/Profile/ProfileContentGrid.swift | 19 +-- 4 files changed, 81 insertions(+), 72 deletions(-) diff --git a/Shared/Models/Post.swift b/Shared/Models/Post.swift index f7d0e77..f0bf81a 100644 --- a/Shared/Models/Post.swift +++ b/Shared/Models/Post.swift @@ -21,6 +21,7 @@ struct Post: Identifiable, Codable { let isLikedByCurrentUser: Bool // Лайк текущим юзером let isSavedByCurrentUser: Bool // Сохранено текущим юзером let authorID: String // Автор + let authorUsername: String // Имя пользователя автора let hashtags: [String]? // Хэштеги let location: String? // Гео let languageCode: [String]? // Язык diff --git a/Shared/Network/PostService.swift b/Shared/Network/PostService.swift index 4919df5..f06e176 100644 --- a/Shared/Network/PostService.swift +++ b/Shared/Network/PostService.swift @@ -99,6 +99,7 @@ class PostService { let thumbID = Bool.random() ? UUID() : nil let postID = UUID() + let authorId = "user_\(Int.random(in: 1...5))" let post = Post( id: postID, title: sampleTitles[i], @@ -117,7 +118,8 @@ class PostService { commentsCount: Int.random(in: 0...100), isLikedByCurrentUser: Bool.random(), isSavedByCurrentUser: Bool.random(), - authorID: "user_\(Int.random(in: 1...5))", + authorID: authorId, + authorUsername: "username_\(authorId.split(separator: "_").last ?? "")", hashtags: ["#тест", "#видео", "#swiftui", "#ui"].shuffled().prefix(2).map { $0 }, location: Bool.random() ? "Москва" : nil, languageCode: Bool.random() ? ["ru", "en"] : ["ru"], diff --git a/Shared/Views/Tab/Profile/PostDetailView.swift b/Shared/Views/Tab/Profile/PostDetailView.swift index 7360014..d2108e3 100644 --- a/Shared/Views/Tab/Profile/PostDetailView.swift +++ b/Shared/Views/Tab/Profile/PostDetailView.swift @@ -2,75 +2,96 @@ import SwiftUI struct PostDetailView: View { let postID: UUID - @Environment(\.presentationMode) var presentationMode - @State private var post: Post? = nil + @State private var post: Post? var body: some View { - ZStack { + VStack(alignment: .leading, spacing: 0) { if let post = post { - Color.black.ignoresSafeArea() - - VStack { + // Шапка поста + HStack { + Image(systemName: "person.crop.circle.fill") + .resizable() + .frame(width: 36, height: 36) + .foregroundColor(.gray) + Text(post.authorUsername) + .font(.headline) Spacer() - - VStack(alignment: .leading, spacing: 8) { - if let title = post.title { - Text(title) - .font(.title2) - .fontWeight(.bold) - .foregroundColor(.white) - } - - if let desc = post.description { - Text(desc) - .font(.subheadline) - .foregroundColor(Color.white.opacity(0.8)) - } - - Text("UUID: \(post.id.uuidString)") - .font(.caption2) - .foregroundColor(Color.white.opacity(0.5)) - - HStack(spacing: 12) { - Label("\(post.views)", systemImage: "eye") - Label("\(post.likes)", systemImage: "heart") - Label("\(post.saves)", systemImage: "bookmark") - Label("\(post.commentsCount)", systemImage: "text.bubble") - } - .font(.footnote) - .foregroundColor(Color.white.opacity(0.9)) + Button(action: {}) { + Image(systemName: "ellipsis") + .foregroundColor(.primary) } - .padding() - .background(Color.black.opacity(0.4)) - .cornerRadius(12) - .padding(.horizontal) - .padding(.bottom, 32) } + .padding(.horizontal) + .padding(.vertical, 8) - VStack { - HStack { - Spacer() - Button(action: { - presentationMode.wrappedValue.dismiss() - }) { - Image(systemName: "xmark.circle.fill") - .font(.system(size: 30)) - .foregroundColor(.white) - .padding() - } + // Изображение поста + Rectangle() + .fill(Color.gray.opacity(0.3)) + .aspectRatio(1, contentMode: .fit) + .frame(maxWidth: .infinity) + + // Панель действий + HStack(spacing: 16) { + Button(action: {}) { + Image(systemName: "heart") + .font(.system(size: 24)) + } + Button(action: {}) { + Image(systemName: "message") + .font(.system(size: 24)) + } + Button(action: {}) { + Image(systemName: "paperplane") + .font(.system(size: 24)) } Spacer() + Button(action: {}) { + Image(systemName: "bookmark") + .font(.system(size: 24)) + } } + .foregroundColor(.primary) + .padding(.horizontal) + .padding(.top, 8) + + // Лайки и описание + VStack(alignment: .leading, spacing: 4) { + Text("\(post.likes) likes") + .font(.headline) + + Text(post.description ?? "") + .font(.subheadline) + } + .padding(.horizontal) + .padding(.top, 8) + + // Комментарии + VStack(alignment: .leading, spacing: 4) { + Text("View all \(post.commentsCount) comments") + .font(.caption) + .foregroundColor(.secondary) + .padding(.top, 4) + + Text("2 hours ago") + .font(.caption2) + .foregroundColor(.secondary) + .padding(.top, 4) + } + .padding(.horizontal) + + Spacer() + } else { - ProgressView("Загрузка поста…") - .progressViewStyle(CircularProgressViewStyle(tint: .white)) - .foregroundColor(.white) + ProgressView("Загрузка...") .onAppear { - PostService.shared.fetchPost(by: postID) { result in - self.post = result + // Симуляция загрузки поста + PostService.shared.fetchPost(by: postID) { fetchedPost in + self.post = fetchedPost } } } } + .navigationBarTitleDisplayMode(.inline) + .navigationTitle("Post") } } diff --git a/Shared/Views/Tab/Profile/ProfileContentGrid.swift b/Shared/Views/Tab/Profile/ProfileContentGrid.swift index b16668e..781f31d 100644 --- a/Shared/Views/Tab/Profile/ProfileContentGrid.swift +++ b/Shared/Views/Tab/Profile/ProfileContentGrid.swift @@ -8,20 +8,10 @@ struct ProfileContentGrid: View { let selectedCategory: String let allPosts: [Post] let isLoading: Bool - @State private var selectedPostID: PostIDWrapper? = nil - + var body: some View { VStack(alignment: .leading, spacing: 0) { if isLoading { -// LazyVGrid(columns: Array(repeating: .init(.flexible()), count: 3), spacing: 2) { -// ForEach(0..<100, id: \.self) { _ in -// RoundedRectangle(cornerRadius: 4) -// .fill(Color.gray.opacity(0.15)) -// .aspectRatio(1, contentMode: .fit) -// } -// } -// .padding(.horizontal) -// .redacted(reason: .placeholder) // ⬅️ делает «размытый» стиль VStack { ProgressView("Загрузка...") .padding() @@ -38,9 +28,7 @@ struct ProfileContentGrid: View { } else { LazyVGrid(columns: Array(repeating: .init(.flexible()), count: 3), spacing: 2) { ForEach(filteredPosts) { post in - Button { - selectedPostID = PostIDWrapper(id: post.id) - } label: { + NavigationLink(destination: PostDetailView(postID: post.id)) { Rectangle() .fill(Color.gray.opacity(0.2)) .aspectRatio(1, contentMode: .fit) @@ -87,9 +75,6 @@ struct ProfileContentGrid: View { } } .frame(maxWidth: .infinity, alignment: .topLeading) - .fullScreenCover(item: $selectedPostID) { wrapper in - PostDetailView(postID: wrapper.id) - } } private var filteredPosts: [Post] {