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

Add Profile Pic Removal Button #340

Merged
merged 13 commits into from
Sep 6, 2024
72 changes: 57 additions & 15 deletions app/content/profile/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import { getErrorString, getPfpName } from "~/Utility";
import ProfilePicture from "~/components/ProfilePicture";
import BottomSheetWrapper from "~/components/bottomSheetWrapper";
import DialogComponent from "~/components/dialog";
import DrillList from "~/components/drillList";
import EmptyScreen from "~/components/emptyScreen";
import ErrorComponent from "~/components/errorComponent";
Expand Down Expand Up @@ -85,6 +86,10 @@
const [newPassword, setNewPassword] = useState("");
const [newPasswordCheck, setNewPasswordCheck] = useState("");
const [passwordInputVisible, setPasswordInputVisible] = useState(false);
const [uploadLoading, setUploadLoading] = useState(false);
const [removeLoading, setRemoveLoading] = useState(false);
const [uploadDialogVisible, setUploadDialogVisible] = useState(false);
const hideUploadDialog = () => setUploadDialogVisible(false);

const [imageUploading, setImageUploading] = useState(false);

Expand All @@ -97,7 +102,7 @@
setEmail(userEmail);
}, [userData, userEmail]);

const handleUpdate = useCallback(

Check warning on line 105 in app/content/profile/index.js

View workflow job for this annotation

GitHub Actions / prettier-check

React Hook useCallback received a function whose dependencies are unknown. Pass an inline function instead
debounce(
async () => {
setUpdateLoading(true);
Expand Down Expand Up @@ -300,6 +305,55 @@

return (
<BottomSheetModalProvider>
<DialogComponent
title={"Edit Profile Pic"}
content={"Upload New Pic, or Remove Current Pic"}
solderq35 marked this conversation as resolved.
Show resolved Hide resolved
visible={uploadDialogVisible}
onHide={hideUploadDialog}
buttons={[
{
children: "Remove ",
pressHandler: async () => {
setRemoveLoading(true);
try {
await updateDoc(userRef, {
solderq35 marked this conversation as resolved.
Show resolved Hide resolved
pfp: "",
});
await invalidateMultipleKeys(queryClient, [["userInfo"]]);
} catch (e) {
console.log(e);
showDialog("Error", getErrorString(e));
}
setRemoveLoading(false);
hideUploadDialog();
},
loading: removeLoading,
},
{
children: "Upload",
solderq35 marked this conversation as resolved.
Show resolved Hide resolved
pressHandler: async () => {
setUploadLoading(true);
try {
await handleImageUpload(
setImageUploading,
showSnackBar,
getPfpName(currentTeamId, userId),
userRef,
profilePicSize,
profilePicSize,
);
await invalidateMultipleKeys(queryClient, [["userInfo"]]);
} catch (e) {
console.log(e);
showDialog("Error", getErrorString(e));
}
setUploadLoading(false);
hideUploadDialog();
},
loading: uploadLoading,
},
]}
/>
<SafeAreaView style={{ flex: 1 }} edges={["right", "top", "left"]}>
<Header
title={"Personal Profile"}
Expand Down Expand Up @@ -328,21 +382,9 @@
<View style={styles.modalContent}>
{/* Profile Picture */}
<TouchableOpacity
onPress={async () => {
try {
await handleImageUpload(
setImageUploading,
showSnackBar,
getPfpName(currentTeamId, userId),
userRef,
profilePicSize,
profilePicSize,
);
await invalidateMultipleKeys(queryClient, [["userInfo"]]);
} catch (e) {
console.log(e);
showDialog("Error", getErrorString(e));
}
onPress={() => {
console.log("PFP Upload Pressed!");
setUploadDialogVisible(true);
}}
>
<View style={styles.profilePictureContainer}>
Expand Down
Loading