-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: adding async storage package * feat: adding store and retrieve functions * remove log statement * feat: adding local storage * fix: adding types to local storage * fix: move getLocalState to api dir - remove useLocalStorage hook - use new fetching logic * fix: refactor marks form to seperate component * fix: typo corrected by wife * styles: general style changes * styles: better table styling
- Loading branch information
1 parent
4076e80
commit 64c4d83
Showing
9 changed files
with
222 additions
and
101 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import React, { FC } from 'react'; | ||
import { Keyboard, StyleSheet, View } from 'react-native'; | ||
|
||
import { Button, Input } from '../../../../components/common'; | ||
import { MarkValue } from '../../../../types'; | ||
import { formatNumber } from '../../../../utils'; | ||
import { useCalcForm } from '../useCalcForm'; | ||
|
||
interface MarksFormProps { | ||
status: string; | ||
sendMarks: (newMark: MarkValue) => Promise<void>; | ||
} | ||
|
||
const MarksForm: FC<MarksFormProps> = ({ sendMarks, status }) => { | ||
const [{ aimError, aimValue, distanceError, distanceValue }, dispatch] = useCalcForm(); | ||
|
||
function handleDistanceChange(value: string) { | ||
dispatch({ type: 'SET_DISTANCE_VALUE', payload: value }); | ||
} | ||
|
||
function handleAimChange(value: string) { | ||
dispatch({ type: 'SET_AIM_VALUE', payload: value }); | ||
} | ||
|
||
async function handleAddMark() { | ||
if (!aimValue) { | ||
dispatch({ type: 'SET_AIM_ERROR', payload: true }); | ||
} | ||
if (!distanceValue) { | ||
dispatch({ type: 'SET_DISTANCE_ERROR', payload: true }); | ||
} | ||
if (aimValue && distanceValue) { | ||
const newEntry: MarkValue = { aim: parseFloat(aimValue), distance: parseFloat(distanceValue) }; | ||
|
||
await sendMarks(newEntry); | ||
dispatch({ type: 'SET_AIM_VALUE', payload: '' }); | ||
dispatch({ type: 'SET_DISTANCE_VALUE', payload: '' }); | ||
Keyboard.dismiss(); | ||
} | ||
} | ||
|
||
return ( | ||
<View style={styles.form}> | ||
<View> | ||
<Input | ||
textAlign="center" | ||
maxLength={100} | ||
label="Avstand" | ||
onBlur={() => dispatch({ type: 'SET_DISTANCE_ERROR', payload: false })} | ||
placeholderText="F.eks. 20" | ||
keyboardType="numeric" | ||
error={distanceError} | ||
errorMessage="Fyll inn" | ||
value={distanceValue} | ||
onChangeText={(value) => handleDistanceChange(formatNumber(value))} | ||
/> | ||
</View> | ||
<View> | ||
<Input | ||
textAlign="center" | ||
maxLength={15} | ||
label="Merke" | ||
onBlur={() => dispatch({ type: 'SET_AIM_ERROR', payload: false })} | ||
placeholderText="F.eks. 2.3" | ||
keyboardType="numeric" | ||
value={aimValue} | ||
error={aimError} | ||
errorMessage="Fyll inn" | ||
onChangeText={(value) => handleAimChange(formatNumber(value))} | ||
/> | ||
</View> | ||
<Button | ||
type="filled" | ||
width={100} | ||
loading={status === 'pending'} | ||
buttonStyle={{ marginLeft: 'auto', marginTop: 16 }} | ||
onPress={handleAddMark} | ||
label="Beregn" | ||
/> | ||
</View> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
form: { | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'flex-end', | ||
marginBottom: 32, | ||
}, | ||
}); | ||
|
||
export default MarksForm; |
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
Oops, something went wrong.