feat(api): implement resilient client-side offline fallback engine wh…#32
feat(api): implement resilient client-side offline fallback engine wh…#32Siddh2024 wants to merge 1 commit into
Conversation
…en database is inactive
|
@Siddh2024 is attempting to deploy a commit to the coderzs' projects Team on Vercel. A member of the Team first needs to authorize it. |
|
why is this feature required? seems completely unecessary |
@coder-zs-cse , it will help down other contributors as well , to produce locally , without connection of database . Also this serves as the feature to access the game offline or in case of database error. |
|
yeah but you cannot play the Daily mode without the connection. Daily mode of puzzle means there is a fixed puzzle of the day, everyone in the world is supposed to play the exact same puzzle and share the results. It cannot be coupled into a offline play |
|
For offline play, we can havea seperate button for 'Play Offline' where user chooses the board size and system generates the puzzle, and user is able to play offline. However we need to make sure all the logic is reused. We shuldn't be making duplicate logic for game operations. |
|
contributors can easily spin up a postgresql database locally and use it. or else use a db string from neon.com |
Description
🚀 The Problem
Currently, the Shabble daily shape-guessing game relies entirely on a PostgreSQL database connection. If the database is unconfigured (such as during local development without a
POSTGRES_URL) or goes offline, the app triggers a hard, blocking"Database is inactive"dialog which prevents the user from playing the game entirely.🛠️ The Solution
This Pull Request introduces a highly resilient Client-Side Offline Fallback Engine directly within the API layer inside
src/api/daily-api.ts.Now, if the backend server API returns a connection or server error (e.g.,
500orERR_BAD_RESPONSE), the application catches the error and seamlessly transitions the player into an Offline Sandbox Mode. All core templates, styling, UI layouts, daily shape rules, and original components are 100% untouched and remain exactly as they were, keeping the game fully operational and responsive under all network conditions.💎 Features Implemented
1. Silent Error Catching & Transition
/api/daily/status,/api/daily/hint, and/api/daily/guess) with secure try-catch handlers.2. Algorithmic Client-Side Parity
fetchOfflineBoard: Generates a daily grid layout on the client with a contiguous chain of connected secret tiles based on the chosen board size and current date.getOfflineAdjacentCount: Evaluates MineSweeper-like adjacent'X'counts within the standard 9-grid using the exact coordinate logic as the backend solver.3. Local Persistence & Metrics Sync
localStorageundershabble-offline-puzzle-${date}-${boardSize}keys.shabble-offline-statsthat updates and preserves streaks, game play counts, win-distribution, and stars across page reloads.🧪 Verification & Testing
Automated Checks
npx tsc --noEmit. The code compiles cleanly with zero TypeScript errors.Manual Verification
POSTGRES_URLconnection locally to simulate an inactive database.localStorage.@coder-zs-cse , Approve this pr for the issue #28 , under the tag GSSoC 26'.