Skip to content

Commit

Permalink
Restyled by prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
restyled-commits committed Dec 9, 2023
1 parent bd94e62 commit 834115f
Show file tree
Hide file tree
Showing 14 changed files with 250 additions and 236 deletions.
16 changes: 8 additions & 8 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ const SignupScreen = React.lazy(() => import("./pages/Signup"));
const ForgotPassword = React.lazy(() => import("./pages/ForgotPassword"));
const Friends = React.lazy(() => import("./pages/Friends"));
const NotFound = React.lazy(() => import("./pages/NotFound"));
const Contributors = React.lazy(
() => import("./pages/FooterPages/ContributorPage"),
const Contributors = React.lazy(() =>
import("./pages/FooterPages/ContributorPage"),
);
const HelpCenter = React.lazy(() => import("./pages/FooterPages/HelpCenter"));
// ------------------------------------- Components ------------------------------------------------
const Notifications = React.lazy(() => import("./components/Notification"));
const SideBar = React.lazy(() => import("./components/SideBar"));
const Navbar = React.lazy(() => import("./components/Navbar"));
const DeleteAccount = React.lazy(
() => import("./components/SettingsComponents/DeleteAccount"),
const DeleteAccount = React.lazy(() =>
import("./components/SettingsComponents/DeleteAccount"),
);
const SettingsSidebar = React.lazy(
() => import("./components/SettingsComponents/Sidebar"),
const SettingsSidebar = React.lazy(() =>
import("./components/SettingsComponents/Sidebar"),
);
const SoundSetting = React.lazy(
() => import("./components/SettingsComponents/Sounds"),
const SoundSetting = React.lazy(() =>
import("./components/SettingsComponents/Sounds"),
);

export function getModalStyle() {
Expand Down
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 };
4 changes: 2 additions & 2 deletions src/components/postView/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import firebase from "firebase/compat/app";
import useCreatedAt from "../../hooks/useCreatedAt.jsx";
import { useNavigate } from "react-router-dom";

const ImageSlider = React.lazy(
() => import("../../reusableComponents/ImageSlider"),
const ImageSlider = React.lazy(() =>
import("../../reusableComponents/ImageSlider"),
);
const PostDetails = React.lazy(() => import("./PostDetails.jsx"));

Expand Down
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: 46 additions & 45 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();
});
await Promise.all(deleteImagePromises);
}
})
.then(() => {
playSuccessSound();
enqueueSnackbar("Post deleted successfully!", {variant : "success"});
setOpen(false);
.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();
});
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,19 +61,20 @@ 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 : [],
});
} else if (!docSnap.docs[0].data().username) {
docSnap.docs[0].ref.update({
username : doc.data().uid,
});
}
playSuccessSound();
enqueueSnackbar("Login successful!", {
variant : "success",
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: [],
});
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",
});
}
} 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",
});
}
});
};

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 834115f

Please sign in to comment.