🐛 Fix bugs

This commit is contained in:
2025-10-29 01:50:27 +08:00
parent 1a37d384e6
commit 926ae5402f
5 changed files with 43 additions and 40 deletions

View File

@@ -1,6 +1,7 @@
{
"images" : [
{
"filename" : "icon.png",
"idiom" : "universal",
"platform" : "watchos",
"size" : "1024x1024"

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

View File

@@ -19,6 +19,7 @@ class ActivityViewModel: ObservableObject {
private let networkService = NetworkService()
let filter: String
private var isMock = false
private var hasFetched = false // Add this
init(filter: String, mockActivities: [SnActivity]? = nil) {
self.filter = filter
@@ -29,10 +30,11 @@ class ActivityViewModel: ObservableObject {
}
func fetchActivities(token: String, serverUrl: String) async {
if isMock { return }
if isMock || hasFetched { return } // Check hasFetched
guard !isLoading else { return }
isLoading = true
errorMessage = nil
hasFetched = true // Set hasFetched
do {
let fetchedActivities = try await networkService.fetchActivities(filter: filter, token: token, serverUrl: serverUrl)
@@ -40,6 +42,7 @@ class ActivityViewModel: ObservableObject {
} catch {
self.errorMessage = error.localizedDescription
print("[watchOS] fetchActivities failed with error: \(error)")
hasFetched = false // Reset on error
}
isLoading = false

View File

@@ -37,7 +37,9 @@ struct ActivityListView: View {
switch activity.type {
case "posts.new", "posts.new.replies":
if case .post(let post) = activity.data {
NavigationLink(destination: PostDetailView(post: post)) {
NavigationLink(
destination: PostDetailView(post: post).environmentObject(appState)
) {
PostRowView(post: post)
}
}
@@ -51,12 +53,13 @@ struct ActivityListView: View {
}
}
}
.task {
// Only fetch if appState is ready and token/serverUrl are available
.onAppear {
if appState.isReady, let token = appState.token, let serverUrl = appState.serverUrl {
Task.detached {
await viewModel.fetchActivities(token: token, serverUrl: serverUrl)
}
}
}
.navigationTitle(viewModel.filter)
.navigationBarTitleDisplayMode(.inline)
}

View File

@@ -11,33 +11,38 @@ import SwiftUI
struct ExploreView: View {
@StateObject private var appState = AppState()
@State private var isComposing = false
@State private var selectedTab: String = "Explore"
var body: some View {
NavigationStack {
Group {
if appState.isReady {
TabView {
NavigationStack {
TabView(selection: $selectedTab) {
ActivityListView(filter: "Explore")
}
.tag("Explore")
.tabItem {
Label("Explore", systemImage: "safari")
}
NavigationStack {
ActivityListView(filter: "Subscriptions")
}
.tag("Subscriptions")
.tabItem {
Label("Subscriptions", systemImage: "star")
}
NavigationStack {
ActivityListView(filter: "Friends")
}
.tag("Friends")
.tabItem {
Label("Friends", systemImage: "person.2")
}
}
.navigationTitle(selectedTab)
.toolbar {
ToolbarItem(placement: .primaryAction) {
Button(action: { isComposing = true }) {
Label("Compose", systemImage: "plus")
}
}
}
.environmentObject(appState)
} else {
ProgressView { Text("Connecting to phone...") }
@@ -46,18 +51,9 @@ struct ExploreView: View {
}
}
}
.navigationTitle("Explore")
.toolbar {
ToolbarItem(placement: .primaryAction) {
Button(action: { isComposing = true }) {
Label("Compose", systemImage: "plus")
}
}
}
.sheet(isPresented: $isComposing) {
ComposePostView()
.environmentObject(appState)
}
}
}
}