Skip to content

Commit

Permalink
Fixed UI and added the setting of userpub that disappeared
Browse files Browse the repository at this point in the history
  • Loading branch information
emilnormann committed Dec 8, 2023
1 parent ec3c779 commit 2853c60
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 43 deletions.
12 changes: 7 additions & 5 deletions app/(login)/(groupScreen)/createGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,32 @@ export default function getCreateComponent(){
const [processing, setProcessing] = useState(false)

function redirect() {
router.replace('../../shoppingList')
router.replace('/shoppingList')
}
function createNewGroup(groupName : string){
if (groupName != ""){ // Some val
if (groupName != ""){
group.current.create(groupName, redirect)
}else {
setProcessing(false)
}
}
return (
// <View>
<>
<Text style={styles.descriptiveText}> What is the name of your new group?</Text>
<View style={{alignItems:"center"}}><Text style={styles.explainerText}> What is the name of your new group?</Text></View>
<Text style={styles.descriptiveText}>Group name</Text>
<View style={styles.inputBox}>
<TextInput style={styles.inputField} value={groupName} onChangeText={(groupName) =>{setGroupName(groupName)}}/>
</View>
<Pressable onPress={() => {
<Pressable style={styles.button}onPress={() => {
if (!processing){
createNewGroup(groupName)
setProcessing(true)
}
}
}><Text style={styles.descriptiveText}>Create new group</Text></Pressable>


{/* </View> */}
</>
)
}
18 changes: 13 additions & 5 deletions app/(login)/(groupScreen)/group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,27 @@ export default function GroupScreen() {
)
}

function getSmallTextComponent() {
function getMainScreenTextComponent() {
return (
<View style={{alignItems: "center"}}>
{/* <View style={styles.separator}/> */}
<View style={{alignItems: "center"}}>
<Pressable onPress={() => setCurrentState(State.create)}><Text style={styles.descriptiveText}>Create new group</Text></Pressable>
<Pressable onPress={() => logout()}><Text style={styles.descriptiveText}>Log out</Text></Pressable>
</View>
)
}
function getNonMainScreenTextComponent() {
return (
<View style={{alignItems: "center"}}>
<Pressable onPress={() => setCurrentState(State.buttons)}><Text style={styles.descriptiveText}>Go back</Text></Pressable>
<Pressable onPress={() => logout()}><Text style={styles.descriptiveText}>Log out</Text></Pressable>
</View>
)
}

function logout() {
console.log("tried to log out")
user.current.logout()
router.replace('../login')
router.replace('/login')
}

return (
Expand All @@ -75,7 +82,8 @@ export default function GroupScreen() {
<ImageBackground source={require('../../../assets/images/accountScreensImage.png')} style={styles.backgroundImage}>
<LogoAndName/>
{getActiveComponent(currentState)}
{currentState != State.create && getSmallTextComponent()}
{currentState == State.buttons && getMainScreenTextComponent()}
{currentState != State.buttons && getNonMainScreenTextComponent()}
</ImageBackground>
</View>
</>
Expand Down
4 changes: 2 additions & 2 deletions app/(login)/(groupScreen)/joinGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ export default function getCreateComponent(){
}
return (
<>
<Text style={styles.descriptiveText}> Join a group by typing its unique id </Text>
<View style={{alignItems:"center"}}><Text style={styles.explainerText}> Join a group by typing its unique id </Text></View>
<Text style={styles.descriptiveText}>Group id</Text>
<View style={styles.inputBox}>
<TextInput style={styles.inputField} value={uuid} onChangeText={(uuid) =>{setUuid(uuid)}}/>
</View>
<Pressable onPress={() => {
<Pressable style={styles.button} onPress={() => {
if (!processing){
joinGroup(uuid)
setProcessing(true)
Expand Down
3 changes: 1 addition & 2 deletions app/(login)/(groupScreen)/joinGroupBluetooth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import GroupScreen from "./group"
export default function getBluetoothComponent() {
return (
<View>
<Text> Bluetooth placeholder </Text>
<Pressable onPress={() => router.replace("./group")}><Text style={styles.descriptiveText}>Go back</Text></Pressable>
<Text> Bluetooth placeholder </Text>
</View>
)
}
5 changes: 2 additions & 3 deletions app/(login)/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ export default function loginScreen () {

// TODO: Create useGroup
group.current.checkIfInGroup((ack: Boolean) => {
if (ack) {
group.current.setPeers();
router.replace('../shoppingList');
if (false) {
router.replace('/shoppingList');
}else{
router.replace('/group');
}
Expand Down
4 changes: 4 additions & 0 deletions app/(login)/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ const styles = StyleSheet.create({
fontSize: 15,
fontWeight: "bold",
},
explainerText: {
fontSize: 17,
color: "white",
},
});

export default styles
17 changes: 4 additions & 13 deletions handlers/group.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {randomUUID} from 'expo-crypto';
interface IGroup {
create(groupName: string, action : () => void): void;
join(uuid: string, action : (ack: Boolean) => void): void;
checkIfInGroup(action : (ack: Boolean) => void): void ;
leave() : Boolean;
setPeers() : void;
create(groupName: string, callback : () => void): void;
join(uuid: string, callback : (ack: Boolean) => void): void;
checkIfInGroup(callback : (ack: Boolean) => void): void ;
leave() : Boolean;
}

class GroupHandle implements IGroup {
Expand Down Expand Up @@ -43,14 +42,6 @@ class GroupHandle implements IGroup {
})
}

public setPeers() : void { // Currently does not do anything, peer discovery should be kinda manually handled by GUN itself
this.checkIfInGroup((ack) => {
if (ack){
let members = user.get("group").get("members")
}
})
}

public leave() : Boolean {
user.get("group").put(null)
return true
Expand Down
24 changes: 11 additions & 13 deletions handlers/user.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
interface IAuth {
create(fullName: string, email: string, phoneNumber: string, password: string, login: (ack: any) => Boolean): void;
login(phoneNumber: string, password: string, success: (ack: any, user: UserGunDB) => Boolean): void;
create(fullName: string, email: string, phoneNumber: string, password: string, callback: (ack: any) => Boolean): void;
login(phoneNumber: string, password: string, callback: (ack: any, user: UserGunDB) => Boolean): void;
logout() : void;
}

Expand All @@ -11,34 +11,32 @@ class UserHandle implements IAuth {
this.user = this.gun.user();
}

public create(fullName: string, email: string, phoneNumber: string, password: string, login: (ack: any, user: UserGunDB) => Boolean): void {
public create(fullName: string, email: string, phoneNumber: string, password: string, callback: (ack: any, user: UserGunDB) => Boolean): void {
user.create(phoneNumber, password, (ack: any) => {
if (ack.err != undefined) {
login(ack,undefined)
callback(ack,undefined)
return false;
}

const newUser = gun.user(ack.pub);
const newUser = gun.user(ack.soul);
newUser.get("fullName").put(fullName);
newUser.get("email").put(email);
this.login(phoneNumber,password, login)
this.login(phoneNumber,password, callback)
});
}

public login(phoneNumber: string, password: string, success: (ack: any, user: UserGunDB) => Boolean): void {
public login(phoneNumber: string, password: string, callback: (ack: any, user: UserGunDB) => Boolean): void {
this.user.auth(phoneNumber, password, (ack: any) => {
success(ack, user)
if (ack != undefined){
userPub = ack.soul
}
callback(ack, user)
});

}

public logout() : void {
this.user.leave()
}

private isLoggedIn(): boolean {
return this.user.is;
}
}

export function userHandle(gun: Gun): IAuth {
Expand Down

0 comments on commit 2853c60

Please sign in to comment.