Skip to content

Commit

Permalink
Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
KateKashko authored and darkbringer1 committed Apr 16, 2024
1 parent c46bfb9 commit a383062
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 113 deletions.
111 changes: 5 additions & 106 deletions Targets/SwiftBuddiesFeed/Sources/FeedCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
23 changes: 16 additions & 7 deletions Targets/SwiftBuddiesFeed/Sources/FeedView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import Design
import DefaultNetworkOperationPackage

public struct FeedView: View {

@State private var addPost = false

public var body: some View {
NavigationStack{
ScrollView{
Expand All @@ -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()
}
}

}
}

Expand Down

0 comments on commit a383062

Please sign in to comment.