Skip to content

Commit

Permalink
feat: added values progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalyiegorov committed May 21, 2023
1 parent 986a244 commit e90515d
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 35 deletions.
30 changes: 21 additions & 9 deletions components/available-values-item/available-values-item.styles.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
import { StyleSheet } from 'react-native';

import { CellSizeConstant } from '../../constants/dimensions.contant';
import { Colors } from '../theme';

const tileSize = 40;
export const AvailableValuesItemStyles = StyleSheet.create({
text: { color: Colors.black },
textActive: {
color: Colors.cell.activeValueText
},
wrapper: {
button: {
alignItems: 'center',
borderColor: Colors.black,
borderBottomColor: Colors.black,
borderColor: Colors.cell.highlighted,
borderWidth: 1,
height: tileSize,
height: CellSizeConstant,
justifyContent: 'center',
width: tileSize
width: CellSizeConstant
},
container: {
position: 'relative'
},
progress: {
backgroundColor: 'green',
height: 2,
left: 0,
position: 'absolute',
top: CellSizeConstant - 2,
zIndex: 5
},
text: { color: Colors.black },
textActive: {
color: Colors.cell.activeValueText
},
wrapperActive: {
backgroundColor: Colors.cell.highlightedText
Expand Down
30 changes: 15 additions & 15 deletions components/available-values-item/available-values-item.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import { cs } from '@rnw-community/shared';
import { Pressable, Text } from 'react-native';

import { useAppDispatch } from '../../hooks/redux.hook';
import { appRootSelectValueAction } from '../../store/app-root/actions/app-root-select-value.action';
import { cs, type OnEventFn } from '@rnw-community/shared';
import { Pressable, Text, View } from 'react-native';

import { AvailableValuesItemStyles as styles } from './available-values-item.styles';

interface Props {
value: number;
isActive: boolean;
progress: number;
onSelect: OnEventFn<number>;
}

// TODO: Add animation when wrong value is selected
// TODO: Add animation when correct value is selected
export const AvailableValuesItem = ({ value }: Props) => {
const dispatch = useAppDispatch();

const isActive = false;

const handlePress = () => void dispatch(appRootSelectValueAction(value));
export const AvailableValuesItem = ({ value, isActive, onSelect, progress }: Props) => {
const handlePress = () => onSelect(value);

const wrapperStyles = [styles.wrapper, cs(isActive, styles.wrapperActive)];
const buttonStyles = [styles.button, cs(isActive, styles.wrapperActive)];
const textStyles = [styles.text, cs(isActive, styles.textActive)];
const progressStyles = [styles.progress, { width: `${progress}%` }];

return (
<Pressable key={value} style={wrapperStyles} onPress={handlePress}>
<Text style={textStyles}>{value}</Text>
</Pressable>
<View style={styles.container}>
<Pressable key={value} style={buttonStyles} onPress={handlePress}>
<Text style={textStyles}>{value}</Text>
</Pressable>
<View style={progressStyles} />
</View>
);
};
10 changes: 2 additions & 8 deletions components/available-values/available-values.styles.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import { StyleSheet } from 'react-native';

import { CellSizeConstant } from '../../constants/dimensions.contant';

export const AvailableValuesStyles = StyleSheet.create({
valueWrapper: {
borderWidth: 1,
height: CellSizeConstant,
width: CellSizeConstant
},
wrapper: {
flex: 1,
flexDirection: 'row',
gap: 2,
flexWrap: 'wrap',
gap: 10,
justifyContent: 'center'
}
});
15 changes: 14 additions & 1 deletion components/available-values/available-values.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
import { View } from 'react-native';
import { useSelector } from 'react-redux';

import { useAppDispatch } from '../../hooks/redux.hook';
import { appRootSelectValueAction } from '../../store/app-root/actions/app-root-select-value.action';
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';

const getValueProgress = (allValues: Record<number, number>, value: number) => (allValues[value] / 9) * 100;

export const AvailableValues = () => {
const allValues = useSelector(appRootAvailableValuesSelector);
const availableValues = Object.keys(allValues)
.filter(key => allValues[Number(key)] < 9)
.map(Number);

const dispatch = useAppDispatch();
const handleSelect = (value: number) => void dispatch(appRootSelectValueAction(value));

return (
<View style={styles.wrapper}>
{availableValues.map(value => (
<AvailableValuesItem value={value} key={value} />
<AvailableValuesItem
value={value}
key={value}
onSelect={handleSelect}
isActive={false}
progress={getValueProgress(allValues, value)}
/>
))}
</View>
);
Expand Down
2 changes: 1 addition & 1 deletion components/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const BlackTheme = {
black: 'rgb(255, 255, 255)',
cell: {
active: 'rgba(0, 255, 0, 1)',
highlighted: 'rgba(255,255,255,0.2)',
highlighted: 'rgba(255,255,255,0.15)',
highlightedText: 'rgba(0, 255, 0, 1)',
activeValueText: 'rgba(201, 242, 155, 0.5)'
}
Expand Down
2 changes: 1 addition & 1 deletion constants/dimensions.contant.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const CellSizeConstant = 50;
export const CellSizeConstant = 45;

0 comments on commit e90515d

Please sign in to comment.