Initial commit: nightly iOS app + Supabase backend
iOS SwiftUI app with Supabase auth/realtime, Node.js backend, Docker/Supabase self-hosted infrastructure, and APNs scheduler. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import Foundation
|
||||
|
||||
@MainActor
|
||||
class FeedViewModel: ObservableObject {
|
||||
@Published var posts: [Post] = []
|
||||
@Published var isLoading = false
|
||||
|
||||
func load() async {
|
||||
isLoading = true
|
||||
defer { isLoading = false }
|
||||
do {
|
||||
posts = try await supabase.getFeed()
|
||||
} catch {
|
||||
#if DEBUG
|
||||
posts = Post.previews
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
func resonate(_ post: Post) async {
|
||||
guard let idx = posts.firstIndex(where: { $0.id == post.id }) else { return }
|
||||
let wasActive = posts[idx].hasResonated
|
||||
|
||||
posts[idx].hasResonated = !wasActive
|
||||
posts[idx].resonanceCount += wasActive ? -1 : 1
|
||||
|
||||
do {
|
||||
try await supabase.toggleResonance(postId: post.id, currentlyActive: wasActive)
|
||||
} catch {
|
||||
posts[idx].hasResonated = wasActive
|
||||
posts[idx].resonanceCount += wasActive ? 1 : -1
|
||||
}
|
||||
}
|
||||
|
||||
/// Neuen Post vom Realtime-Service in den Feed einfügen
|
||||
func prepend(_ post: Post) {
|
||||
guard !posts.contains(where: { $0.id == post.id }) else { return }
|
||||
posts.insert(post, at: 0)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user