-
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.
Merge pull request #86 from andreasalstrup/qr-and-notice
Notice Board and QR codes
- Loading branch information
Showing
16 changed files
with
618 additions
and
94 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
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 |
---|---|---|
@@ -1,50 +1,95 @@ | ||
import React, { useEffect, useRef, useState } from 'react'; | ||
import { StyleSheet, TextInput, useColorScheme, SafeAreaView, ScrollView } from 'react-native'; | ||
import { StyleSheet, TextInput, useColorScheme, SafeAreaView, ScrollView, Pressable } from 'react-native'; | ||
import { Text, View } from '../../components/Themed'; | ||
import Colors from '../../constants/Colors'; | ||
import { groupHandle } from '../../handlers/group'; | ||
import { noticeHandle } from '../../handlers/notice'; | ||
import { AntDesign } from '@expo/vector-icons'; | ||
import Modal from "react-native-modal"; | ||
import { QrCodeSvg } from 'react-native-qr-svg'; | ||
|
||
export default function NoticeScreen() { | ||
const colorScheme = useColorScheme() ?? 'light'; | ||
const group = useRef(groupHandle(gun)).current; | ||
const group = useRef(groupHandle(gun)); | ||
const notice = useRef(noticeHandle(gun)); | ||
const [isModalVisible, setIsModalVisible] = useState(false); | ||
const [houseRules, setHouseRules] = useState(''); | ||
const [groupId, setGroupId] = useState('') | ||
const [groupName, setGroupName] = useState('') | ||
const users = [ | ||
{ name: 'Test Bruger', phone: '12 34 56 78', email: '[email protected]' }, | ||
{ name: 'Andreas Alstrup', phone: '87 65 43 21', email: '[email protected]' }, | ||
]; | ||
const [users, setUsers] = useState<User[]>([]) | ||
|
||
useEffect(() => { | ||
group.getUUID(setGroupId) | ||
group.getGName(setGroupName) | ||
group.current.getUUID((id) => setGroupId(id)) | ||
group.current.getGName((name) => setGroupName(name)) | ||
notice.current.onUsersUpdate((data: User) => { | ||
setUsers(prev => { | ||
if(!prev.includes(data)){ | ||
return [...prev, data] | ||
} | ||
return prev | ||
}) | ||
}) | ||
notice.current.onHouseRulesUpdate((rules) => setHouseRules(rules)) | ||
}, []) | ||
|
||
return ( | ||
<SafeAreaView style={[styles.container, {backgroundColor: Colors[colorScheme].background}]}> | ||
<ScrollView> | ||
<View> | ||
<Text style={styles.title}>Household Rules</Text> | ||
{groupName != '' && <Text>Group name: {groupName}</Text>} | ||
{groupId != '' && <Text selectable={true}>Group ID: {groupId}</Text>} | ||
<View style={styles.groupInfo}> | ||
<View> | ||
<Text>Group name: {groupName}</Text> | ||
<Text selectable={true}>ID: {groupId}</Text> | ||
</View> | ||
<View style={{flex: 1}}> | ||
<Pressable | ||
style={styles.qrCodeIcon} | ||
onPress={()=>{ | ||
setIsModalVisible(true) | ||
}}> | ||
<AntDesign | ||
name="qrcode" | ||
size={30} | ||
color={'gray'}/> | ||
</Pressable> | ||
</View> | ||
</View> | ||
<TextInput | ||
style={[styles.input, {color: Colors[colorScheme].text}]} | ||
placeholder="Click to make rules" | ||
placeholderTextColor={'gray'} | ||
value={houseRules} | ||
onChangeText={(text) => setHouseRules(text)} | ||
onChangeText={(text) => { | ||
notice.current.updateHouseRules(text) | ||
setHouseRules(text) | ||
}} | ||
editable | ||
multiline | ||
/> | ||
<Text style={styles.title}>Contact Information</Text> | ||
{users.map((user, index) => ( | ||
<View key={index} style={styles.userCard}> | ||
<Text style={styles.userName}>{user.name}</Text> | ||
<Text>Phone: {user.phone}</Text> | ||
<Text style={styles.userName}>{user.fullName}</Text> | ||
<Text>Phone: {user.phoneNumber}</Text> | ||
<Text>Email: {user.email}</Text> | ||
</View> | ||
))} | ||
</View> | ||
</ScrollView> | ||
<Modal | ||
style={styles.modalContainer} | ||
animationIn='zoomIn' | ||
animationOut='zoomOut' | ||
isVisible={isModalVisible} | ||
onBackdropPress={() => setIsModalVisible(false)}> | ||
<QrCodeSvg | ||
style={styles.modalContainer} | ||
value={groupId} | ||
frameSize={200} | ||
dotColor={Colors[colorScheme].text} | ||
backgroundColor={Colors[colorScheme].background}/> | ||
</Modal> | ||
</SafeAreaView> | ||
); | ||
} | ||
|
@@ -81,4 +126,16 @@ const styles = StyleSheet.create({ | |
fontSize: 16, | ||
fontWeight: 'bold', | ||
}, | ||
groupInfo: { | ||
flexDirection: 'row' | ||
}, | ||
qrCodeIcon: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}, | ||
modalContainer: { | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}, | ||
}); |
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.