-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sfr fixes part 2 #52
base: main
Are you sure you want to change the base?
Sfr fixes part 2 #52
Changes from all commits
2cc942a
e28162c
1a82b9f
4afcd7c
106ae70
6076fbd
5a9fb93
3d22ca3
98e98e3
e0b61d4
7a47c15
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
import { | ||
Modal, | ||
Pressable, | ||
StyleSheet, | ||
Text, | ||
TextInput, | ||
View, | ||
} from 'react-native'; | ||
import {useTheme} from '@react-navigation/native'; | ||
import {useState} from 'react'; | ||
import {NoteStructureWithMatchNumber} from '../../database/Notes'; | ||
import Svg, {Path} from 'react-native-svg'; | ||
import {supabase} from '../../lib/supabase'; | ||
|
||
export const EditNoteModal = ({ | ||
alaninnovates marked this conversation as resolved.
Show resolved
Hide resolved
|
||
visible, | ||
note, | ||
onSave, | ||
onCancel, | ||
}: { | ||
visible: boolean; | ||
note: NoteStructureWithMatchNumber; | ||
onSave: (note: NoteStructureWithMatchNumber) => void; | ||
onCancel: () => void; | ||
}) => { | ||
const {colors} = useTheme(); | ||
const [content, setContent] = useState<string>(note.content); | ||
|
||
const saveNote = async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
await supabase.from('notes').update({content}).eq('id', note.id); | ||
// await supabase.from('notes_edits').insert({ | ||
// note_id: note.id, | ||
// content: note.content, | ||
// new_content: content, | ||
// }); | ||
onSave({...note, content}); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
container: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}, | ||
modal: { | ||
backgroundColor: colors.card, | ||
padding: 20, | ||
borderRadius: 10, | ||
width: '80%', | ||
}, | ||
backgroundCovering: { | ||
backgroundColor: 'rgba(0, 0, 0, 0.5)', | ||
position: 'absolute', | ||
top: 0, | ||
right: 0, | ||
bottom: 0, | ||
left: 0, | ||
}, | ||
input: { | ||
backgroundColor: colors.background, | ||
padding: 10, | ||
borderRadius: 5, | ||
marginVertical: 10, | ||
height: '30%', | ||
color: colors.text, | ||
}, | ||
button: { | ||
backgroundColor: colors.primary, | ||
padding: 10, | ||
borderRadius: 5, | ||
marginVertical: 10, | ||
alignItems: 'center', | ||
}, | ||
disabledButton: { | ||
backgroundColor: 'gray', | ||
padding: 10, | ||
borderRadius: 5, | ||
marginVertical: 10, | ||
alignItems: 'center', | ||
}, | ||
buttonText: { | ||
color: colors.background, | ||
}, | ||
}); | ||
|
||
return ( | ||
<Modal animationType="slide" transparent={true} visible={visible}> | ||
<View style={styles.backgroundCovering} /> | ||
<View style={styles.container}> | ||
<View style={styles.modal}> | ||
<View | ||
style={{ | ||
display: 'flex', | ||
flexDirection: 'row', | ||
justifyContent: 'space-between', | ||
alignItems: 'center', | ||
}}> | ||
<Text | ||
style={{color: colors.text, fontWeight: 'bold', fontSize: 24}}> | ||
Edit Note | ||
</Text> | ||
<View | ||
style={{ | ||
flex: 1, | ||
}} | ||
/> | ||
<Pressable | ||
onPress={onCancel} | ||
style={{ | ||
backgroundColor: colors.notification, | ||
padding: 10, | ||
borderRadius: 100, | ||
alignItems: 'center', | ||
}}> | ||
<Svg width="24" height="24" viewBox="0 0 24 24" fill="none"> | ||
<Path | ||
d="M6 18L18 6M6 6l12 12" | ||
stroke="white" | ||
strokeWidth="2" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
/> | ||
</Svg> | ||
</Pressable> | ||
</View> | ||
<Text style={{color: colors.text, fontSize: 18}}> | ||
Match: {note.match_number} | ||
</Text> | ||
<Text style={{color: colors.text, fontSize: 18}}> | ||
Team: {note.team_number} | ||
</Text> | ||
<TextInput | ||
style={styles.input} | ||
alaninnovates marked this conversation as resolved.
Show resolved
Hide resolved
|
||
multiline={true} | ||
value={content} | ||
onChange={e => setContent(e.nativeEvent.text)} | ||
/> | ||
<Pressable | ||
style={ | ||
!content || content === note.content | ||
? styles.button | ||
: styles.disabledButton | ||
} | ||
onPress={saveNote} | ||
disabled={!content || content === note.content}> | ||
<Text style={styles.buttonText}>Save</Text> | ||
</Pressable> | ||
</View> | ||
</View> | ||
</Modal> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,7 +167,18 @@ function ScoutingFlow({navigation, route, resetTimer}) { | |
setFormId(comp.formId); | ||
setFormStructure(comp.form); | ||
setCompetition(comp); | ||
initForm(comp.form); | ||
const storedFormData = await AsyncStorage.getItem( | ||
alaninnovates marked this conversation as resolved.
Show resolved
Hide resolved
|
||
FormHelper.ASYNCSTORAGE_CURRENT_REPORT_KEY, | ||
); | ||
console.log('storedFormData: ', storedFormData); | ||
if (storedFormData != null) { | ||
const data = JSON.parse(storedFormData); | ||
setArrayData(data.arrayData); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be a toast or some other indicator to the user that the form was loaded from offline storage / cache (use a more user-friendly term for this). |
||
setMatch(data.match); | ||
setTeam(data.team); | ||
} else { | ||
initForm(comp.form); | ||
} | ||
} else { | ||
setIsCompetitionHappening(false); | ||
} | ||
|
@@ -357,6 +368,22 @@ function ScoutingFlow({navigation, route, resetTimer}) { | |
//console.log('dict: ', dict); | ||
}, [formStructure]); | ||
|
||
useEffect(() => { | ||
if (arrayData == null) { | ||
return; | ||
} | ||
(async () => { | ||
await AsyncStorage.setItem( | ||
FormHelper.ASYNCSTORAGE_CURRENT_REPORT_KEY, | ||
JSON.stringify({ | ||
arrayData, | ||
match, | ||
team, | ||
}), | ||
); | ||
})(); | ||
}, [arrayData]); | ||
|
||
const styles = StyleSheet.create({ | ||
textInput: { | ||
borderColor: 'gray', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can you not edit an offline note?