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 Sep 18, 2023
1 parent 79d1b2b commit 22d0360
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 229 deletions.
6 changes: 3 additions & 3 deletions src/assets/sounds/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import backBtnSound from "./backBtn.mp3";
import errorSound from "./error.mp3";
import successSound from "./success.mp3";
import lightOnSound from "./lightOn.mp3";
import lightOffSound from "./lightOff.mp3";
import lightOnSound from "./lightOn.mp3";
import successSound from "./success.mp3";

export { backBtnSound, errorSound, successSound, lightOnSound, lightOffSound };
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};
5 changes: 3 additions & 2 deletions src/components/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import NotFound from "../pages/NotFound";

import Caption from "./Caption";
import ChatBox from "./CommunityChat";
import EditProfile from "./EditProfile";
Expand All @@ -6,7 +8,6 @@ import GuestSignInBtn from "./Guest/GuestSignInBtn";
import GuestSignUpBtn from "./Guest/GuestSignUpBtn";
import ImgUpload from "./ImgUpload";
import Navbar from "./Navbar";
import NotFound from "../pages/NotFound";
import Notifications from "./Notification";
import Post from "./Post";
import ReadMore from "./ReadMore";
Expand All @@ -18,6 +19,7 @@ export {
Caption,
ChatBox,
EditProfile,
FriendsComponent,
GuestSignInBtn,
GuestSignUpBtn,
ImgUpload,
Expand All @@ -29,7 +31,6 @@ export {
SideBar,
StoryView,
Suggestion,
FriendsComponent,
};

export default Post;
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
82 changes: 41 additions & 41 deletions src/js/postFn.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
import { db, storage } from "../lib/firebase";
import { playErrorSound, playSuccessSound } from "./sounds";

import firebase from "firebase/compat/app";

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

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 @@ -60,10 +61,9 @@ export const savePost = async (postId) => {

export const deleteComment = async (event, postId, commentId) => {
event.preventDefault();
await db
.collection("posts")
.doc(postId)
.collection("comments")
.doc(commentId)
.delete();
await db.collection("posts")
.doc(postId)
.collection("comments")
.doc(commentId)
.delete();
};
81 changes: 41 additions & 40 deletions src/js/signIn.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,51 @@
import { auth, db, facebookProvider, googleProvider } from "../lib/firebase";
import { playErrorSound, playSuccessSound } from "./sounds";
import {auth, db, facebookProvider, googleProvider} from "../lib/firebase";

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: [],
});
} else if (!docSnap.docs[0].data().username) {
docSnap.docs[0].ref.update({
username: doc.data().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 : [],
});
} else if (!docSnap.docs[0].data().username) {
docSnap.docs[0].ref.update({
username : doc.data().uid,
});
}
playSuccessSound();
enqueueSnackbar("Login successful!", {
variant : "success",
});
}
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 { db, auth } 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 22d0360

Please sign in to comment.