-
-
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.
37 store a set of calculated marks (#78)
* move file * update sentry * new styling button * more styling * #37 store mark set in local storage * reset set name input * new markset interface for storing locally * better documentation of return vaule * adding sentry env * adding jest setup * update button test * adding mocks, setup and test for setModal * rearrange imports * adding metro config for jest-hermes issue * fixes hermes for now * conditionally render buttons * adding confirm modal for removing marks * new version
- Loading branch information
1 parent
697a4b6
commit a86cc9c
Showing
19 changed files
with
292 additions
and
254 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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Modal, StyleSheet, Text, View } from 'react-native'; | ||
import { Button } from '../../../../components/common'; | ||
import { CalculatedMarks } from '../../../../types'; | ||
import { storeLocalStorage } from '../../../../utils'; | ||
|
||
interface Props { | ||
modalVisible: boolean; | ||
setBallistics: (ballistics: CalculatedMarks | null) => void; | ||
closeModal: () => void; | ||
} | ||
|
||
const ConfirmRemoveMarks = ({ modalVisible, setBallistics, closeModal }: Props) => { | ||
function handleRemoveMarks() { | ||
storeLocalStorage(null, 'ballistics').then(() => { | ||
setBallistics(null); | ||
closeModal(); | ||
}); | ||
} | ||
|
||
return ( | ||
<Modal transparent visible={modalVisible} animationType="fade"> | ||
<View style={styles.modal}> | ||
<Text style={{ fontSize: 18 }}>Bekreft fjerning av siktemerker</Text> | ||
<View style={styles.buttons}> | ||
<Button type="outline" label="Avbryt" onPress={closeModal} /> | ||
<Button width={100} label="Ja" onPress={handleRemoveMarks} /> | ||
</View> | ||
</View> | ||
</Modal> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
modal: { | ||
marginTop: 'auto', | ||
marginBottom: '40%', | ||
marginLeft: 'auto', | ||
marginRight: 'auto', | ||
height: 160, | ||
width: '80%', | ||
justifyContent: 'space-around', | ||
alignItems: 'center', | ||
shadowColor: 'black', | ||
shadowOpacity: 0.25, | ||
shadowRadius: 8, | ||
shadowOffset: { width: 0, height: 2 }, | ||
elevation: 5, | ||
borderRadius: 8, | ||
backgroundColor: 'white', | ||
}, | ||
buttons: { | ||
width: '100%', | ||
flexDirection: 'row', | ||
justifyContent: 'space-around', | ||
}, | ||
}); | ||
|
||
export default ConfirmRemoveMarks; |
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,75 @@ | ||
import { useState } from 'react'; | ||
import { Modal, View } from 'react-native'; | ||
import { Button, Input } from '../../../../components/common'; | ||
import { CalculatedMarks, MarkSet } from '../../../../types'; | ||
import { getLocalStorage, storeLocalStorage } from '../../../../utils'; | ||
|
||
interface Props { | ||
modalVisible: boolean; | ||
closeModal: () => void; | ||
setBallistics: (ballistics: CalculatedMarks | null) => void; | ||
ballistics: CalculatedMarks | null; | ||
} | ||
|
||
const SetModal = ({ modalVisible, closeModal, setBallistics, ballistics }: Props) => { | ||
const [name, setName] = useState(''); | ||
const [nameError, setNameError] = useState(''); | ||
|
||
async function storeMarksWithName(name: string) { | ||
if (ballistics) { | ||
const setList = await getLocalStorage<Array<MarkSet>>('marksSets'); | ||
|
||
const marksSet = { | ||
name: name, | ||
marks: ballistics.given_marks, | ||
distances: ballistics.given_distances, | ||
}; | ||
|
||
if (setList) { | ||
const nameExists = setList.some((set) => set.name === name); | ||
if (nameExists) { | ||
setNameError('Name is already taken'); | ||
} else { | ||
setList.push(marksSet); | ||
storeLocalStorage(setList, 'marksSets'); | ||
setBallistics(null); | ||
setNameError(''); | ||
setName(''); | ||
closeModal(); | ||
} | ||
} else { | ||
const marksSets = Array<MarkSet>(); | ||
marksSets.push(marksSet); | ||
storeLocalStorage(marksSets, 'marksSets'); | ||
setBallistics(null); | ||
setName(''); | ||
setNameError(''); | ||
closeModal(); | ||
} | ||
} | ||
} | ||
|
||
const handleSave = async () => { | ||
await storeMarksWithName(name); | ||
}; | ||
|
||
return ( | ||
<Modal visible={modalVisible} animationType="fade"> | ||
<View style={{ flex: 1, margin: 32, justifyContent: 'center', alignItems: 'center' }}> | ||
<Input | ||
label="Sett navn på settet" | ||
error={nameError.length > 0} | ||
errorMessage={nameError} | ||
onChangeText={setName} | ||
value={name} | ||
/> | ||
<View style={{ flexDirection: 'row', marginTop: 24, justifyContent: 'space-between' }}> | ||
<Button type="outline" label="Avbryt" onPress={closeModal} /> | ||
<Button label="Lagre sett" onPress={handleSave} /> | ||
</View> | ||
</View> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default SetModal; |
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,5 @@ | ||
export { default as ConfirmRemoveMarks } from './ConfirmRemoveMarks'; | ||
export { default as MarksForm } from './MarksForm'; | ||
export { default as MarksTable } from './MarksTable'; | ||
export { default as SetModal } from './SetModal'; | ||
export { useCalcForm } from './useCalcForm'; |
File renamed without changes.
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
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,4 @@ | ||
jest.mock('@react-native-async-storage/async-storage', () => | ||
require('@react-native-async-storage/async-storage/jest/async-storage-mock'), | ||
); | ||
jest.mock('@sentry/react-native', () => ({ init: () => jest.fn() })); |
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,8 @@ | ||
// eslint-disable-next-line prettier/prettier | ||
const { getDefaultConfig } = require('expo/metro-config'); | ||
|
||
const config = getDefaultConfig(__dirname); | ||
|
||
config.resolver.blockList = [/(.*.test.ts?)$/]; | ||
|
||
module.exports = config; |
Oops, something went wrong.