Skip to content

Commit

Permalink
StatsbarPlayer 10percent
Browse files Browse the repository at this point in the history
  • Loading branch information
williamdlm committed Oct 14, 2021
1 parent e729b8c commit 7deefd2
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { MainComplete } from "../src/components/Main";
import { ExperienceProvider } from "../src/contexts/ExperienceContext";

export default function Home(props) {
console.log(props);
// console.log(props);
return (
<ExperienceProvider
level={props.level}
Expand Down
11 changes: 8 additions & 3 deletions pages/quiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ function QuestionWidget({
const isCorrect = selectedAlternative === question.answer;
const hasAlternativeSelected = selectedAlternative !== undefined;
const { completeQuestion } = useContext(ExperienceContext);
// console.log(question);
console.log(selectedAlternative);
const { handlePointsStats } = useContext(ExperienceContext);
// console.log(question.type);
return (
<Widget style={{ margin: "0 auto" }}>
<Widget.Header>
Expand Down Expand Up @@ -98,7 +98,12 @@ function QuestionWidget({
addResult(isCorrect);
setTimeout(() => {
{
isCorrect && completeQuestion(1);
{
isCorrect && completeQuestion(1);
}
{
isCorrect && handlePointsStats(question.type);
}
}
onSubmit();
setSelectedAlternative(undefined);
Expand Down
44 changes: 43 additions & 1 deletion src/contexts/ExperienceContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,50 @@ export function ExperienceProvider({ children, ...rest }) {
// prettier-ignore
const experienceToNextLevel = Math.pow((level + 1) * 4, 2);
const [titleUser, setTitleUser] = useState("Iniciante");
const [totalPointsStatsBar, setTotalPointsStatsBar] = useState(10);
const [pointsBarType, setPointsBarType] = useState({
totalTypeZero: 5,
totalTypeOne: 5,
totalTypeTwo: 5,
totalTypeTree: 5,
});
const name = "William Mota";

let copy = Object.assign({}, pointsBarType);
function handlePointsStats(type) {
setTotalPointsStatsBar(totalPointsStatsBar + 1);
switch (type) {
case 0:
console.log(pointsBarType);
copy.totalTypeZero++;
setPointsBarType(copy);
console.log(copy);
break;
case 1:
copy.totalTypeOne++;
setPointsBarType(copy);
console.log(pointsBarType);
break;
case 2:
copy.totalTypeTwo++;
setPointsBarType(copy);
console.log(pointsBarType);
break;
case 3:
copy.totalTypeTree++;
setPointsBarType(copy);
console.log(pointsBarType);
break;

default:
break;
}
}

useEffect(() => {
console.log(pointsBarType);
}, [pointsBarType]);

useEffect(() => {
Cookies.set("level", String(level));
Cookies.set("currentExperience", String(currentExperience));
Expand Down Expand Up @@ -47,7 +89,6 @@ export function ExperienceProvider({ children, ...rest }) {

setCurrentExperience(finalExperience);
}
console.log(db.titulos[0]);
return (
<ExperienceContext.Provider
value={{
Expand All @@ -59,6 +100,7 @@ export function ExperienceProvider({ children, ...rest }) {
name,
titleUser,
handleTitles,
handlePointsStats,
}}
>
{children}
Expand Down

0 comments on commit 7deefd2

Please sign in to comment.