Skip to content
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
4 changes: 2 additions & 2 deletions app/community/[communityId]/comments/[pid]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getCommunityData } from "@/lib/communities";
import { getPost } from "@/lib/posts";
import { getCommunityData } from "@/lib/community/getCommunityData";
import PostClientPage from "./PostClientPage";
import { notFound } from "next/navigation";
import { getPost } from "@/lib/post/getPost";

export default async function PostPage({
params,
Expand Down
2 changes: 1 addition & 1 deletion app/community/[communityId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getCommunityData } from "@/lib/communities";
import { getCommunityData } from "@/lib/community/getCommunityData";
import CommunityClientPage from "./CommunityClientPage";
import { notFound } from "next/navigation";

Expand Down
2 changes: 1 addition & 1 deletion app/community/[communityId]/submit/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getCommunityData } from "@/lib/communities";
import { getCommunityData } from "@/lib/community/getCommunityData";
import SubmitPostClientPage from "./SubmitPostClientPage";
import { notFound } from "next/navigation";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
Stack,
Text,
} from "@chakra-ui/react";
import { CommunityMember } from "@/lib/communityMembers";
import { CommunityMember } from "@/lib/community/fetchCommunityMembers";
import useCommunityMembers from "@/hooks/community/useCommunityMembers";

type CommunityMembersModalProps = {
Expand Down
4 changes: 2 additions & 2 deletions hooks/community/useCommunityMembers.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use client';
"use client";

import { useCallback, useState } from "react";
import {
CommunityMember,
fetchCommunityMembers,
} from "@/lib/communityMembers";
} from "@/lib/community/fetchCommunityMembers";

const useCommunityMembers = () => {
const [members, setMembers] = useState<CommunityMember[]>([]);
Expand Down
10 changes: 4 additions & 6 deletions hooks/useUserProfile.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { postStateAtom } from "@/atoms/postsAtom";
import { auth } from "@/firebase/clientApp";
import {
deleteProfileImage,
updateUserCommentsName,
updateUserPostsName,
uploadProfileImage,
} from "@/lib/userProfile";
import { deleteProfileImage } from "@/lib/user-profile/deleteProfileImage";
import { updateUserCommentsName } from "@/lib/user-profile/updateUserCommentsName";
import { updateUserPostsName } from "@/lib/user-profile/updateUserPostsName";
import { uploadProfileImage } from "@/lib/user-profile/uploadProfileImage";
import { useSetAtom } from "jotai";
import { useRouter } from "next/navigation";
import { useState } from "react";
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions lib/user-profile/deleteProfileImage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { storage } from "@/firebase/clientApp";
import { deleteObject, ref } from "firebase/storage";

/**
* Deletes the profile image from Firebase Storage.
* @param userId - ID of the user
*/
export const deleteProfileImage = async (userId: string) => {
const imageRef = ref(storage, `users/${userId}/profileImage`);
await deleteObject(imageRef);
};
28 changes: 28 additions & 0 deletions lib/user-profile/updateUserCommentsName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { firestore } from "@/firebase/clientApp";
import { collection, doc, getDocs, query, where, writeBatch } from "firebase/firestore";

/**
* Updates the name of the creator of the comments.
* Finds all the comments a user has created and updates the creator name.
* @param userId - ID of the user whose comments are to be updated
* @param newUserName - New name of the user
*/
export const updateUserCommentsName = async (
userId: string,
newUserName: string
) => {
const commentsQuery = query(
collection(firestore, "comments"),
where("creatorId", "==", userId)
);
const commentsSnapshot = await getDocs(commentsQuery);

const batch = writeBatch(firestore);

commentsSnapshot.forEach((commentDoc) => {
const commentRef = doc(firestore, "comments", commentDoc.id);
batch.update(commentRef, { creatorDisplayText: newUserName });
});

await batch.commit();
};
28 changes: 28 additions & 0 deletions lib/user-profile/updateUserPostsName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { firestore } from "@/firebase/clientApp";
import { collection, doc, getDocs, query, where, writeBatch } from "firebase/firestore";

/**
* Updates the name of the creator of the posts.
* Finds all the posts a user has created and updates the creator name.
* @param userId - ID of the user whose posts are to be updated
* @param newUserName - New name of the user
*/
export const updateUserPostsName = async (
userId: string,
newUserName: string
) => {
const postsQuery = query(
collection(firestore, "posts"),
where("creatorId", "==", userId)
);
const postsSnapshot = await getDocs(postsQuery);

const batch = writeBatch(firestore);

postsSnapshot.forEach((postDoc) => {
const postRef = doc(firestore, "posts", postDoc.id);
batch.update(postRef, { creatorUsername: newUserName });
});

await batch.commit();
};
17 changes: 17 additions & 0 deletions lib/user-profile/uploadProfileImage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { storage } from "@/firebase/clientApp";
import { getDownloadURL, ref, uploadString } from "firebase/storage";

/**
* Uploads a profile image to Firebase Storage.
* @param userId - ID of the user
* @param selectedFile - Base64 string of the image
* @returns Download URL of the uploaded image
*/
export const uploadProfileImage = async (
userId: string,
selectedFile: string
) => {
const imageRef = ref(storage, `users/${userId}/profileImage`);
await uploadString(imageRef, selectedFile, "data_url");
return await getDownloadURL(imageRef);
};
91 changes: 0 additions & 91 deletions lib/userProfile.ts

This file was deleted.

Loading