Skip to content
This repository has been archived by the owner on Nov 11, 2021. It is now read-only.

Commit

Permalink
record screen redux setup
Browse files Browse the repository at this point in the history
  • Loading branch information
lochungtin committed May 31, 2021
1 parent 0fbf7f4 commit 02559de
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
2 changes: 2 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
apply plugin: "com.android.application"

apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"

import com.android.build.OutputFile

/**
Expand Down
4 changes: 2 additions & 2 deletions src/navigation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { StatusBar } from 'react-native';
import { connect } from 'react-redux';

import Main from '../screens/main';
import Leaderboard from '../screens/leaderboard';
import Records from '../screens/records';

const Root = createStackNavigator();

Expand All @@ -16,7 +16,7 @@ class AppNav extends React.Component {
<StatusBar backgroundColor={'#0E0E0E'} />
<Root.Navigator>
<Root.Screen component={Main} name='Main' />
<Root.Screen component={Leaderboard} name='Leaderboard' />
<Root.Screen component={Records} name='Records' />
</Root.Navigator>
</NavigationContainer>
);
Expand Down
11 changes: 8 additions & 3 deletions src/redux/action.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import Board from '../game/board';
import { ActionType, GameConfig } from '../utils/types';
import { ActionType, GameConfig, RecordType, } from '../utils/types';

export enum ActionName {
SAVE_GAME_STATE
SAVE_GAME_STATE,
SAVE_RECORDS,
}

export const updateRecords = (payload: Array<RecordType>): ActionType => ({
type: ActionName.SAVE_RECORDS,
payload
});

export const saveGameState = (payload: GameConfig): ActionType => ({
type: ActionName.SAVE_GAME_STATE,
payload,
Expand Down
9 changes: 7 additions & 2 deletions src/redux/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ import { combineReducers } from 'redux';

import { ActionName } from './action';

import { ActionType, GameConfig } from '../utils/types';
import { ActionType, GameConfig, RecordType } from '../utils/types';

const saveGame = (board: GameConfig = null, action: ActionType) => action.type === ActionName.SAVE_GAME_STATE ? action.payload : board;
const saveGame = (board: GameConfig = null, action: ActionType) =>
action.type === ActionName.SAVE_GAME_STATE ? action.payload : board;

const saveRecords = (records: Array<RecordType> = [], action: ActionType) =>
action.type === ActionName.SAVE_RECORDS ? action.payload : records;

export default combineReducers({
game: saveGame,
records: saveRecords,
})
File renamed without changes.
11 changes: 6 additions & 5 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ export interface CoordinatePair {
col: number;
}

export interface MergingPairs {
mergee: CoordinatePair,
merger: CoordinatePair,
}

// game config
export interface GameConfig {
board: Array<Array<number>>,
Expand Down Expand Up @@ -50,3 +45,9 @@ export interface TileColorSchemeType {
'2048': string,
large: string,
}

// game records
export interface RecordType {
topTile: number,
score: number,
}

0 comments on commit 02559de

Please sign in to comment.