I want get access to the User-Database but I don't know how to do it.
How to add the parameter var user: User out this code:
import SwiftUI
import SDWebImageSwiftUI
import FirebaseFirestore
import FirebaseStorage
struct PostCardView: View {
var post: Post
var user: User
/// - Callbacks
var onUpdate: (Post)->()
var onDelete: ()->()
/// - View Properties
@AppStorage("user_UID") private var userUID: String = ""
@AppStorage ("isAdmin") private var isAdmin: Bool = false
@AppStorage ("isVerified") private var isVerified: Bool = false
@State private var docListner: ListenerRegistration?
@State private var showComments: Bool = false
@State private var expandImages: Bool = false
@State private var pageIndex: Int = 0
@State private var showUserProfile: Bool = false
var body: some View {
[...]
}
}
To this:
import SwiftUI
import Firebase
import FirebaseFirestore
struct ReusablePostsView: View {
var basedOnUID: Bool = false
var uid: String = ""
@Binding var posts: [Post]
/// - View Properties
@State private var isFetching: Bool = true
/// - Pagination
@State private var paginationDoc: QueryDocumentSnapshot?
var body: some View {
ScrollView(.vertical, showsIndicators: false) {
LazyVStack{
// StatView()
if isFetching{
ProgressView()
.padding(.top,30)
}else{
if posts.isEmpty{
/// No Post's Found on Firestore
Text("Keine Beiträge gefunden")
.font(.caption)
.foregroundColor(.gray)
.padding(.top,30)
}else{
/// - Displaying Post's
Posts()
}
}
}
.padding(15)
}
.refreshable {
/// - Scroll to Refresh
/// Disbaling Refresh for UID based Post's
guard !basedOnUID else{return}
isFetching = true
posts = []
/// - Resetting Pagination Doc
paginationDoc = nil
await fetchPosts()
}
.task {
/// - Fetching For One Time
guard posts.isEmpty else{return}
await fetchPosts()
}
}
/// - Displaying Fetched Post's
@ViewBuilder
func Posts()->some View{
ForEach(posts){post in
PostCardView(post: post) { updatedPost in
/// Updating Post in the Array
if let index = posts.firstIndex(where: { post in
post.id == updatedPost.id
}){
posts[index].likedIDs = updatedPost.likedIDs
posts[index].dislikedIDs = updatedPost.dislikedIDs
}
} onDelete: {
/// Removing Post From the Array
withAnimation(.easeInOut(duration: 0.25)){
posts.removeAll{post.id == $0.id}
}
}
.onAppear {
/// - When Last Post Appears, Fetching New Post (If There)
if post.id == posts.last?.id && paginationDoc != nil{
Task{await fetchPosts()}
}
}
Divider()
.padding(.horizontal,-15)
}
}
/// - Fetching Post's
func fetchPosts()async{
do{
var query: Query!
/// - Implementing Pagination
if let paginationDoc{
query = Firestore.firestore().collection("Posts")
.order(by: "publishedDate", descending: true)
.start(afterDocument: paginationDoc)
.limit(to: 20)
}else{
query = Firestore.firestore().collection("Posts")
.order(by: "publishedDate", descending: true)
.limit(to: 20)
}
/// - New Query For UID Based Document Fetch
/// Simply Filter the Post's Which is not belongs to this UID
if basedOnUID{
query = query
.whereField("userUID", isEqualTo: uid)
}
let docs = try await query.getDocuments()
let fetchedPosts = docs.documents.compactMap { doc -> Post? in
try? doc.data(as: Post.self)
}
await MainActor.run(body: {
posts.append(contentsOf: fetchedPosts)
paginationDoc = docs.documents.last
isFetching = false
})
}catch{
print(error.localizedDescription)
}
}
}
struct ReusablePostsView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hello, how long have I to wait for the beta test?
Its my first time and I want to know if that normal and how long is the regular waiting time.
The current status is: "Warten auf Prüfung", in English it should be "Waiting for Review"
Hi, I bought an Apple Developer Membership and after purchase the Apple Developer App show me following text: „You‘ll receive an email soon“.
Is this normal and how long should I wait or should I contact the support?