Browse Source

load all scores on highscore screen

pull/8/head
Tim Glasgow 2 years ago
parent
commit
bfd2bdad45
  1. 4
      squarenotsquare/src/realm/DbAPI.js
  2. 9
      squarenotsquare/src/realm/repos/ScoreRepo.js
  3. 2
      squarenotsquare/src/redux/actions/UserActions.js
  4. 4
      squarenotsquare/src/screens/HighScore.js

4
squarenotsquare/src/realm/DbAPI.js

@ -30,6 +30,10 @@ class DatabaseAPI {
return true;
}
getHighScores() {
return this.scoreRepo.getHighScores();
}
async initDB() {
let repos = await initDB();
this.systemRepo = repos.systemRepo;

9
squarenotsquare/src/realm/repos/ScoreRepo.js

@ -24,4 +24,13 @@ export default class ScoreRepo {
);
});
};
getHighScores = () => {
let score = this.realmDB.objects(ScoreEntity.name);
let highScores = [];
score.forEach((row) => {
highScores.push({user: row.user, value: row.value});
});
return highScores;
};
}

2
squarenotsquare/src/redux/actions/UserActions.js

@ -21,7 +21,7 @@ export function squareFinished(answers, finalTime) {
newUser.lastGameAnswers = answers;
let finalScore = calculateSquareScore(answers, finalTime);
DbAPI.createScore(userState.username, finalScore);
DbAPI.createScore(userState.username, finalScore.toString());
dispatch({
type: SQUARE_FINISHED,
user: newUser

4
squarenotsquare/src/screens/HighScore.js

@ -1,12 +1,14 @@
import React, { useEffect } from "react";
import React, { useEffect, useRef } from "react";
import { BackHandler, SafeAreaView, Text, TouchableOpacity, View } from "react-native";
import { styles } from './styles/AppStyles';
import Slider from "../components/Slider";
import { useDispatch } from "react-redux";
import {goHome} from '../redux/actions/SystemActions';
import DbAPI from "../realm/DbAPI";
function HighScore(){
const dispatch = useDispatch();
const scores = useRef(DbAPI.getHighScores());
useEffect(() => {
BackHandler.addEventListener('hardwareBackPress', () => {return true});

Loading…
Cancel
Save