Skip to content

Commit

Permalink
Smooth database user
Browse files Browse the repository at this point in the history
  • Loading branch information
s-dimaria committed May 24, 2023
1 parent e5d7dd3 commit ac4c9a8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/components/player/NextTimerScore.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function NextTimerScore() {
}, []);

useEffect(() => {
resetAllScoreOfUsers();
const today = new Date(serverDate);
const nextMonday = new Date(
today.getFullYear(),
Expand Down
12 changes: 9 additions & 3 deletions src/components/utils/firebaseRealtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,21 @@ async function updateUserByUid(uid: any, score: any) {
async function resetAllScoreOfUsers() {
await get(ref(db, "users/")).then((snapshot) => {
snapshot.forEach((u) => {

if(u.val().timestamp != undefined) {
if(new Date().getTime() - u.val().timestamp >= TIME_TO_DELETE) {
console.log(u.val());
if(new Date().getTime() - u.val().timestamp >= TIME_TO_DELETE) {
localStorage.setItem("firstTime", "false");
localStorage.removeItem("Game");
remove(ref(db,"users/" + u.key));
}
update(ref(db,"users/" + u.key), {score: 0})
update(ref(db,"users/" + u.key), {score: 0})
}

else {
localStorage.setItem("firstTime", "false");
localStorage.removeItem("Game");
remove(ref(db,"users/" + u.key));
}
})
});
}
Expand Down

0 comments on commit ac4c9a8

Please sign in to comment.