Skip to content
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

Feat: move signout button #277

Merged
merged 9 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 44 additions & 44 deletions client/app/components/auth/AuthButtons.tsx
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
import { useFonts } from "expo-font";

Check warning on line 1 in client/app/components/auth/AuthButtons.tsx

View workflow job for this annotation

GitHub Actions / lint (21.x)

'useFonts' is defined but never used
import React, { useState } from "react";

Check warning on line 2 in client/app/components/auth/AuthButtons.tsx

View workflow job for this annotation

GitHub Actions / lint (21.x)

'useState' is defined but never used
import {
StyleSheet,
Text,
TouchableOpacity,
Dimensions,
Alert,

Check warning on line 8 in client/app/components/auth/AuthButtons.tsx

View workflow job for this annotation

GitHub Actions / lint (21.x)

'Alert' is defined but never used
Image,
ImageSourcePropType,
} from "react-native";

import { appSignOut } from "../../services/AuthStore";
// Migrated to SettingsScree.tsx

interface SignOutButtonProps {}
// import { appSignOut } from "../../services/AuthStore";
// interface SignOutButtonProps {}
// export const SignOutButton: React.FC<SignOutButtonProps> = () => {
// const [loading, setLoading] = useState(false);

export const SignOutButton: React.FC<SignOutButtonProps> = () => {
const [loading, setLoading] = useState(false);
// const handleSignOut = async () => {
// Alert.alert(
// "Confirm Sign Out",
// "Are you sure you want to sign out?",
// [
// {
// text: "Cancel",
// style: "cancel",
// },
// {
// text: "Sign Out",
// onPress: async () => {
// setLoading(true);
// const response = await appSignOut();
// setLoading(false);

const handleSignOut = async () => {
Alert.alert(
"Confirm Sign Out",
"Are you sure you want to sign out?",
[
{
text: "Cancel",
style: "cancel",
},
{
text: "Sign Out",
onPress: async () => {
setLoading(true);
const response = await appSignOut();
setLoading(false);
// if (response?.user === null) {
// console.log("Sign out successful");
// } else if (response?.error) {
// console.log(response.error);
// Alert.alert(
// "Sign Out Failed",
// "An error occurred during sign out. Please try again.",
// );
// }
// },
// },
// ],
// { cancelable: false },
// );
// };

if (response?.user === null) {
console.log("Sign out successful");
} else if (response?.error) {
console.log(response.error);
Alert.alert(
"Sign Out Failed",
"An error occurred during sign out. Please try again.",
);
}
},
},
],
{ cancelable: false },
);
};

return (
<TouchableOpacity
style={styles.sign_out_button}
onPress={handleSignOut}
disabled={loading}>
<Text style={styles.button_text}>Sign Out</Text>
</TouchableOpacity>
// return (
// <TouchableOpacity
// style={styles.sign_out_button}
// onPress={handleSignOut}
// disabled={loading}>
// <Text style={styles.button_text}>Sign Out</Text>
// </TouchableOpacity>

);
};
// );
// };

export const LogInButton: React.FC<{ onPress?: () => void }> = ({
onPress,
Expand Down
1 change: 0 additions & 1 deletion client/app/screens/chat/ChatScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Dimensions,
} from "react-native";

import { SignOutButton } from "../../components/auth/AuthButtons";

Check warning on line 11 in client/app/screens/chat/ChatScreen.tsx

View workflow job for this annotation

GitHub Actions / lint (21.x)

'SignOutButton' is defined but never used
import { ChatScreenFooter } from "../../components/chat/ChatScreenFooter";
import MessageChannel from "../../components/chat/MessageChannel";
import { useLocation } from "../../contexts/LocationContext";
Expand Down Expand Up @@ -100,7 +100,6 @@
Chat Screen
</Text>
</View>
<SignOutButton />
<View style={styles.chatContainer}>
<MessageChannel messages={messages} />
</View>
Expand Down
94 changes: 81 additions & 13 deletions client/app/screens/settings/SettingsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ import {
Modal,
Button,
FlatList,
TouchableWithoutFeedback
TouchableWithoutFeedback,
TouchableOpacity,
Alert
} from "react-native";

import { SettingsItem } from "../../components/settings/SettingsItem";
import {ColorInput, DisplayNameInput} from "@app/components/settings/TextInputs";
import { appSignOut } from "../../services/AuthStore";

// List of settings items
// toggle type: a switch
Expand All @@ -41,10 +44,13 @@ const Sections = [
header: "Privacy",
items: [{ id: "deleteMessages", title: "Delete messages", type: "toggle" }],
},
{
header: "Manage Account",
items: [{ id: "signOut", title: "Sign Out", type: "select" }],
}
];

const SettingsScreen: React.FC = () => {
// settings values (will be changed later to reflect the actual settings)
const [data, setData] = useState({
displayName: "Display Name",
profilePicIndex: 0, // index for icons array
Expand Down Expand Up @@ -75,6 +81,40 @@ const SettingsScreen: React.FC = () => {
require("../../../assets/icons/user/fake_pfp.jpg"),
];

const [loading, setLoading] = useState(false);

const handleSignOut = async () => {
Alert.alert(
"Confirm Sign Out",
"Are you sure you want to sign out?",
[
{
text: "Cancel",
style: "cancel",
},
{
text: "Sign Out",
onPress: async () => {
setLoading(true);
const response = await appSignOut();
setLoading(false);

if (response?.user === null) {
console.log("Sign out successful");
} else if (response?.error) {
console.log(response.error);
Alert.alert(
"Sign Out Failed",
"An error occurred during sign out. Please try again.",
);
}
},
},
],
{ cancelable: false }
);
};

return (
<SafeAreaView style={styles.safeAreaStyle}>
<ScrollView style={styles.container}>
Expand Down Expand Up @@ -168,16 +208,31 @@ const SettingsScreen: React.FC = () => {
<Text style={styles.sectionHeaderText}>{header}</Text>
</View>
<View style={styles.sectionContent}>
{items.map(({ id, title, type }) => (
<SettingsItem
key={id}
id={id}
title={title}
type={type}
setter={setData}
data={data}
/>
))}
{items.map(({ id, title, type }) => {
if (id === "signOut") {
return (
<TouchableOpacity
key={id}
style={styles.signOutRow}
onPress={handleSignOut}
disabled={loading}
>
<Text style={styles.signOutText}>Sign Out</Text>
</TouchableOpacity>
);
}

return (
<SettingsItem
key={id}
id={id}
title={title}
type={type}
setter={setData}
data={data}
/>
);
})}
</View>
</View>
))}
Expand All @@ -187,7 +242,6 @@ const SettingsScreen: React.FC = () => {
};

const styles = StyleSheet.create({
// Styles
safeAreaStyle: {
flex: 1,
backgroundColor: "#f6f6f6",
Expand Down Expand Up @@ -242,6 +296,20 @@ const styles = StyleSheet.create({
marginLeft: "auto",
height: "50%", // For some reason I can't get the view to auto fit height to children so just set to 50% for now
},
signOutRow: {
paddingHorizontal: 24,
paddingVertical: 12,
borderBottomWidth: 1,
borderColor: "#e3e3e3",
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center",
},
signOutText: {
fontSize: 16,
fontWeight: "600",
color: "red",
},
});

export default SettingsScreen;
2 changes: 1 addition & 1 deletion client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
},
"include": ["**/*.ts", "**/*.tsx", "env.d.ts"],
"exclude": ["node_modules"]
}
}
Loading