Browse Source

username input on home screen

pull/8/head
Tim Glasgow 2 years ago
parent
commit
2fa7ddf395
  1. 2
      squarenotsquare/src/realm/migrations/MigrateV1.js
  2. 13
      squarenotsquare/src/redux/actions/SystemActions.js
  3. 13
      squarenotsquare/src/redux/actions/UserActions.js
  4. 5
      squarenotsquare/src/redux/reducers/UserReducer.js
  5. 21
      squarenotsquare/src/screens/Home.js
  6. 5
      squarenotsquare/src/screens/styles/AppStyles.js
  7. 3
      squarenotsquare/src/themes/Icons.js
  8. 3
      squarenotsquare/src/themes/Metrics.js

2
squarenotsquare/src/realm/migrations/MigrateV1.js

@ -7,7 +7,7 @@ export function migratev1(oldRealm, newRealm) {
newRealm.create(SystemEntity.name, { newRealm.create(SystemEntity.name, {
id: uuidv4(), id: uuidv4(),
key: 'username', key: 'username',
value: 'changeme' value: 'noname'
}); });
} }
} }

13
squarenotsquare/src/redux/actions/SystemActions.js

@ -5,7 +5,8 @@ import { squareNav } from "../../navigation/SquareNav";
export function appInit() { export function appInit() {
return async (dispatch) => { return async (dispatch) => {
await DbAPI.initDB(); await DbAPI.initDB();
dispatch(onInit()); let lastUsername = DbAPI.getSystemValue('username').value;
dispatch(onInit(lastUsername));
squareNav('Home'); squareNav('Home');
} }
} }
@ -28,11 +29,13 @@ export function goToScores() {
} }
} }
function onInit() { function onInit(lastUsername) {
return (dispatch) => { return (dispatch, getState) => {
let currentUser = {...getState().user};
currentUser.username = lastUsername;
dispatch({ dispatch({
type: APP_INIT type: APP_INIT,
//system: system user: currentUser
}); });
} }
} }

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

