API Endpoints for trackjs/javascript-gameshow
This documentation provides an in-depth overview of the routes defined within the TrackJS/JavaScript-Gameshow codebase. The routing logic primarily utilizes preact-router
, and the examples included here detail how to navigate between different components of the application.
Overview of Routes
In the JavaScript-Gameshow application, routes are defined in the App
component, found in the presenter-app/src/app.tsx
file. The significant routes include:
- Home
- Game New
- Game Details
- Question Details
- Game List
- Find Player
- Error Not Found
- Test Questions
- Test Prizes
Route Definitions
The following sections detail each route with code examples extracted from the respective files.
Home Route
The home route is generally represented in home.tsx
. An example click event that routes to the home page can be seen here:
route('/')}>Home
This route redirects users back to the homepage.
Find Player Route
This route is defined in home.tsx
and allows users to find an available player. The corresponding code snippet is:
route('/find-player')}>Find Player
Games Route
The route for the games page is defined in home.tsx
as well:
route(`/games`)}>List Games
This button click leads to a list of available games.
Game New Route
For creating a new game, it’s defined in gameNew.tsx
. The logic for routing follows this structure:
route(`/game/${game.id}/q/0`, false);
This enables navigating to the question view of the newly created game.
Game Details Route
The game details route can be seen while listing games in gameList.tsx
. Depending on the game status, it can route to different states:
route(`/game/${game.id}`)}>Prizes
route(`/game/${game.id}/q/${game.questionsAsked.length}`)}>Resume
This facilitates navigation to game’s prize section or resume the game.
Question Details Route
The question details route handles the navigation inside the game flow. It can be seen in questionDetails.tsx
:
route(`/game/${game.id}/q/${state.questionIdx + 1}`)}>Next Question
This allows users to progress through the game’s questions.
Error Not Found Route
In case of an error or unknown path, the errorNotFound.tsx
file defines the routing back to the home as follows:
route("/")}>Home
This provides a fallback in the event of a 404 error.
Additional Routing Logic in App Component
In the presenter-app/src/app.tsx
, all these routes integrate into the Router
component. Below is a simplified look at how routes are laid out:
const App = () => (
<Router>
<Home path="/" />
<GameNew path="/game/new" />
<GameDetails path="/game/:id" />
<QuestionDetails path="/game/:id/q/:questionIdx" />
<GameList path="/games" />
<FindPlayer path="/find-player" />
<ErrorNotFound default />
</Router>
);
Each route component maps to its corresponding path, allowing for proper navigation throughout the application.
Summary
The defined routes in the TrackJS/JavaScript-Gameshow codebase demonstrate a structured navigation system leveraging preact-router
. Each routing command facilitates user interaction through various components, enhancing the overall user experience in navigating the game show application.
For further insight into the routing logic, refer to the files, especially presenter-app/src/app.tsx
and the corresponding route components discussed herein. Each feature ensures cohesive navigation across the application and promotes user engagement.
Sources:
- Presenter App Component Code.
- Individual Route Component Codes.
Sources
- presenter-app/src/routes/home.tsx
- presenter-app/src/routes/error/errorNotFound.tsx
- presenter-app/src/sw.js
- presenter-app/build/route-home.chunk.01056.js
- presenter-app/src/routes/game/gameNew.tsx
- presenter-app/src/routes/game/q/questionDetails.tsx
- presenter-app/src/app.tsx
- audience-app/public/404.html
- presenter-app/src/routes/game/gameList.tsx
- presenter-app/src/controllers/GameController.ts