Skip to content

Commit

Permalink
Restyled by clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
restyled-commits committed Dec 9, 2023
1 parent 9e5ba7c commit bd94e62
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 232 deletions.
2 changes: 1 addition & 1 deletion src/assets/sounds/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import lightOffSound from "./lightOff.mp3";
import lightOnSound from "./lightOn.mp3";
import successSound from "./success.mp3";

export { backBtnSound, errorSound, lightOffSound, lightOnSound, successSound };
export {backBtnSound, errorSound, lightOffSound, lightOnSound, successSound};
2 changes: 1 addition & 1 deletion src/components/SettingsComponents/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import DeleteAccount from "./DeleteAccount";
import SettingsSidebar from "./Sidebar";
import SoundSetting from "./Sounds";

export { DeleteAccount, SettingsSidebar, SoundSetting };
export {DeleteAccount, SettingsSidebar, SoundSetting};
2 changes: 1 addition & 1 deletion src/js/deleteImg.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { storage } from "../lib/firebase";
import {storage} from "../lib/firebase";

export default async function deleteImg(imageUrl) {
if (imageUrl && imageUrl !== "") {
Expand Down
91 changes: 45 additions & 46 deletions src/js/postFn.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
import firebase from "firebase/compat/app";

import { db, storage } from "../lib/firebase";
import {db, storage} from "../lib/firebase";

import { playErrorSound, playSuccessSound } from "./sounds";
import {playErrorSound, playSuccessSound} from "./sounds";

export const deletePost = async (
uid,
postId,
imageUrl,
enqueueSnackbar,
setOpen,
) => {
uid,
postId,
imageUrl,
enqueueSnackbar,
setOpen,
) => {
try {
await db
.runTransaction(async (transaction) => {
// Delete doc ref from user doc
const docRef = db.collection("users").doc(uid);
transaction.update(docRef, {
posts: firebase.firestore.FieldValue.arrayRemove(postId),
});

// Delete the post document
const postRef = db.collection("posts").doc(postId);
transaction.delete(postRef);
})
.then(async () => {
if (imageUrl !== "") {
const url = JSON.parse(imageUrl);
const deleteImagePromises = url.map(({ imageUrl }) => {
const imageRef = storage.refFromURL(imageUrl);
return imageRef.delete();
.runTransaction(async (transaction) => {
// Delete doc ref from user doc
const docRef = db.collection("users").doc(uid);
transaction.update(docRef, {
posts : firebase.firestore.FieldValue.arrayRemove(postId),
});
await Promise.all(deleteImagePromises);
}
})
.then(() => {
playSuccessSound();
enqueueSnackbar("Post deleted successfully!", { variant: "success" });
setOpen(false);
});

// Delete the post document
const postRef = db.collection("posts").doc(postId);
transaction.delete(postRef);
})
.then(async () => {
if (imageUrl !== "") {
const url = JSON.parse(imageUrl);
const deleteImagePromises = url.map(({imageUrl}) => {
const imageRef = storage.refFromURL(imageUrl);
return imageRef.delete();
});
await Promise.all(deleteImagePromises);
}
})
.then(() => {
playSuccessSound();
enqueueSnackbar("Post deleted successfully!", {variant : "success"});
setOpen(false);
});
} catch (error) {
playErrorSound();
enqueueSnackbar(`Error deleting post: ${error}`, { variant: "error" });
enqueueSnackbar(`Error deleting post: ${error}`, {variant : "error"});
}
};

Expand All @@ -61,20 +61,19 @@ export const savePost = async (postId) => {

export const deleteComment = async (postId, commentId, enqueueSnackbar) => {
try {
await db
.collection("posts")
.doc(postId)
.collection("comments")
.doc(commentId)
.delete()
.then(() => {
playSuccessSound();
enqueueSnackbar("Comment deleted successfully!", {
variant: "success",
await db.collection("posts")
.doc(postId)
.collection("comments")
.doc(commentId)
.delete()
.then(() => {
playSuccessSound();
enqueueSnackbar("Comment deleted successfully!", {
variant : "success",
});
});
});
} catch (error) {
playErrorSound();
enqueueSnackbar(`Error deleting comment: ${error}`, { variant: "error" });
enqueueSnackbar(`Error deleting comment: ${error}`, {variant : "error"});
}
};
80 changes: 40 additions & 40 deletions src/js/signIn.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
import { auth, db, facebookProvider, googleProvider } from "../lib/firebase";
import {auth, db, facebookProvider, googleProvider} from "../lib/firebase";

import { playErrorSound, playSuccessSound } from "./sounds";
import {playErrorSound, playSuccessSound} from "./sounds";

const signInWithOAuth = (e, enqueueSnackbar, navigate, google = true) => {
e.preventDefault();
const provider = google ? googleProvider : facebookProvider;
auth
.signInWithPopup(provider)
.then(async (val) => {
const userRef = db.collection("users").where("uid", "==", val?.user?.uid);
auth.signInWithPopup(provider)
.then(async (val) => {
const userRef =
db.collection("users").where("uid", "==", val?.user?.uid);

const docSnap = await userRef.get();
if (docSnap.docs.length < 1) {
const usernameDoc = db.collection("users");
await usernameDoc.doc(auth.currentUser.uid).set({
uid: val.user.uid,
username: val.user.uid,
name: val.user.displayName,
photoURL: val.user.photoURL,
displayName: val.user.displayName,
Friends: [],
posts: [],
const docSnap = await userRef.get();
if (docSnap.docs.length < 1) {
const usernameDoc = db.collection("users");
await usernameDoc.doc(auth.currentUser.uid).set({
uid : val.user.uid,
username : val.user.uid,
name : val.user.displayName,
photoURL : val.user.photoURL,
displayName : val.user.displayName,
Friends : [],
posts : [],
});
} else if (!docSnap.docs[0].data().username) {
docSnap.docs[0].ref.update({
username : doc.data().uid,
});
}
playSuccessSound();
enqueueSnackbar("Login successful!", {
variant : "success",
});
} else if (!docSnap.docs[0].data().username) {
docSnap.docs[0].ref.update({
username: doc.data().uid,
});
}
playSuccessSound();
enqueueSnackbar("Login successful!", {
variant: "success",
navigate("/");
})
.catch((error) => {
if (error.code === "auth/account-exists-with-different-credential") {
playErrorSound();
enqueueSnackbar("Account exists with a different credential", {
variant : "error",
});
} else {
playErrorSound();
enqueueSnackbar(error.message, {
variant : "error",
});
}
});
navigate("/");
})
.catch((error) => {
if (error.code === "auth/account-exists-with-different-credential") {
playErrorSound();
enqueueSnackbar("Account exists with a different credential", {
variant: "error",
});
} else {
playErrorSound();
enqueueSnackbar(error.message, {
variant: "error",
});
}
});
};

export default signInWithOAuth;
2 changes: 1 addition & 1 deletion src/js/userData.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { auth, db } from "../lib/firebase";
import {auth, db} from "../lib/firebase";

export default async function getUserSessionData(getRef) {
const user = auth?.currentUser;
Expand Down
Loading

0 comments on commit bd94e62

Please sign in to comment.