@ -3,17 +3,22 @@ import { ADDITION_FINISHED, ADDITION_START, SQUARE_FINISHED, SQUARE_START } from
import { calculateSquareScore } from "../../libs/CalculateScore"; import { calculateSquareScore } from "../../libs/CalculateScore";
import DbAPI from "../../realm/DbAPI"; import DbAPI from "../../realm/DbAPI";
export function squareStartPressed(mode) { export function squareStartPressed(mode, username) {
return (dispatch) => { return (dispatch, getState) => {
DbAPI.createSystemValue('username', username);
let userState = {...getState().user};
userState.username = username;
if (mode === 'square') { if (mode === 'square') {
squareNav('Game'); squareNav('Game');
dispatch({ dispatch({
type: SQUARE_START type: SQUARE_START,
user: userState
}); });
} else if (mode === 'addition') { } else if (mode === 'addition') {
squareNav('AdditionGame'); squareNav('AdditionGame');
dispatch({ dispatch({
type: ADDITION_START type: ADDITION_START,
user: userState
}) })
} }
} }

5
squarenotsquare/src/redux/reducers/UserReducer.js

@ -2,7 +2,8 @@ import { APP_INIT } from "../types/SystemTypes";
import { import {
SQUARE_START, SQUARE_START,
SQUARE_FINISHED, SQUARE_FINISHED,
ADDITION_FINISHED ADDITION_FINISHED,
ADDITION_START
} from '../types/UserTypes'; } from '../types/UserTypes';
const initialUserState = { const initialUserState = {
@ -14,7 +15,9 @@ const initialUserState = {
function usr(state = initialUserState, action) { function usr(state = initialUserState, action) {
switch (action.type) { switch (action.type) {
case APP_INIT:
case SQUARE_START: case SQUARE_START:
case ADDITION_START:
case SQUARE_FINISHED: case SQUARE_FINISHED:
case ADDITION_FINISHED: case ADDITION_FINISHED:
return {...state, ...action.user}; return {...state, ...action.user};

21
squarenotsquare/src/screens/Home.js

@ -1,12 +1,12 @@
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { BackHandler, SafeAreaView, Text, TouchableOpacity, View } from "react-native"; import { BackHandler, SafeAreaView, Text, TextInput, TouchableOpacity, View } from "react-native";
import { styles } from './styles/AppStyles'; import { styles } from './styles/AppStyles';
import MaterialIcon from 'react-native-vector-icons/MaterialCommunityIcons'; import MaterialIcon from 'react-native-vector-icons/MaterialCommunityIcons';
import Icons from '../themes/Icons'; import Icons from '../themes/Icons';
import Colors from "../themes/Colors"; import Colors from "../themes/Colors";
import Metrics from "../themes/Metrics"; import Metrics from "../themes/Metrics";
import Slider from "../components/Slider"; import Slider from "../components/Slider";
import { useDispatch } from "react-redux"; import { useDispatch, useSelector } from "react-redux";
import {squareStartPressed} from '../redux/actions/UserActions'; import {squareStartPressed} from '../redux/actions/UserActions';
import { goToScores } from "../redux/actions/SystemActions"; import { goToScores } from "../redux/actions/SystemActions";
import ModePicker from '../components/ScrollingPicker'; import ModePicker from '../components/ScrollingPicker';
@ -14,13 +14,15 @@ import ModePicker from '../components/ScrollingPicker';
function Home(){ function Home(){
const dispatch = useDispatch(); const dispatch = useDispatch();
const [mode, setMode] = useState('square'); const [mode, setMode] = useState('square');
const userRedux = useSelector((state) => state.user);
const [username, setUsername] = useState(() => {return userRedux.username})
useEffect(() => { useEffect(() => {
BackHandler.addEventListener('hardwareBackPress', () => {return true}); BackHandler.addEventListener('hardwareBackPress', () => {return true});
}, []) }, [])
function onPressStart(){ function onPressStart(){
dispatch(squareStartPressed(mode)); dispatch(squareStartPressed(mode, username));
} }
function onPressHighScores(){ function onPressHighScores(){
@ -76,6 +78,19 @@ function Home(){
</TouchableOpacity> </TouchableOpacity>
</Slider> </Slider>
</View> </View>
<View style={[styles.flexRow, styles.centeredJustify, styles.centeredItems]}>
<MaterialIcon
name={Icons.squareIcons.edit}
color={Colors.material.grey400}
size={Metrics.icons.inputIcon}
/>
<TextInput
style={[styles.darkText, styles.headerTitleFont, styles.usernameInput]}
placeholder={'username'}
value={username}
onChangeText={(updated) => setUsername(updated)}
/>
</View>
<View style={[styles.footer, styles.centeredJustify]}> <View style={[styles.footer, styles.centeredJustify]}>
<Text style={[styles.greyText, styles.tinyFont, styles.centeredText]}> <Text style={[styles.greyText, styles.tinyFont, styles.centeredText]}>
0.0.1a Atonal Software Aug 9 2022 0.0.1a Atonal Software Aug 9 2022

5
squarenotsquare/src/screens/styles/AppStyles.js

@ -109,6 +109,11 @@ export const styles = StyleSheet.create({
height: Metrics.buttons.answerButton.height height: Metrics.buttons.answerButton.height
}, },
usernameInput: {
borderBottomWidth: Metrics.borders.width,
borderBottomColor: Colors.material.grey400
},
addQuestionHeight: { addQuestionHeight: {
height: Metrics.screenSections.addQuestionHeight height: Metrics.screenSections.addQuestionHeight
}, },

3
squarenotsquare/src/themes/Icons.js

@ -5,7 +5,8 @@ class AppIcons {
toggleOn: 'toggle-switch-on', toggleOn: 'toggle-switch-on',
toggleOff: 'toggle-switch-off', toggleOff: 'toggle-switch-off',
check: 'check', check: 'check',
plus: 'plus' plus: 'plus',
edit: 'pencil'
}; };
wrongShapes = { wrongShapes = {

3
squarenotsquare/src/themes/Metrics.js

@ -25,7 +25,8 @@ class AppMetrics {
this.icons = { this.icons = {
splashIcon: this.normalize(100), splashIcon: this.normalize(100),
buttonIcon: this.normalize(20) buttonIcon: this.normalize(20),
inputIcon: this.normalize(15)
} }
this.images = { this.images = {

Loading…
Cancel
Save