feat(watch): add workout deletion sync and optimize delete operations
This commit is contained in:
@@ -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
|
||||
return self.session?.receivedApplicationContext as? [String: Any]
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
"android": "expo run:android",
|
||||
"ios": "expo run:ios",
|
||||
"web": "expo start --web",
|
||||
"clean": "rm -rf .expo ios android node_modules && npm i",
|
||||
"db:generate": "drizzle-kit generate",
|
||||
"prebuild": "expo prebuild && npm run eas-build-post-install",
|
||||
"prebuild:clean": "expo prebuild --clean && npm run eas-build-post-install",
|
||||
|
||||
@@ -253,7 +253,9 @@ export async function deleteSession(sessionId: string) {
|
||||
|
||||
export async function deleteSessionAndSync(sessionId: string) {
|
||||
await deleteSession(sessionId);
|
||||
await WatchConnectivity.sendWorkoutDeleted(sessionId);
|
||||
WatchConnectivity.sendWorkoutDeleted(sessionId).catch((err) =>
|
||||
console.warn("[ops] sync failed:", err)
|
||||
);
|
||||
}
|
||||
|
||||
export async function deleteWorkout(id: string) {
|
||||
@@ -272,7 +274,9 @@ export async function deleteWorkout(id: string) {
|
||||
|
||||
export async function deleteWorkoutAndSync(id: string) {
|
||||
await deleteWorkout(id);
|
||||
await WatchConnectivity.sendWorkoutDeleted(id);
|
||||
WatchConnectivity.sendWorkoutDeleted(id).catch((err) =>
|
||||
console.warn("[ops] sync failed:", err)
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Stats ───────────────────────────────────────────────────
|
||||
|
||||
@@ -52,7 +52,7 @@ export function HistoryScreen() {
|
||||
style: "destructive",
|
||||
onPress: async () => {
|
||||
await deleteSessionAndSync(id);
|
||||
await loadSessions();
|
||||
setSessions((prev) => prev.filter((s) => s.id !== id));
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
@@ -64,7 +64,7 @@ export function WorkoutListScreen() {
|
||||
style: "destructive",
|
||||
onPress: async () => {
|
||||
await deleteWorkoutAndSync(id);
|
||||
await loadWorkouts();
|
||||
setWorkouts((prev) => prev.filter((w) => w.id !== id));
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
@@ -9,6 +9,7 @@ WatchConnectivity = requireOptionalNativeModule("WatchConnectivity") ?? {
|
||||
isReachable: async () => false,
|
||||
sendWorkoutPlan: 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 () => [],
|
||||
getApplicationContext: async () => null,
|
||||
updateApplicationContext: async () => {},
|
||||
|
||||
Reference in New Issue
Block a user