Feedback Stage
Welcome to the documentation for the Feedback Stage component! This guide will help understand the code and its features. This page is verified by: Vedant Kejariwal
Functions
This is the list of functions that are defined on this page.
Component: Feedback
Description
The Feedback
component manages the feedback stage of the game. It gathers feedback data from consumers and producers and updates player data, including reviews and warrant status.
Key Features
-
Role-based Logic:
- Differentiates functionality based on whether the player is a consumer or a producer.
-
Consumer Feedback:
- Allows consumers to provide reviews for products purchased during the game.
-
Timer Integration:
- Alerts users when the timer is about to expire, providing a warning toast.
-
Dynamic Player Filtering:
- Filters players into consumer and producer roles for targeted actions.
-
Data Persistence:
- Updates player data, such as reviews and purchases, during the feedback stage.
Function: handleSubmit()
Description
This function handles the submission of feedback data, updating each player's data with consumer reviews and producer performance during the feedback stage.
Parameters
None
Returns
None
Code
function handleSubmit() {
if (player.get("role") === "consumer") {
// console.log(
// `Saving ${consumerReviews} to consumer ${player.get("name")}`
// );
// console.log("conbut sumerReviews in handleSubmit", consumerReviews);
player.set("consumerReviews", consumerReviews);
}
player.stage.set("submit", true);
}
Logic Explanation
-
Consumer Reviews Update:
- If the player is a consumer, updates the
consumerReviews
field with the latest feedback data.
- If the player is a consumer, updates the
-
Stage Submission:
- Marks the stage as submitted using
player.stage.set("submit", true)
to proceed to the next stage.
- Marks the stage as submitted using
useEffect Hook
Description
This hook monitors the stage timer and triggers a warning toast when there are 15 seconds left in the stage.
Parameters
None (depends on timer
and toastShown
).
Returns
None (executes side effects).
Code
useEffect(() => {
if (timer?.remaining || timer?.remaining === 0) {
const remainingSeconds = Math.round(timer.remaining / 1000);
if (remainingSeconds <= 15 && !toastShown) {
toast.warning("Hurry up! Only 15 seconds left!");
setToastShown(true);
}
}
}, [timer, toastShown]);
Logic Explanation
-
Monitor Timer:
- Checks the remaining time in the stage using the
timer.remaining
property.
- Checks the remaining time in the stage using the
-
Trigger Warning:
- Displays a warning toast when the time left is 15 seconds or less.
-
Prevent Multiple Warnings:
- Uses the
toastShown
state to ensure the warning is displayed only once per stage.
- Uses the