-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPostsView.swift
57 lines (49 loc) · 1.56 KB
/
PostsView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import SwiftUI
struct PostsView: View {
@State private var newPostText: String = ""
@State private var posts: [Post] = []
var body: some View {
NavigationView {
VStack {
Image("makers-logo")
.resizable()
.scaledToFit()
.frame(width: 100, height: 100)
ScrollView {
VStack(spacing: 20) {
ForEach(posts, id: \.id) { post in
PostView(post: post)
}
}
.padding()
}.refreshable {
fetchPosts()
}
HStack {
TextField("Write something...", text: $newPostText)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding()
Button("Post") {
}
.padding()
}
.background(Color.gray.opacity(0.1))
.cornerRadius(10)
.padding()
}
}
.onAppear {
fetchPosts()
}
}
private func fetchPosts() {
PostService.shared.fetchPosts { fetchedPosts in
self.posts = fetchedPosts
}
}
struct PostsFeedView_Previews: PreviewProvider {
static var previews: some View {
PostsView()
}
}
}