feat(watch): add workout deletion sync and optimize delete operations

This commit is contained in:
2026-08-12 13:52:23 +02:00
parent 2096489fd1
commit ca9259d5bd
6 changed files with 95 additions and 64 deletions
+25
View File
@@ -166,6 +166,31 @@ public class WatchConnectivityModule: Module {
} }
} }
AsyncFunction("sendWorkoutDeleted") { (id: String, promise: Promise) in
guard let session = self.session else {
promise.reject("NO_SESSION", "WCSession not available")
return
}
func doSend() {
let message: [String: Any] = ["type": "workoutDeleted", "id": id]
guard let cleaned = self.cleanForWCSession(message) as? [String: Any] else {
promise.resolve(["status": "sent"])
return
}
session.transferUserInfo(cleaned)
promise.resolve(["status": "sent"])
}
if self.isActivated {
doSend()
} else {
self.pendingPromises.append(doSend)
}
}
AsyncFunction("getApplicationContext") { () -> [String: Any]? in AsyncFunction("getApplicationContext") { () -> [String: Any]? in
return self.session?.receivedApplicationContext as? [String: Any] return self.session?.receivedApplicationContext as? [String: Any]
} }
+1
View File
@@ -43,6 +43,7 @@
"android": "expo run:android", "android": "expo run:android",
"ios": "expo run:ios", "ios": "expo run:ios",
"web": "expo start --web", "web": "expo start --web",
"clean": "rm -rf .expo ios android node_modules && npm i",
"db:generate": "drizzle-kit generate", "db:generate": "drizzle-kit generate",
"prebuild": "expo prebuild && npm run eas-build-post-install", "prebuild": "expo prebuild && npm run eas-build-post-install",
"prebuild:clean": "expo prebuild --clean && npm run eas-build-post-install", "prebuild:clean": "expo prebuild --clean && npm run eas-build-post-install",
+6 -2
View File
@@ -253,7 +253,9 @@ export async function deleteSession(sessionId: string) {
export async function deleteSessionAndSync(sessionId: string) { export async function deleteSessionAndSync(sessionId: string) {
await deleteSession(sessionId); await deleteSession(sessionId);
await WatchConnectivity.sendWorkoutDeleted(sessionId); WatchConnectivity.sendWorkoutDeleted(sessionId).catch((err) =>
console.warn("[ops] sync failed:", err)
);
} }
export async function deleteWorkout(id: string) { export async function deleteWorkout(id: string) {
@@ -272,7 +274,9 @@ export async function deleteWorkout(id: string) {
export async function deleteWorkoutAndSync(id: string) { export async function deleteWorkoutAndSync(id: string) {
await deleteWorkout(id); await deleteWorkout(id);
await WatchConnectivity.sendWorkoutDeleted(id); WatchConnectivity.sendWorkoutDeleted(id).catch((err) =>
console.warn("[ops] sync failed:", err)
);
} }
// ─── Stats ─────────────────────────────────────────────────── // ─── Stats ───────────────────────────────────────────────────
@@ -52,7 +52,7 @@ export function HistoryScreen() {
style: "destructive", style: "destructive",
onPress: async () => { onPress: async () => {
await deleteSessionAndSync(id); await deleteSessionAndSync(id);
await loadSessions(); setSessions((prev) => prev.filter((s) => s.id !== id));
}, },
}, },
]); ]);
@@ -64,7 +64,7 @@ export function WorkoutListScreen() {
style: "destructive", style: "destructive",
onPress: async () => { onPress: async () => {
await deleteWorkoutAndSync(id); await deleteWorkoutAndSync(id);
await loadWorkouts(); setWorkouts((prev) => prev.filter((w) => w.id !== id));
}, },
}, },
]); ]);
+1
View File
@@ -9,6 +9,7 @@ WatchConnectivity = requireOptionalNativeModule("WatchConnectivity") ?? {
isReachable: async () => false, isReachable: async () => false,
sendWorkoutPlan: async () => ({ error: "WatchConnectivity native module not available" }), sendWorkoutPlan: async () => ({ error: "WatchConnectivity native module not available" }),
sendWorkoutCompletion: async () => ({ error: "WatchConnectivity native module not available" }), sendWorkoutCompletion: async () => ({ error: "WatchConnectivity native module not available" }),
sendWorkoutDeleted: async () => ({ error: "WatchConnectivity native module not available" }),
pollEvents: async () => [], pollEvents: async () => [],
getApplicationContext: async () => null, getApplicationContext: async () => null,
updateApplicationContext: async () => {}, updateApplicationContext: async () => {},