From a38306220812296b29d97332e3580cfce0c56968 Mon Sep 17 00:00:00 2001 From: KateKashko <107617602+KateKashko@users.noreply.github.com> Date: Mon, 15 Apr 2024 13:39:49 +0300 Subject: [PATCH] Code refactoring --- .../SwiftBuddiesFeed/Sources/FeedCell.swift | 111 +----------------- .../SwiftBuddiesFeed/Sources/FeedView.swift | 23 ++-- 2 files changed, 21 insertions(+), 113 deletions(-) diff --git a/Targets/SwiftBuddiesFeed/Sources/FeedCell.swift b/Targets/SwiftBuddiesFeed/Sources/FeedCell.swift index 42fd943..b8eb491 100644 --- a/Targets/SwiftBuddiesFeed/Sources/FeedCell.swift +++ b/Targets/SwiftBuddiesFeed/Sources/FeedCell.swift @@ -11,117 +11,16 @@ import SwiftUI struct FeedCell: View { let post: Post - var body: some View { + var body: some View{ VStack{ - // MARK: - image + username + date - HStack{ - if let user = post.user{ - Image(user.profileImageUrl) - .resizable() - .scaledToFill() - .frame(width: 43, height: 43) - .clipShape(Circle()) - - VStack{ - Text(user.name) - .font(.body) - .fontWeight(.medium) - .frame(maxWidth: .infinity, alignment: .leading) -// .foregroundColor(.mainGray) - - Spacer() - - Text("01.01.2025 at 09.00 a.m.") //need add logic - .font(.caption2) - .fontWeight(.regular) - .frame(maxWidth: .infinity, alignment: .leading) - .foregroundColor(.gray) - } - .frame(maxHeight: 43) - } - Spacer() - } - .padding(.top, 10) - .padding(.horizontal, 10) - -// MARK: - post content, location - Text(post.content) - .frame(maxWidth: .infinity, alignment: .leading) - .font(.footnote) - .padding(.horizontal, 10) - .padding(.top, 4) - -// MARK: - post image - if let imageUrl = post.imageUrl, !imageUrl.isEmpty { - Image(imageUrl) - .resizable() - .scaledToFit() - } - -// MARK: - like and comments counters - HStack{ - - Image(systemName: "heart.fill") - .foregroundColor(.red) - - Text("\(post.likeCount)") - .font(.footnote) - .fontWeight(.medium) - .frame(maxWidth: .infinity, alignment: .leading) - - Text("\(post.commentsCount) comments") - .font(.footnote) - .fontWeight(.regular) - .frame(maxWidth: .infinity, alignment: .trailing) - - } - .padding(.top, 8) - .padding(.horizontal, 10) - .foregroundColor(.gray) + FeedCellHeaderView(post: Post.MOCK_POSTS[0]) + FeedCellContentView(post: Post.MOCK_POSTS[1]) + FeedCellCountersView(post: Post.MOCK_POSTS[2]) Divider() -// MARK: - action buttons - HStack{ - Spacer() - VStack{ - Button{ - print("like post") - } label: { - Image(systemName: "heart") // need add "if" statements to change color if already liked post - .imageScale(.medium) - } - Text("Like") - .font(.caption2) - } - Spacer() - VStack{ - Button{ - print("Comment on post") - } label: { - Image(systemName: "bubble.right") - .imageScale(.medium) - } - Text("Comment") - .font(.caption2) - } - Spacer() - VStack{ - Button{ - print("Share post") - } label: { - Image(systemName: "paperplane") - .imageScale(.medium) - } - Text("Share") - .font(.caption2) - } - Spacer() - } - .padding(.top, 4) - .padding([.bottom, .horizontal], 10) - .foregroundColor(.gray) + ActionButtonView() } .background(Color.white) .clipShape(RoundedRectangle(cornerRadius: 15)) diff --git a/Targets/SwiftBuddiesFeed/Sources/FeedView.swift b/Targets/SwiftBuddiesFeed/Sources/FeedView.swift index 6beac03..2107418 100644 --- a/Targets/SwiftBuddiesFeed/Sources/FeedView.swift +++ b/Targets/SwiftBuddiesFeed/Sources/FeedView.swift @@ -4,6 +4,9 @@ import Design import DefaultNetworkOperationPackage public struct FeedView: View { + + @State private var addPost = false + public var body: some View { NavigationStack{ ScrollView{ @@ -27,17 +30,23 @@ public struct FeedView: View { } ToolbarItem(placement: .navigationBarTrailing) { - Image(systemName: "plus.circle") - .resizable() - .scaledToFill() - .frame(width: 24, height: 24) - .foregroundColor(.cyan) - + Button(action: { + addPost.toggle() + }) { + Image(systemName: "plus.circle") + .resizable() + .scaledToFill() + .frame(width: 24, height: 24) + .foregroundColor(Color.cyan) + } } } .background(.white) //here will be custom color + .sheet(isPresented: $addPost) { + + AddPostView() + } } - } }