-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5cd3626
commit 3d413dd
Showing
14 changed files
with
151 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,26 @@ | ||
import { StatusBar } from 'expo-status-bar'; | ||
import { StyleSheet, Text, View } from 'react-native'; | ||
import { StyleSheet, View } from 'react-native'; | ||
import { Provider } from 'react-redux'; | ||
|
||
import { AvailableValues } from './components/available-values/available-values'; | ||
import { Field } from './components/field/field'; | ||
import { createStore } from './store/create-store'; | ||
|
||
// TODO: Extract to AppRoot | ||
export default function App() { | ||
return ( | ||
<Provider store={createStore}> | ||
<View style={styles.container}> | ||
<Text>Open up App.js to start working on your app!</Text> | ||
<StatusBar style="auto" /> | ||
<Field /> | ||
<AvailableValues /> | ||
</View> | ||
</Provider> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
alignItems: 'center', | ||
backgroundColor: '#fff', | ||
flex: 1, | ||
justifyContent: 'center' | ||
flex: 1 | ||
} | ||
}); |
19 changes: 19 additions & 0 deletions
19
components/available-values-item/available-values-item.styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { StyleSheet } from 'react-native'; | ||
|
||
const tileSize = 40; | ||
export const AvailableValuesItemStyles = StyleSheet.create({ | ||
text: {}, | ||
textActive: { | ||
color: 'white' | ||
}, | ||
wrapper: { | ||
alignItems: 'center', | ||
borderWidth: 1, | ||
height: tileSize, | ||
justifyContent: 'center', | ||
width: tileSize | ||
}, | ||
wrapperActive: { | ||
backgroundColor: 'green' | ||
} | ||
}); |
28 changes: 28 additions & 0 deletions
28
components/available-values-item/available-values-item.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { cs } from '@rnw-community/shared'; | ||
import { Pressable, Text } from 'react-native'; | ||
import { useDispatch } from 'react-redux'; | ||
|
||
import { appRootSelectValueAction } from '../../store/app-root/app-root.actions'; | ||
|
||
import { AvailableValuesItemStyles as styles } from './available-values-item.styles'; | ||
|
||
interface Props { | ||
value: number; | ||
} | ||
|
||
export const AvailableValuesItem = ({ value }: Props) => { | ||
const dispatch = useDispatch(); | ||
|
||
const isActive = false; | ||
|
||
const handlePress = () => void dispatch(appRootSelectValueAction(value)); | ||
|
||
const wrapperStyles = [styles.wrapper, cs(isActive, styles.wrapperActive)]; | ||
const textStyles = [styles.text, cs(isActive, styles.textActive)]; | ||
|
||
return ( | ||
<Pressable key={value} style={wrapperStyles} onPress={handlePress}> | ||
<Text style={textStyles}>{value}</Text> | ||
</Pressable> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { StyleSheet } from 'react-native'; | ||
|
||
export const AvailableValuesStyles = StyleSheet.create({ | ||
valueWrapper: { | ||
alignItems: 'center', | ||
borderWidth: 1, | ||
height: 30, | ||
justifyContent: 'center', | ||
width: 30 | ||
}, | ||
wrapper: { | ||
flex: 1, | ||
flexDirection: 'row', | ||
gap: 5, | ||
height: 30, | ||
justifyContent: 'center', | ||
width: '100%' | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { View } from 'react-native'; | ||
import { useSelector } from 'react-redux'; | ||
|
||
import { appRootAvailableValuesSelector } from '../../store/app-root/app-root.selectors'; | ||
import { AvailableValuesItem } from '../available-values-item/available-values-item'; | ||
|
||
import { AvailableValuesStyles as styles } from './available-values.styles'; | ||
|
||
export const AvailableValues = () => { | ||
const allValues = useSelector(appRootAvailableValuesSelector); | ||
const availableValues = Object.keys(allValues) | ||
.filter(key => allValues[Number(key)] < 9) | ||
.map(Number); | ||
|
||
return ( | ||
<View style={styles.wrapper}> | ||
{availableValues.map(value => ( | ||
<AvailableValuesItem value={value} key={value} /> | ||
))} | ||
</View> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { appRootSlice } from './app-root.slice'; | ||
|
||
export const { load: appRootLoadAction, selectCell: appRootSelectCellAction } = appRootSlice.actions; | ||
export const { load: appRootLoadAction, selectCell: appRootSelectCellAction, selectValue: appRootSelectValueAction } = appRootSlice.actions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
import { createSelector } from '@reduxjs/toolkit'; | ||
|
||
import { getAvailableFieldValues } from '../../utils/get-available-field-values.util'; | ||
import { type RootState } from '../create-store'; | ||
|
||
const appRootSelector = (state: RootState) => state.appRoot; | ||
|
||
export const appRootFieldSelector = createSelector(appRootSelector, state => state.gameField); | ||
export const appRootSelectedCellSelector = createSelector(appRootSelector, state => state.selectedCell); | ||
export const appRootSelectedValueSelector = createSelector(appRootSelector, state => state.selectedValue); | ||
export const appRootAvailableValuesSelector = createSelector(appRootSelector, state => getAvailableFieldValues(state.gameField)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { isDefined } from '@rnw-community/shared'; | ||
|
||
import { type CellInterface } from '../interfaces/cell.interface'; | ||
|
||
export const getAvailableFieldValues = (field: CellInterface[][]): Record<number, number> => { | ||
const availableValues: Record<string, number> = {}; | ||
for (let x = 0; x < field.length; x++) { | ||
for (let y = 0; y < field[x].length; y++) { | ||
const value = field[x][y].value; | ||
availableValues[value] = isDefined(availableValues[value]) ? availableValues[value] + 1 : 1; | ||
} | ||
} | ||
|
||
return availableValues; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { type CellInterface } from '../interfaces/cell.interface'; | ||
|
||
import { hasValueInColumn } from './has-value-in-column.util'; | ||
import { hasValueInGroup } from './has-value-in-group.util'; | ||
import { hasValueInRow } from './has-value-in-row.util'; | ||
|
||
export const isCorrectCell = (cell: CellInterface, matrix: CellInterface[][]): boolean => { | ||
return !hasValueInRow(cell, matrix) && !hasValueInColumn(cell, matrix) && !hasValueInGroup(cell, matrix); | ||
}; |