Able to clear status on watchOS

🐛 Fix some bugs in status on watchOS
This commit is contained in:
2025-10-30 01:15:42 +08:00
parent dbcd1b6d36
commit b57caf56db
2 changed files with 49 additions and 8 deletions

View File

@@ -148,9 +148,9 @@ class NetworkService {
}
func createOrUpdateStatus(attitude: Int, isInvisible: Bool, isNotDisturb: Bool, label: String?, token: String, serverUrl: String) async throws -> SnAccountStatus {
// First check if status exists
// Check if there's already a customized status
let existingStatus = try? await fetchAccountStatus(token: token, serverUrl: serverUrl)
let method = existingStatus == nil ? "POST" : "PATCH"
let method = (existingStatus?.isCustomized == true) ? "PATCH" : "POST"
guard let baseURL = URL(string: serverUrl) else {
throw URLError(.badURL)

View File

@@ -13,6 +13,7 @@ struct AccountView: View {
@State private var status: SnAccountStatus?
@State private var isLoading = false
@State private var error: Error?
@State private var showingClearConfirmation = false
@StateObject private var profileImageLoader = ImageLoader()
@StateObject private var bannerImageLoader = ImageLoader()
@@ -110,8 +111,23 @@ struct AccountView: View {
.font(.subheadline)
.foregroundColor(.secondary)
Spacer()
if status?.isCustomized == true {
Button(action: {
showingClearConfirmation = true
}) {
ZStack {
Circle()
.fill(Color.red.opacity(0.1))
.frame(width: 28, height: 28)
Image(systemName: "trash")
.foregroundColor(.red)
}
}
.buttonStyle(.plain)
.frame(width: 28, height: 28)
}
NavigationLink(
destination: StatusCreationView(initialStatus: status)
destination: StatusCreationView(initialStatus: status?.isCustomized == true ? status : nil)
.environmentObject(appState)
) {
ZStack {
@@ -210,6 +226,16 @@ struct AccountView: View {
}
}
.navigationTitle("Account")
.confirmationDialog("Clear Status", isPresented: $showingClearConfirmation) {
Button("Clear Status", role: .destructive) {
Task {
await clearStatus()
}
}
Button("Cancel", role: .cancel) {}
} message: {
Text("Are you sure you want to clear your status? This action cannot be undone.")
}
.onAppear {
Task.detached {
await loadUserProfile()
@@ -235,6 +261,21 @@ struct AccountView: View {
isLoading = false
}
private func clearStatus() async {
guard let token = appState.token, let serverUrl = appState.serverUrl else {
error = NSError(domain: "AccountView", code: 1, userInfo: [NSLocalizedDescriptionKey: "Authentication not available"])
return
}
do {
try await networkService.clearStatus(token: token, serverUrl: serverUrl)
// Refresh status after clearing
status = try await networkService.fetchAccountStatus(token: token, serverUrl: serverUrl)
} catch {
self.error = error
}
}
}
#Preview {