Bugfix/undo fix (#3)
* Add undoLink API function * Call backend undo on undoLastLink to keep chain in sync
This commit is contained in:
@@ -96,6 +96,10 @@ export async function validateLink(
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function undoLink(gameId: string): Promise<void> {
|
||||
await apiClient.post(`/games/${gameId}/undo`);
|
||||
}
|
||||
|
||||
export async function getGameSession(id: string): Promise<GameHistoryEntry> {
|
||||
const { data } = await apiClient.get<GameHistoryEntry>(`/games/${id}`);
|
||||
return data;
|
||||
|
||||
@@ -261,6 +261,16 @@ export const useGameStore = create<GameState>((set, get) => ({
|
||||
passedMovieB: hasPassedMovieB,
|
||||
validationError: null,
|
||||
});
|
||||
|
||||
// Fire-and-forget backend undo to keep DB chain in sync
|
||||
const { sessionId } = get();
|
||||
if (sessionId) {
|
||||
import('@/api/games').then(({ undoLink }) => {
|
||||
undoLink(sessionId).catch((err) => {
|
||||
console.error('[GameStore] Failed to undo link on backend:', err);
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
setValidating: (isValidating: boolean) => set({ isValidating }),
|
||||
|
||||
Reference in New Issue
Block a user