From 46a51f7dbc961eb184e6e8d052e3ab42f8b830df Mon Sep 17 00:00:00 2001 From: Maruf Bepary Date: Sun, 7 Dec 2025 20:27:52 +0000 Subject: [PATCH 1/4] REFACTOR: Moved admin user type to types folder --- components/Modal/CommunitySettings/AdminManager.tsx | 2 +- hooks/admin/useAddAdmin.ts | 2 +- hooks/admin/useAdminList.ts | 2 +- hooks/admin/useAdminSearch.ts | 2 +- hooks/admin/useRemoveAdmin.ts | 2 +- lib/community/fetchCommunityAdmins.ts | 2 +- lib/community/findUserByEmail.ts | 2 +- lib/community/searchUsersByEmail.ts | 2 +- lib/community/adminTypes.ts => types/adminUserType.ts | 0 9 files changed, 8 insertions(+), 8 deletions(-) rename lib/community/adminTypes.ts => types/adminUserType.ts (100%) diff --git a/components/Modal/CommunitySettings/AdminManager.tsx b/components/Modal/CommunitySettings/AdminManager.tsx index 528b2bd..2c6968e 100644 --- a/components/Modal/CommunitySettings/AdminManager.tsx +++ b/components/Modal/CommunitySettings/AdminManager.tsx @@ -16,7 +16,7 @@ import { } from "@chakra-ui/react"; import React, { useEffect, useState } from "react"; import { useAuthState } from "react-firebase-hooks/auth"; -import { AdminUser } from "@/lib/community/adminTypes"; +import { AdminUser } from "@/types/adminUserType"; type AdminManagerProps = { communityData: Community; diff --git a/hooks/admin/useAddAdmin.ts b/hooks/admin/useAddAdmin.ts index b4e680b..5a92846 100644 --- a/hooks/admin/useAddAdmin.ts +++ b/hooks/admin/useAddAdmin.ts @@ -1,5 +1,5 @@ import { Community, communityStateAtom } from "@/atoms/communitiesAtom"; -import { AdminUser } from "@/lib/community/adminTypes"; +import { AdminUser } from "@/types/adminUserType"; import { addCommunityAdmin } from "@/lib/community/addCommunityAdmin"; import { useSetAtom } from "jotai"; import { Dispatch, SetStateAction, useCallback } from "react"; diff --git a/hooks/admin/useAdminList.ts b/hooks/admin/useAdminList.ts index 4f42690..9a5d33f 100644 --- a/hooks/admin/useAdminList.ts +++ b/hooks/admin/useAdminList.ts @@ -1,5 +1,5 @@ import { useCallback, useState } from "react"; -import { AdminUser } from "@/lib/community/adminTypes"; +import { AdminUser } from "@/types/adminUserType"; import { fetchCommunityAdmins } from "@/lib/community/fetchCommunityAdmins"; const useAdminList = () => { diff --git a/hooks/admin/useAdminSearch.ts b/hooks/admin/useAdminSearch.ts index 2a65b50..c6cb714 100644 --- a/hooks/admin/useAdminSearch.ts +++ b/hooks/admin/useAdminSearch.ts @@ -1,5 +1,5 @@ import { useCallback } from "react"; -import { AdminUser } from "@/lib/community/adminTypes"; +import { AdminUser } from "@/types/adminUserType"; import { findUserByEmail } from "@/lib/community/findUserByEmail"; import { searchUsersByEmail } from "@/lib/community/searchUsersByEmail"; diff --git a/hooks/admin/useRemoveAdmin.ts b/hooks/admin/useRemoveAdmin.ts index 5bd056b..bdd328e 100644 --- a/hooks/admin/useRemoveAdmin.ts +++ b/hooks/admin/useRemoveAdmin.ts @@ -1,5 +1,5 @@ import { Community, communityStateAtom } from "@/atoms/communitiesAtom"; -import { AdminUser } from "@/lib/community/adminTypes"; +import { AdminUser } from "@/types/adminUserType"; import { removeCommunityAdmin } from "@/lib/community/removeCommunityAdmin"; import { useSetAtom } from "jotai"; import { Dispatch, SetStateAction, useCallback } from "react"; diff --git a/lib/community/fetchCommunityAdmins.ts b/lib/community/fetchCommunityAdmins.ts index 5bd418d..0f35e2c 100644 --- a/lib/community/fetchCommunityAdmins.ts +++ b/lib/community/fetchCommunityAdmins.ts @@ -1,7 +1,7 @@ import { firestore } from "@/firebase/clientApp"; import { doc, getDoc } from "firebase/firestore"; -import { AdminUser } from "./adminTypes"; +import { AdminUser } from "../../types/adminUserType"; /** * Fetches all admins for a community. diff --git a/lib/community/findUserByEmail.ts b/lib/community/findUserByEmail.ts index 93c71af..3ab24da 100644 --- a/lib/community/findUserByEmail.ts +++ b/lib/community/findUserByEmail.ts @@ -1,7 +1,7 @@ import { firestore } from "@/firebase/clientApp"; import { collection, getDocs, query, where } from "firebase/firestore"; -import { AdminUser } from "./adminTypes"; +import { AdminUser } from "../../types/adminUserType"; /** * Finds a user by their exact email address. diff --git a/lib/community/searchUsersByEmail.ts b/lib/community/searchUsersByEmail.ts index 7c669ca..c8d3de6 100644 --- a/lib/community/searchUsersByEmail.ts +++ b/lib/community/searchUsersByEmail.ts @@ -1,7 +1,7 @@ import { firestore } from "@/firebase/clientApp"; import { collection, getDocs, limit, query, where } from "firebase/firestore"; -import { AdminUser } from "./adminTypes"; +import { AdminUser } from "../../types/adminUserType"; /** * Searches for users by email. diff --git a/lib/community/adminTypes.ts b/types/adminUserType.ts similarity index 100% rename from lib/community/adminTypes.ts rename to types/adminUserType.ts From 537b805688ce1c856a8149616fb275efd5312a7b Mon Sep 17 00:00:00 2001 From: Maruf Bepary Date: Sun, 7 Dec 2025 20:30:38 +0000 Subject: [PATCH 2/4] REFACTOR: Moved comment type into types folder --- components/Posts/Comments/CommentItem.tsx | 12 ++++++++++-- components/Posts/Comments/Comments.tsx | 4 ++-- hooks/comments/useCommentList.ts | 2 +- hooks/comments/useCreateComment.ts | 2 +- hooks/comments/useDeleteComment.ts | 2 +- hooks/comments/types.ts => types/comment.ts | 0 6 files changed, 15 insertions(+), 7 deletions(-) rename hooks/comments/types.ts => types/comment.ts (100%) diff --git a/components/Posts/Comments/CommentItem.tsx b/components/Posts/Comments/CommentItem.tsx index 6b60d16..0210656 100644 --- a/components/Posts/Comments/CommentItem.tsx +++ b/components/Posts/Comments/CommentItem.tsx @@ -1,5 +1,13 @@ -import { Comment } from "@/hooks/comments/types"; -import { Box, Button, Flex, Icon, Spinner, Stack, Text } from "@chakra-ui/react"; +import { Comment } from "@/types/comment"; +import { + Box, + Button, + Flex, + Icon, + Spinner, + Stack, + Text, +} from "@chakra-ui/react"; import { User } from "firebase/auth"; import React, { useState } from "react"; import { CgProfile } from "react-icons/cg"; diff --git a/components/Posts/Comments/Comments.tsx b/components/Posts/Comments/Comments.tsx index dea1332..e0fb6ca 100644 --- a/components/Posts/Comments/Comments.tsx +++ b/components/Posts/Comments/Comments.tsx @@ -1,6 +1,6 @@ /* eslint-disable react-hooks/exhaustive-deps */ import { Post } from "@/atoms/postsAtom"; -import { Comment } from "@/hooks/comments/types"; +import { Comment } from "@/types/comment"; import useCommentList from "@/hooks/comments/useCommentList"; import useCreateComment from "@/hooks/comments/useCreateComment"; import useDeleteComment from "@/hooks/comments/useDeleteComment"; @@ -201,7 +201,7 @@ const Comments: React.FC = ({ cursor="default" > - { const showToast = useCustomToast(); diff --git a/hooks/comments/useCreateComment.ts b/hooks/comments/useCreateComment.ts index 9c8a53e..a5696da 100644 --- a/hooks/comments/useCreateComment.ts +++ b/hooks/comments/useCreateComment.ts @@ -12,7 +12,7 @@ import { firestore } from "@/firebase/clientApp"; import { Post, postStateAtom } from "@/atoms/postsAtom"; import { useSetAtom } from "jotai"; import useCustomToast from "@/hooks/useCustomToast"; -import { Comment } from "./types"; +import { Comment } from "../../types/comment"; const useCreateComment = ( selectedPost: Post | null, diff --git a/hooks/comments/useDeleteComment.ts b/hooks/comments/useDeleteComment.ts index f0f7d02..1727190 100644 --- a/hooks/comments/useDeleteComment.ts +++ b/hooks/comments/useDeleteComment.ts @@ -4,7 +4,7 @@ import { firestore } from "@/firebase/clientApp"; import { postStateAtom } from "@/atoms/postsAtom"; import { useSetAtom } from "jotai"; import useCustomToast from "@/hooks/useCustomToast"; -import { Comment } from "./types"; +import { Comment } from "../../types/comment"; const useDeleteComment = ( comments: Comment[], diff --git a/hooks/comments/types.ts b/types/comment.ts similarity index 100% rename from hooks/comments/types.ts rename to types/comment.ts From 98c760d9b8e13451fd869cc8e99139c85e15bba3 Mon Sep 17 00:00:00 2001 From: Maruf Bepary Date: Sun, 7 Dec 2025 20:31:39 +0000 Subject: [PATCH 3/4] REFACTOR: Renamed admin user type --- components/Modal/CommunitySettings/AdminManager.tsx | 2 +- hooks/admin/useAddAdmin.ts | 2 +- hooks/admin/useAdminList.ts | 2 +- hooks/admin/useAdminSearch.ts | 2 +- hooks/admin/useRemoveAdmin.ts | 2 +- lib/community/fetchCommunityAdmins.ts | 2 +- lib/community/findUserByEmail.ts | 2 +- lib/community/searchUsersByEmail.ts | 2 +- types/{adminUserType.ts => adminUser.ts} | 0 9 files changed, 8 insertions(+), 8 deletions(-) rename types/{adminUserType.ts => adminUser.ts} (100%) diff --git a/components/Modal/CommunitySettings/AdminManager.tsx b/components/Modal/CommunitySettings/AdminManager.tsx index 2c6968e..dfa3d31 100644 --- a/components/Modal/CommunitySettings/AdminManager.tsx +++ b/components/Modal/CommunitySettings/AdminManager.tsx @@ -16,7 +16,7 @@ import { } from "@chakra-ui/react"; import React, { useEffect, useState } from "react"; import { useAuthState } from "react-firebase-hooks/auth"; -import { AdminUser } from "@/types/adminUserType"; +import { AdminUser } from "@/types/adminUser"; type AdminManagerProps = { communityData: Community; diff --git a/hooks/admin/useAddAdmin.ts b/hooks/admin/useAddAdmin.ts index 5a92846..5149d6e 100644 --- a/hooks/admin/useAddAdmin.ts +++ b/hooks/admin/useAddAdmin.ts @@ -1,5 +1,5 @@ import { Community, communityStateAtom } from "@/atoms/communitiesAtom"; -import { AdminUser } from "@/types/adminUserType"; +import { AdminUser } from "@/types/adminUser"; import { addCommunityAdmin } from "@/lib/community/addCommunityAdmin"; import { useSetAtom } from "jotai"; import { Dispatch, SetStateAction, useCallback } from "react"; diff --git a/hooks/admin/useAdminList.ts b/hooks/admin/useAdminList.ts index 9a5d33f..11d1830 100644 --- a/hooks/admin/useAdminList.ts +++ b/hooks/admin/useAdminList.ts @@ -1,5 +1,5 @@ import { useCallback, useState } from "react"; -import { AdminUser } from "@/types/adminUserType"; +import { AdminUser } from "@/types/adminUser"; import { fetchCommunityAdmins } from "@/lib/community/fetchCommunityAdmins"; const useAdminList = () => { diff --git a/hooks/admin/useAdminSearch.ts b/hooks/admin/useAdminSearch.ts index c6cb714..edeb507 100644 --- a/hooks/admin/useAdminSearch.ts +++ b/hooks/admin/useAdminSearch.ts @@ -1,5 +1,5 @@ import { useCallback } from "react"; -import { AdminUser } from "@/types/adminUserType"; +import { AdminUser } from "@/types/adminUser"; import { findUserByEmail } from "@/lib/community/findUserByEmail"; import { searchUsersByEmail } from "@/lib/community/searchUsersByEmail"; diff --git a/hooks/admin/useRemoveAdmin.ts b/hooks/admin/useRemoveAdmin.ts index bdd328e..4dd4897 100644 --- a/hooks/admin/useRemoveAdmin.ts +++ b/hooks/admin/useRemoveAdmin.ts @@ -1,5 +1,5 @@ import { Community, communityStateAtom } from "@/atoms/communitiesAtom"; -import { AdminUser } from "@/types/adminUserType"; +import { AdminUser } from "@/types/adminUser"; import { removeCommunityAdmin } from "@/lib/community/removeCommunityAdmin"; import { useSetAtom } from "jotai"; import { Dispatch, SetStateAction, useCallback } from "react"; diff --git a/lib/community/fetchCommunityAdmins.ts b/lib/community/fetchCommunityAdmins.ts index 0f35e2c..993ea13 100644 --- a/lib/community/fetchCommunityAdmins.ts +++ b/lib/community/fetchCommunityAdmins.ts @@ -1,7 +1,7 @@ import { firestore } from "@/firebase/clientApp"; import { doc, getDoc } from "firebase/firestore"; -import { AdminUser } from "../../types/adminUserType"; +import { AdminUser } from "../../types/adminUser"; /** * Fetches all admins for a community. diff --git a/lib/community/findUserByEmail.ts b/lib/community/findUserByEmail.ts index 3ab24da..d804c9b 100644 --- a/lib/community/findUserByEmail.ts +++ b/lib/community/findUserByEmail.ts @@ -1,7 +1,7 @@ import { firestore } from "@/firebase/clientApp"; import { collection, getDocs, query, where } from "firebase/firestore"; -import { AdminUser } from "../../types/adminUserType"; +import { AdminUser } from "../../types/adminUser"; /** * Finds a user by their exact email address. diff --git a/lib/community/searchUsersByEmail.ts b/lib/community/searchUsersByEmail.ts index c8d3de6..490fc31 100644 --- a/lib/community/searchUsersByEmail.ts +++ b/lib/community/searchUsersByEmail.ts @@ -1,7 +1,7 @@ import { firestore } from "@/firebase/clientApp"; import { collection, getDocs, limit, query, where } from "firebase/firestore"; -import { AdminUser } from "../../types/adminUserType"; +import { AdminUser } from "../../types/adminUser"; /** * Searches for users by email. diff --git a/types/adminUserType.ts b/types/adminUser.ts similarity index 100% rename from types/adminUserType.ts rename to types/adminUser.ts From 1e57aeecb9498b5a6616d30bd30f8c157b23c27f Mon Sep 17 00:00:00 2001 From: Maruf Bepary Date: Sun, 7 Dec 2025 21:09:03 +0000 Subject: [PATCH 4/4] REFACTOR: Centralised types and interfaces --- app/communities/page.tsx | 2 +- .../[communityId]/CommunityClientPage.tsx | 3 +- .../comments/[pid]/PostClientPage.tsx | 5 +- .../submit/SubmitPostClientPage.tsx | 3 +- app/page.tsx | 1 - atoms/authModalAtom.ts | 14 +----- atoms/communitiesAtom.ts | 37 +-------------- atoms/directoryMenuAtom.ts | 19 +------- atoms/postsAtom.ts | 47 +------------------ atoms/savedPostsAtom.ts | 9 +--- components/Community/about/About.tsx | 2 +- components/Community/about/AboutCommunity.tsx | 2 +- .../Community/about/AdminSectionAbout.tsx | 2 +- .../community-header/CommunityHeader.tsx | 2 +- .../CommunityMembersButton.tsx | 1 - .../community-header/CommunitySettings.tsx | 2 +- .../community-item/CommunityItem.tsx | 2 +- .../CommunityItemButtonMembersSection.tsx | 2 +- .../CommunityItemNameIconSection.tsx | 2 +- .../recommendations/RecommendationRow.tsx | 2 +- .../CommunityMembersModal.tsx | 2 +- .../Modal/CommunitySettings/AdminManager.tsx | 2 +- .../CommunitySettings/CommunitySettings.tsx | 3 +- .../Modal/CommunitySettings/ImageSettings.tsx | 2 +- .../CommunitySettings/PrivacySettings.tsx | 2 +- components/Navbar/SearchModal.tsx | 2 +- components/Posts/Comments/Comments.tsx | 2 +- components/Posts/Posts.tsx | 2 +- .../Posts/new-post-form/NewPostForm.tsx | 2 +- components/Posts/post-item/PostBody.tsx | 2 +- components/Posts/post-item/PostDetails.tsx | 2 +- components/Posts/post-item/PostItem.tsx | 2 +- components/Posts/post-item/PostTitle.tsx | 2 +- components/Posts/post-item/VoteSection.tsx | 2 +- hooks/admin/useAddAdmin.ts | 3 +- hooks/admin/useRemoveAdmin.ts | 3 +- hooks/comments/useCommentList.ts | 2 +- hooks/comments/useCreateComment.ts | 3 +- hooks/community/useCommunitiesFeed.ts | 2 +- hooks/community/useCommunityImage.ts | 3 +- hooks/community/useCommunityMembers.ts | 6 +-- .../useCommunityMembershipActions.tsx | 2 +- hooks/community/useCommunityPermissions.tsx | 2 +- hooks/community/useCommunityPrivacy.ts | 3 +- hooks/community/useCommunitySnippets.ts | 3 +- hooks/community/useDeleteCommunity.ts | 2 +- hooks/community/useJoinCommunity.tsx | 7 +-- hooks/posts/useCreatePost.ts | 2 +- hooks/posts/usePostDeletion.ts | 5 +- hooks/posts/usePostSelection.ts | 4 +- hooks/posts/usePostVote.tsx | 2 +- hooks/posts/usePostVoteSync.ts | 2 +- hooks/posts/usePostsFeed.ts | 3 +- hooks/posts/useSavedPosts.tsx | 5 +- hooks/useDirectory.tsx | 7 +-- hooks/useSearch.tsx | 4 +- lib/community/fetchCommunityMembers.ts | 7 +-- lib/post/getPost.ts | 2 +- types/authModal.ts | 4 ++ types/community.ts | 17 +++++++ types/communityMember.ts | 5 ++ types/directoryMenu.ts | 9 ++++ types/post.ts | 22 +++++++++ types/savedPost.ts | 7 +++ 64 files changed, 141 insertions(+), 195 deletions(-) create mode 100644 types/authModal.ts create mode 100644 types/community.ts create mode 100644 types/communityMember.ts create mode 100644 types/directoryMenu.ts create mode 100644 types/post.ts create mode 100644 types/savedPost.ts diff --git a/app/communities/page.tsx b/app/communities/page.tsx index 438fbf2..4732138 100644 --- a/app/communities/page.tsx +++ b/app/communities/page.tsx @@ -10,7 +10,7 @@ import useCommunityMembershipActions from "@/hooks/community/useCommunityMembers import { useIntersectionObserver } from "@/hooks/useIntersectionObserver"; import { Box, Heading, Spinner, Stack, Text } from "@chakra-ui/react"; import React, { useEffect, useMemo } from "react"; -import { Community } from "@/atoms/communitiesAtom"; +import { Community } from "@/types/community"; /** * Displays the communities page with the top 5 communities. diff --git a/app/community/[communityId]/CommunityClientPage.tsx b/app/community/[communityId]/CommunityClientPage.tsx index a5c7948..c6b72aa 100644 --- a/app/community/[communityId]/CommunityClientPage.tsx +++ b/app/community/[communityId]/CommunityClientPage.tsx @@ -1,6 +1,6 @@ "use client"; -import { Community, communityStateAtom } from "@/atoms/communitiesAtom"; +import { communityStateAtom } from "@/atoms/communitiesAtom"; import About from "@/components/Community/about/About"; import CreatePostLink from "@/components/Community/CreatePostLink"; import CommunityHeader from "@/components/Community/community-header/CommunityHeader"; @@ -8,6 +8,7 @@ import PageContent from "@/components/Layout/PageContent"; import Posts from "@/components/Posts/Posts"; import { useAtom } from "jotai"; import React, { useEffect } from "react"; +import { Community } from "@/types/community"; type CommunityPageProps = { communityData: Community; diff --git a/app/community/[communityId]/comments/[pid]/PostClientPage.tsx b/app/community/[communityId]/comments/[pid]/PostClientPage.tsx index ece2c34..28d266a 100644 --- a/app/community/[communityId]/comments/[pid]/PostClientPage.tsx +++ b/app/community/[communityId]/comments/[pid]/PostClientPage.tsx @@ -1,8 +1,7 @@ "use client"; /* eslint-disable react-hooks/exhaustive-deps */ -import { Community, communityStateAtom } from "@/atoms/communitiesAtom"; -import { Post } from "@/atoms/postsAtom"; +import { communityStateAtom } from "@/atoms/communitiesAtom"; import About from "@/components/Community/about/About"; import PageContent from "@/components/Layout/PageContent"; import PostLoader from "@/components/Loaders/post-loader/PostLoader"; @@ -19,6 +18,8 @@ import { User } from "firebase/auth"; import { useAtom } from "jotai"; import React, { useEffect } from "react"; import { useAuthState } from "react-firebase-hooks/auth"; +import { Community } from "@/types/community"; +import { Post } from "@/types/post"; type PostPageProps = { communityData: Community; diff --git a/app/community/[communityId]/submit/SubmitPostClientPage.tsx b/app/community/[communityId]/submit/SubmitPostClientPage.tsx index 3ea6231..1ecfb2a 100644 --- a/app/community/[communityId]/submit/SubmitPostClientPage.tsx +++ b/app/community/[communityId]/submit/SubmitPostClientPage.tsx @@ -1,7 +1,7 @@ "use client"; import { authModalStateAtom } from "@/atoms/authModalAtom"; -import { Community, communityStateAtom } from "@/atoms/communitiesAtom"; +import { communityStateAtom } from "@/atoms/communitiesAtom"; import About from "@/components/Community/about/About"; import PageContent from "@/components/Layout/PageContent"; import AuthButtons from "@/components/Navbar/RightContent/AuthButtons"; @@ -11,6 +11,7 @@ import { Box, Stack, Text } from "@chakra-ui/react"; import { useAtom, useSetAtom } from "jotai"; import React, { useEffect } from "react"; import { useAuthState } from "react-firebase-hooks/auth"; +import { Community } from "@/types/community"; type SubmitPostPageProps = { communityData: Community; diff --git a/app/page.tsx b/app/page.tsx index d323fa8..f18c400 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,7 +1,6 @@ "use client"; /* eslint-disable react-hooks/exhaustive-deps */ -import { PostVote } from "@/atoms/postsAtom"; import CreatePostLink from "@/components/Community/CreatePostLink"; import PersonalHome from "@/components/Community/PersonalHome"; import Recommendations from "@/components/Community/recommendations/Recommendations"; diff --git a/atoms/authModalAtom.ts b/atoms/authModalAtom.ts index 46695cf..a7b699a 100644 --- a/atoms/authModalAtom.ts +++ b/atoms/authModalAtom.ts @@ -1,17 +1,5 @@ import { atom } from "jotai"; - -/** - * Interface which describes the state of the authentication modal. - * The modal has 2 properties: - * @property {boolean} open - whether the modal is open or not - * @property {"login" | "signup" | "resetPassword"} view - which specific view of the modal should be displayed - * - * @see https://jotai.org/docs/core/atom - */ -export interface AuthModalState { - open: boolean; - view: "login" | "signup" | "resetPassword"; -} +import { AuthModalState } from "@/types/authModal"; /** * Describes the default state of the authentication modal. diff --git a/atoms/communitiesAtom.ts b/atoms/communitiesAtom.ts index 350cbdd..d4feed7 100644 --- a/atoms/communitiesAtom.ts +++ b/atoms/communitiesAtom.ts @@ -1,40 +1,5 @@ -import { Timestamp } from "firebase/firestore"; import { atom } from "jotai"; - -/** - * Interface representing a community. - * @property {string} id - unique identifier for the community - * @property {string} creatorId - unique identifier for the user who created the community - * @property {number} numberOfMembers - number of members in the community - * @property {"public" | "restricted" | "private"} privacyType - privacy type of the community - * @property {Timestamp} createdAt - timestamp of when the community was created - * @property {string} imageURL - URL of the community's image - */ -export interface Community { - id: string; - creatorId: string; - numberOfMembers: number; - privacyType: "public" | "restricted" | "private"; - createdAt?: Timestamp; - imageURL?: string; - adminIds?: string[]; -} - -/** - * The snippet representing a community a user us subscribed to - * is stored in the `users` collection (as snippets) in the database for higher efficiency. - * This interface represents the snippets of data for a community that a user is subscribed to. - * The whole community data is not required and it can be fetched from `communities` if required. - * This stores just enough data to model the subscription relations. - * @property {string} communityId - unique identifier for the community - * @property {boolean} isAdmin - whether the user is an admin of the community or not - * @property {string} imageURL - URL of the community's image - */ -export interface CommunitySnippet { - communityId: string; - isAdmin?: boolean; - imageURL?: string; -} +import { Community, CommunitySnippet } from "@/types/community"; /** * Stores the community snippets to track the state of the communities atom. diff --git a/atoms/directoryMenuAtom.ts b/atoms/directoryMenuAtom.ts index 3915e29..5e01ee9 100644 --- a/atoms/directoryMenuAtom.ts +++ b/atoms/directoryMenuAtom.ts @@ -1,23 +1,6 @@ import { atom } from "jotai"; -import { IconType } from "react-icons"; import { TiHome } from "react-icons/ti"; - -/** - * Interface which describes the state of the directory menu item. - * Captures community information for the directory menu item. - * @property {string} displayText - text to be displayed on the menu item - * @property {string} link - link to be navigated to when the menu item is clicked - * @property {IconType} icon - icon to be displayed on the menu item - * @property {string} iconColor - color of the icon - * @property {string} imageURL - URL of the image to be displayed on the menu item - */ -export type DirectoryMenuItem = { - displayText: string; - link: string; - icon: IconType; - iconColor: string | { base: string; _dark: string }; - imageURL?: string; -}; +import { DirectoryMenuItem } from "@/types/directoryMenu"; /** * Interface which describes the state of the directory menu. diff --git a/atoms/postsAtom.ts b/atoms/postsAtom.ts index b6a8f90..03189c6 100644 --- a/atoms/postsAtom.ts +++ b/atoms/postsAtom.ts @@ -1,50 +1,5 @@ -import { Timestamp } from "firebase/firestore"; import { atom } from "jotai"; - -/** - * Interface representing a post. - * Posts are created by users and are stored in the `posts` collection in Firebase. - * @property {string} id - ID of the post - * @property {string} communityId - ID of the community the post belongs to - * @property {string} creatorId - ID of the user who created the post - * @property {string} creatorUsername - username of the user who created the post - * @property {string} title - title of the post - * @property {string} body - body of the post - * @property {number} numberOfComments - number of comments on the post - * @property {number} voteStatus - whether the post was liked or disliked by the current user - * @property {string} imageURL - URL of the image attached to the post - * @property {string} communityImageURL - URL of the image attached to the community - * @property {Timestamp} createTime - time when the post was created - */ -export type Post = { - id?: string; // optional because firebase will automatically add the id for the post - communityId: string; - creatorId: string; - creatorUsername: string; - title: string; - body: string; - numberOfComments: number; - voteStatus: number; - imageURL?: string; - communityImageURL?: string; - createTime: Timestamp; -}; - -/** - * Snippet representing user voting on a post. - * This snippet is stored in the `users` collection in Firebase. - * Stores the ID of the post, ID of the community of that post, and whether it was liked or disliked (+-1) - * @property {string} id - ID of the snippet - * @property {string} postId - ID of the post - * @property {string} communityId - ID of the community the post belongs to - * @property {number} voteValue - whether the post was liked or disliked by the current user (1 or -1) - */ -export type PostVote = { - id: string; - postId: string; - communityId: string; - voteValue: number; -}; +import { Post, PostVote } from "@/types/post"; /** * Represents the base state for the atom. diff --git a/atoms/savedPostsAtom.ts b/atoms/savedPostsAtom.ts index 29cb022..03fd5d2 100644 --- a/atoms/savedPostsAtom.ts +++ b/atoms/savedPostsAtom.ts @@ -1,12 +1,5 @@ import { atom } from "jotai"; - -export type SavedPost = { - id: string; - postId: string; - communityId: string; - postTitle: string; - communityImageURL?: string; -}; +import { SavedPost } from "@/types/savedPost"; interface SavedPostState { savedPosts: SavedPost[]; diff --git a/components/Community/about/About.tsx b/components/Community/about/About.tsx index db0a375..d5293af 100644 --- a/components/Community/about/About.tsx +++ b/components/Community/about/About.tsx @@ -1,4 +1,4 @@ -import { Community } from "@/atoms/communitiesAtom"; +import { Community } from "@/types/community"; import useCommunityState from "@/hooks/community/useCommunityState"; import { Box, Button, Flex, Stack } from "@chakra-ui/react"; import { useRouter } from "next/navigation"; diff --git a/components/Community/about/AboutCommunity.tsx b/components/Community/about/AboutCommunity.tsx index f5f98ef..03af9ad 100644 --- a/components/Community/about/AboutCommunity.tsx +++ b/components/Community/about/AboutCommunity.tsx @@ -1,5 +1,5 @@ import React from "react"; -import { Community } from "@/atoms/communitiesAtom"; +import { Community } from "@/types/community"; import { Flex, Text } from "@chakra-ui/react"; import moment from "moment"; diff --git a/components/Community/about/AdminSectionAbout.tsx b/components/Community/about/AdminSectionAbout.tsx index cac84d2..d710691 100644 --- a/components/Community/about/AdminSectionAbout.tsx +++ b/components/Community/about/AdminSectionAbout.tsx @@ -1,5 +1,5 @@ import React, { useState } from "react"; -import { Community } from "@/atoms/communitiesAtom"; +import { Community } from "@/types/community"; import { Button } from "@chakra-ui/react"; import useCommunityPermissions from "@/hooks/community/useCommunityPermissions"; import CommunitySettingsModal from "@/components/Modal/CommunitySettings/CommunitySettings"; diff --git a/components/Community/community-header/CommunityHeader.tsx b/components/Community/community-header/CommunityHeader.tsx index 0546134..0764027 100644 --- a/components/Community/community-header/CommunityHeader.tsx +++ b/components/Community/community-header/CommunityHeader.tsx @@ -1,4 +1,4 @@ -import { Community } from "@/atoms/communitiesAtom"; +import { Community } from "@/types/community"; import { Box, Flex } from "@chakra-ui/react"; import React from "react"; import useCommunityState from "@/hooks/community/useCommunityState"; diff --git a/components/Community/community-header/CommunityMembersButton.tsx b/components/Community/community-header/CommunityMembersButton.tsx index 61707be..a9e35d8 100644 --- a/components/Community/community-header/CommunityMembersButton.tsx +++ b/components/Community/community-header/CommunityMembersButton.tsx @@ -2,7 +2,6 @@ import React, { useState } from "react"; import { IconButton, Icon } from "@chakra-ui/react"; import CommunityMembersModal from "../../Modal/CommunityMembers/CommunityMembersModal"; import { FiUsers } from "react-icons/fi"; -import { Community } from "@/atoms/communitiesAtom"; type CommunityMembersButtonProps = { communityId: string; diff --git a/components/Community/community-header/CommunitySettings.tsx b/components/Community/community-header/CommunitySettings.tsx index 6e7b954..6ecd004 100644 --- a/components/Community/community-header/CommunitySettings.tsx +++ b/components/Community/community-header/CommunitySettings.tsx @@ -6,7 +6,7 @@ import { useAuthState } from "react-firebase-hooks/auth"; import { auth } from "@/firebase/clientApp"; import { FiSettings } from "react-icons/fi"; import CommunitySettingsModal from "../../Modal/CommunitySettings/CommunitySettings"; -import { Community } from "@/atoms/communitiesAtom"; +import { Community } from "@/types/community"; type CommunitySettingsProps = { communityData: Community; diff --git a/components/Community/community-item/CommunityItem.tsx b/components/Community/community-item/CommunityItem.tsx index 05f1b6b..a55998a 100644 --- a/components/Community/community-item/CommunityItem.tsx +++ b/components/Community/community-item/CommunityItem.tsx @@ -1,4 +1,4 @@ -import { Community } from "@/atoms/communitiesAtom"; +import { Community } from "@/types/community"; import { Flex, Stack } from "@chakra-ui/react"; import { useRouter } from "next/navigation"; import React from "react"; diff --git a/components/Community/community-item/CommunityItemButtonMembersSection.tsx b/components/Community/community-item/CommunityItemButtonMembersSection.tsx index a88b030..0405bf7 100644 --- a/components/Community/community-item/CommunityItemButtonMembersSection.tsx +++ b/components/Community/community-item/CommunityItemButtonMembersSection.tsx @@ -1,5 +1,5 @@ import React from "react"; -import { Community } from "@/atoms/communitiesAtom"; +import { Community } from "@/types/community"; import { Stack, Flex, Icon, Button } from "@chakra-ui/react"; import { BsFillPeopleFill } from "react-icons/bs"; diff --git a/components/Community/community-item/CommunityItemNameIconSection.tsx b/components/Community/community-item/CommunityItemNameIconSection.tsx index 29d49c3..8d10e6b 100644 --- a/components/Community/community-item/CommunityItemNameIconSection.tsx +++ b/components/Community/community-item/CommunityItemNameIconSection.tsx @@ -1,5 +1,5 @@ import React from "react"; -import { Community } from "@/atoms/communitiesAtom"; +import { Community } from "@/types/community"; import { Flex, Image, Icon, Text } from "@chakra-ui/react"; import { IoPeopleCircleOutline } from "react-icons/io5"; diff --git a/components/Community/recommendations/RecommendationRow.tsx b/components/Community/recommendations/RecommendationRow.tsx index 3e9be88..bdba9b4 100644 --- a/components/Community/recommendations/RecommendationRow.tsx +++ b/components/Community/recommendations/RecommendationRow.tsx @@ -1,5 +1,5 @@ import React from "react"; -import { Community } from "@/atoms/communitiesAtom"; +import { Community } from "@/types/community"; import { Flex, Icon, Image, Text, Button } from "@chakra-ui/react"; import Link from "next/link"; import { IoPeopleCircleOutline } from "react-icons/io5"; diff --git a/components/Modal/CommunityMembers/CommunityMembersModal.tsx b/components/Modal/CommunityMembers/CommunityMembersModal.tsx index 05fe917..9226d4b 100644 --- a/components/Modal/CommunityMembers/CommunityMembersModal.tsx +++ b/components/Modal/CommunityMembers/CommunityMembersModal.tsx @@ -16,7 +16,7 @@ import { Stack, Text, } from "@chakra-ui/react"; -import { CommunityMember } from "@/lib/community/fetchCommunityMembers"; +import { CommunityMember } from "@/types/communityMember"; import useCommunityMembers from "@/hooks/community/useCommunityMembers"; type CommunityMembersModalProps = { diff --git a/components/Modal/CommunitySettings/AdminManager.tsx b/components/Modal/CommunitySettings/AdminManager.tsx index dfa3d31..0906166 100644 --- a/components/Modal/CommunitySettings/AdminManager.tsx +++ b/components/Modal/CommunitySettings/AdminManager.tsx @@ -1,4 +1,4 @@ -import { Community } from "@/atoms/communitiesAtom"; +import { Community } from "@/types/community"; import { auth } from "@/firebase/clientApp"; import useCustomToast from "@/hooks/useCustomToast"; import useAddAdmin from "@/hooks/admin/useAddAdmin"; diff --git a/components/Modal/CommunitySettings/CommunitySettings.tsx b/components/Modal/CommunitySettings/CommunitySettings.tsx index d76083e..4ea13d1 100644 --- a/components/Modal/CommunitySettings/CommunitySettings.tsx +++ b/components/Modal/CommunitySettings/CommunitySettings.tsx @@ -1,4 +1,4 @@ -import { Community, communityStateAtom } from "@/atoms/communitiesAtom"; +import { communityStateAtom } from "@/atoms/communitiesAtom"; import useCommunityImage from "@/hooks/community/useCommunityImage"; import useCommunityPrivacy from "@/hooks/community/useCommunityPrivacy"; import useDeleteCommunity from "@/hooks/community/useDeleteCommunity"; @@ -26,6 +26,7 @@ import { ModalFooter, PrivacySettings, } from "."; +import { Community } from "@/types/community"; type CommunitySettingsModalProps = { open: boolean; diff --git a/components/Modal/CommunitySettings/ImageSettings.tsx b/components/Modal/CommunitySettings/ImageSettings.tsx index 3b77de5..4222ab9 100644 --- a/components/Modal/CommunitySettings/ImageSettings.tsx +++ b/components/Modal/CommunitySettings/ImageSettings.tsx @@ -1,4 +1,4 @@ -import { Community } from "@/atoms/communitiesAtom"; +import { Community } from "@/types/community"; import { Box, Button, Flex, Image, Input, Stack, Text } from "@chakra-ui/react"; import React from "react"; diff --git a/components/Modal/CommunitySettings/PrivacySettings.tsx b/components/Modal/CommunitySettings/PrivacySettings.tsx index 673d38e..f5497d8 100644 --- a/components/Modal/CommunitySettings/PrivacySettings.tsx +++ b/components/Modal/CommunitySettings/PrivacySettings.tsx @@ -1,4 +1,4 @@ -import { Community } from "@/atoms/communitiesAtom"; +import { Community } from "@/types/community"; import { Box, Flex, Stack, Text } from "@chakra-ui/react"; import React from "react"; import { FiCheck } from "react-icons/fi"; diff --git a/components/Navbar/SearchModal.tsx b/components/Navbar/SearchModal.tsx index 8fc57cd..544f685 100644 --- a/components/Navbar/SearchModal.tsx +++ b/components/Navbar/SearchModal.tsx @@ -18,7 +18,7 @@ import React, { useRef, useState } from "react"; import { AiOutlineSearch } from "react-icons/ai"; import useSearch from "@/hooks/useSearch"; import { useRouter } from "next/navigation"; -import { Post } from "@/atoms/postsAtom"; +import { Post } from "@/types/post"; import moment from "moment"; type SearchModalProps = { diff --git a/components/Posts/Comments/Comments.tsx b/components/Posts/Comments/Comments.tsx index e0fb6ca..3f54e20 100644 --- a/components/Posts/Comments/Comments.tsx +++ b/components/Posts/Comments/Comments.tsx @@ -1,5 +1,5 @@ /* eslint-disable react-hooks/exhaustive-deps */ -import { Post } from "@/atoms/postsAtom"; +import { Post } from "@/types/post"; import { Comment } from "@/types/comment"; import useCommentList from "@/hooks/comments/useCommentList"; import useCreateComment from "@/hooks/comments/useCreateComment"; diff --git a/components/Posts/Posts.tsx b/components/Posts/Posts.tsx index 291f2de..0ad2f42 100644 --- a/components/Posts/Posts.tsx +++ b/components/Posts/Posts.tsx @@ -1,5 +1,5 @@ /* eslint-disable react-hooks/exhaustive-deps */ -import { Community } from "@/atoms/communitiesAtom"; +import { Community } from "@/types/community"; import { auth } from "@/firebase/clientApp"; import useCommunityPermissions from "@/hooks/community/useCommunityPermissions"; import usePostState from "@/hooks/posts/usePostState"; diff --git a/components/Posts/new-post-form/NewPostForm.tsx b/components/Posts/new-post-form/NewPostForm.tsx index d1a95bd..036a65c 100644 --- a/components/Posts/new-post-form/NewPostForm.tsx +++ b/components/Posts/new-post-form/NewPostForm.tsx @@ -1,4 +1,4 @@ -import { Community } from "@/atoms/communitiesAtom"; +import { Community } from "@/types/community"; import useCreatePost from "@/hooks/posts/useCreatePost"; import useSelectFile from "@/hooks/useSelectFile"; import { Flex, Icon } from "@chakra-ui/react"; diff --git a/components/Posts/post-item/PostBody.tsx b/components/Posts/post-item/PostBody.tsx index d4211ad..f9b70e5 100644 --- a/components/Posts/post-item/PostBody.tsx +++ b/components/Posts/post-item/PostBody.tsx @@ -1,6 +1,6 @@ import React from "react"; import { Text, Flex, Skeleton, Image } from "@chakra-ui/react"; -import { Post } from "@/atoms/postsAtom"; +import { Post } from "@/types/post"; type PostBodyProps = { post: Post; diff --git a/components/Posts/post-item/PostDetails.tsx b/components/Posts/post-item/PostDetails.tsx index 82d8a15..92d7d47 100644 --- a/components/Posts/post-item/PostDetails.tsx +++ b/components/Posts/post-item/PostDetails.tsx @@ -2,7 +2,7 @@ import React from "react"; import { Stack, Image, Icon, Link, Text } from "@chakra-ui/react"; import { IoPeopleCircleOutline } from "react-icons/io5"; import moment from "moment"; -import { Post } from "@/atoms/postsAtom"; +import { Post } from "@/types/post"; type PostDetailsProps = { showCommunityImage?: boolean; diff --git a/components/Posts/post-item/PostItem.tsx b/components/Posts/post-item/PostItem.tsx index 974c580..84cd827 100644 --- a/components/Posts/post-item/PostItem.tsx +++ b/components/Posts/post-item/PostItem.tsx @@ -1,4 +1,4 @@ -import { Post } from "@/atoms/postsAtom"; +import { Post } from "@/types/post"; import useCustomToast from "@/hooks/useCustomToast"; import useSavedPosts from "@/hooks/posts/useSavedPosts"; import { Flex, Stack } from "@chakra-ui/react"; diff --git a/components/Posts/post-item/PostTitle.tsx b/components/Posts/post-item/PostTitle.tsx index a7d6f19..0baad5c 100644 --- a/components/Posts/post-item/PostTitle.tsx +++ b/components/Posts/post-item/PostTitle.tsx @@ -1,6 +1,6 @@ import React from "react"; import { Text } from "@chakra-ui/react"; -import { Post } from "@/atoms/postsAtom"; +import { Post } from "@/types/post"; type PostTitleProps = { post: Post; diff --git a/components/Posts/post-item/VoteSection.tsx b/components/Posts/post-item/VoteSection.tsx index ec8e95d..746bdc6 100644 --- a/components/Posts/post-item/VoteSection.tsx +++ b/components/Posts/post-item/VoteSection.tsx @@ -6,7 +6,7 @@ import { IoArrowUpCircleOutline, IoArrowUpCircleSharp, } from "react-icons/io5"; -import { Post } from "@/atoms/postsAtom"; +import { Post } from "@/types/post"; type VoteSectionProps = { userVoteValue?: number; diff --git a/hooks/admin/useAddAdmin.ts b/hooks/admin/useAddAdmin.ts index 5149d6e..23e8d32 100644 --- a/hooks/admin/useAddAdmin.ts +++ b/hooks/admin/useAddAdmin.ts @@ -1,8 +1,9 @@ -import { Community, communityStateAtom } from "@/atoms/communitiesAtom"; +import { communityStateAtom } from "@/atoms/communitiesAtom"; import { AdminUser } from "@/types/adminUser"; import { addCommunityAdmin } from "@/lib/community/addCommunityAdmin"; import { useSetAtom } from "jotai"; import { Dispatch, SetStateAction, useCallback } from "react"; +import { Community } from "@/types/community"; const useAddAdmin = () => { const setCommunityStateValue = useSetAtom(communityStateAtom); diff --git a/hooks/admin/useRemoveAdmin.ts b/hooks/admin/useRemoveAdmin.ts index 4dd4897..009ceca 100644 --- a/hooks/admin/useRemoveAdmin.ts +++ b/hooks/admin/useRemoveAdmin.ts @@ -1,8 +1,9 @@ -import { Community, communityStateAtom } from "@/atoms/communitiesAtom"; +import { communityStateAtom } from "@/atoms/communitiesAtom"; import { AdminUser } from "@/types/adminUser"; import { removeCommunityAdmin } from "@/lib/community/removeCommunityAdmin"; import { useSetAtom } from "jotai"; import { Dispatch, SetStateAction, useCallback } from "react"; +import { Community } from "@/types/community"; const useRemoveAdmin = () => { const setCommunityStateValue = useSetAtom(communityStateAtom); diff --git a/hooks/comments/useCommentList.ts b/hooks/comments/useCommentList.ts index 0b730a9..5bcb752 100644 --- a/hooks/comments/useCommentList.ts +++ b/hooks/comments/useCommentList.ts @@ -1,7 +1,7 @@ import { useCallback, useEffect, useState } from "react"; import { collection, getDocs, orderBy, query, where } from "firebase/firestore"; import { firestore } from "@/firebase/clientApp"; -import { Post } from "@/atoms/postsAtom"; +import { Post } from "@/types/post"; import useCustomToast from "@/hooks/useCustomToast"; import { Comment } from "../../types/comment"; diff --git a/hooks/comments/useCreateComment.ts b/hooks/comments/useCreateComment.ts index a5696da..3102fe6 100644 --- a/hooks/comments/useCreateComment.ts +++ b/hooks/comments/useCreateComment.ts @@ -9,7 +9,8 @@ import { writeBatch, } from "firebase/firestore"; import { firestore } from "@/firebase/clientApp"; -import { Post, postStateAtom } from "@/atoms/postsAtom"; +import { postStateAtom } from "@/atoms/postsAtom"; +import { Post } from "@/types/post"; import { useSetAtom } from "jotai"; import useCustomToast from "@/hooks/useCustomToast"; import { Comment } from "../../types/comment"; diff --git a/hooks/community/useCommunitiesFeed.ts b/hooks/community/useCommunitiesFeed.ts index 2cffaa2..8f4bc9d 100644 --- a/hooks/community/useCommunitiesFeed.ts +++ b/hooks/community/useCommunitiesFeed.ts @@ -11,7 +11,7 @@ import { startAfter, } from "firebase/firestore"; import { useEffect, useState } from "react"; -import { Community } from "@/atoms/communitiesAtom"; +import { Community } from "@/types/community"; type UseCommunitiesFeedProps = { limitValue?: number; diff --git a/hooks/community/useCommunityImage.ts b/hooks/community/useCommunityImage.ts index 56ae1dd..ff242ed 100644 --- a/hooks/community/useCommunityImage.ts +++ b/hooks/community/useCommunityImage.ts @@ -1,10 +1,11 @@ -import { Community, communityStateAtom } from "@/atoms/communitiesAtom"; +import { communityStateAtom } from "@/atoms/communitiesAtom"; import { firestore, storage } from "@/firebase/clientApp"; import { collection, doc, getDoc, getDocs, updateDoc } from "firebase/firestore"; import { deleteObject, getDownloadURL, ref, uploadString } from "firebase/storage"; import { useSetAtom } from "jotai"; import { useState } from "react"; import useCustomToast from "../useCustomToast"; +import { Community } from "@/types/community"; const useCommunityImage = (communityData: Community) => { const setCommunityStateValue = useSetAtom(communityStateAtom); diff --git a/hooks/community/useCommunityMembers.ts b/hooks/community/useCommunityMembers.ts index 933f09e..e7b8a5d 100644 --- a/hooks/community/useCommunityMembers.ts +++ b/hooks/community/useCommunityMembers.ts @@ -1,10 +1,8 @@ "use client"; import { useCallback, useState } from "react"; -import { - CommunityMember, - fetchCommunityMembers, -} from "@/lib/community/fetchCommunityMembers"; +import { fetchCommunityMembers } from "@/lib/community/fetchCommunityMembers"; +import { CommunityMember } from "@/types/communityMember"; const useCommunityMembers = () => { const [members, setMembers] = useState([]); diff --git a/hooks/community/useCommunityMembershipActions.tsx b/hooks/community/useCommunityMembershipActions.tsx index 8057c47..8ede1ac 100644 --- a/hooks/community/useCommunityMembershipActions.tsx +++ b/hooks/community/useCommunityMembershipActions.tsx @@ -1,10 +1,10 @@ import { authModalStateAtom } from "@/atoms/authModalAtom"; -import { Community } from "@/atoms/communitiesAtom"; import { useSetAtom } from "jotai"; import { useAuthState } from "react-firebase-hooks/auth"; import { auth } from "@/firebase/clientApp"; import useJoinCommunity from "./useJoinCommunity"; import useLeaveCommunity from "./useLeaveCommunity"; +import { Community } from "@/types/community"; const useCommunityMembershipActions = () => { const [user] = useAuthState(auth); diff --git a/hooks/community/useCommunityPermissions.tsx b/hooks/community/useCommunityPermissions.tsx index c63bd45..ff6d47f 100644 --- a/hooks/community/useCommunityPermissions.tsx +++ b/hooks/community/useCommunityPermissions.tsx @@ -1,4 +1,4 @@ -import { Community } from "@/atoms/communitiesAtom"; +import { Community } from "@/types/community"; import { auth } from "@/firebase/clientApp"; import { useAuthState } from "react-firebase-hooks/auth"; diff --git a/hooks/community/useCommunityPrivacy.ts b/hooks/community/useCommunityPrivacy.ts index a4aab95..d1b8f3a 100644 --- a/hooks/community/useCommunityPrivacy.ts +++ b/hooks/community/useCommunityPrivacy.ts @@ -1,4 +1,5 @@ -import { Community, communityStateAtom } from "@/atoms/communitiesAtom"; +import { communityStateAtom } from "@/atoms/communitiesAtom"; +import { Community } from "@/types/community"; import { firestore } from "@/firebase/clientApp"; import { doc, updateDoc } from "firebase/firestore"; import { useSetAtom } from "jotai"; diff --git a/hooks/community/useCommunitySnippets.ts b/hooks/community/useCommunitySnippets.ts index 0aba4ad..8ba0708 100644 --- a/hooks/community/useCommunitySnippets.ts +++ b/hooks/community/useCommunitySnippets.ts @@ -1,4 +1,5 @@ -import { CommunitySnippet, communityStateAtom } from "@/atoms/communitiesAtom"; +import { communityStateAtom } from "@/atoms/communitiesAtom"; +import { CommunitySnippet } from "@/types/community"; import { auth, firestore } from "@/firebase/clientApp"; import { collection, getDocs } from "firebase/firestore"; import { useSetAtom } from "jotai"; diff --git a/hooks/community/useDeleteCommunity.ts b/hooks/community/useDeleteCommunity.ts index 3551917..ce0cfdd 100644 --- a/hooks/community/useDeleteCommunity.ts +++ b/hooks/community/useDeleteCommunity.ts @@ -1,4 +1,4 @@ -import { Community } from "@/atoms/communitiesAtom"; +import { Community } from "@/types/community"; import { firestore, storage } from "@/firebase/clientApp"; import { collection, diff --git a/hooks/community/useJoinCommunity.tsx b/hooks/community/useJoinCommunity.tsx index b8031a7..5915488 100644 --- a/hooks/community/useJoinCommunity.tsx +++ b/hooks/community/useJoinCommunity.tsx @@ -1,9 +1,6 @@ import { useState } from "react"; -import { - Community, - CommunitySnippet, - communityStateAtom, -} from "@/atoms/communitiesAtom"; +import { communityStateAtom } from "@/atoms/communitiesAtom"; +import { Community, CommunitySnippet } from "@/types/community"; import { auth, firestore } from "@/firebase/clientApp"; import { doc, increment, writeBatch } from "firebase/firestore"; import { useSetAtom } from "jotai"; diff --git a/hooks/posts/useCreatePost.ts b/hooks/posts/useCreatePost.ts index f2de943..8a6d7d9 100644 --- a/hooks/posts/useCreatePost.ts +++ b/hooks/posts/useCreatePost.ts @@ -11,7 +11,7 @@ import { } from "firebase/firestore"; import { getDownloadURL, ref, uploadString } from "firebase/storage"; import { firestore, storage } from "@/firebase/clientApp"; -import { Post } from "@/atoms/postsAtom"; +import { Post } from "@/types/post"; import useCustomToast from "../useCustomToast"; const useCreatePost = () => { diff --git a/hooks/posts/usePostDeletion.ts b/hooks/posts/usePostDeletion.ts index 7048ebb..759126a 100644 --- a/hooks/posts/usePostDeletion.ts +++ b/hooks/posts/usePostDeletion.ts @@ -1,6 +1,7 @@ -import { Post, postStateAtom } from "@/atoms/postsAtom"; +import { postStateAtom } from "@/atoms/postsAtom"; import { savedPostStateAtom } from "@/atoms/savedPostsAtom"; import { firestore, storage } from "@/firebase/clientApp"; +import { Post, PostVote } from "@/types/post"; import { collection, deleteDoc, @@ -19,7 +20,7 @@ const usePostDeletion = ( React.SetStateAction<{ selectedPost: Post | null; posts: Post[]; - postVotes: import("@/atoms/postsAtom").PostVote[]; + postVotes: PostVote[]; }> > ) => { diff --git a/hooks/posts/usePostSelection.ts b/hooks/posts/usePostSelection.ts index 3444758..54a374d 100644 --- a/hooks/posts/usePostSelection.ts +++ b/hooks/posts/usePostSelection.ts @@ -1,4 +1,4 @@ -import { Post } from "@/atoms/postsAtom"; +import { Post, PostVote } from "@/types/post"; import { useRouter } from "next/navigation"; const usePostSelection = ( @@ -6,7 +6,7 @@ const usePostSelection = ( React.SetStateAction<{ selectedPost: Post | null; posts: Post[]; - postVotes: import("@/atoms/postsAtom").PostVote[]; + postVotes: PostVote[]; }> > ) => { diff --git a/hooks/posts/usePostVote.tsx b/hooks/posts/usePostVote.tsx index 7ed746a..1dfbc50 100644 --- a/hooks/posts/usePostVote.tsx +++ b/hooks/posts/usePostVote.tsx @@ -1,6 +1,5 @@ /* eslint-disable react-hooks/exhaustive-deps */ import { authModalStateAtom } from "@/atoms/authModalAtom"; -import { Post, PostVote } from "@/atoms/postsAtom"; import { auth, firestore } from "@/firebase/clientApp"; import { collection, @@ -16,6 +15,7 @@ import { useSetAtom } from "jotai"; import { useAuthState } from "react-firebase-hooks/auth"; import useCustomToast from "../useCustomToast"; import React from "react"; +import { Post, PostVote } from "@/types/post"; type SetPostState = React.Dispatch< React.SetStateAction<{ diff --git a/hooks/posts/usePostVoteSync.ts b/hooks/posts/usePostVoteSync.ts index 23034b4..78b3522 100644 --- a/hooks/posts/usePostVoteSync.ts +++ b/hooks/posts/usePostVoteSync.ts @@ -1,11 +1,11 @@ import { communityStateAtom } from "@/atoms/communitiesAtom"; -import { Post, PostVote } from "@/atoms/postsAtom"; import { firestore } from "@/firebase/clientApp"; import { collection, getDocs, query, where } from "firebase/firestore"; import { useAtomValue } from "jotai"; import React, { useEffect } from "react"; import { useAuthState } from "react-firebase-hooks/auth"; import { auth } from "@/firebase/clientApp"; +import { Post, PostVote } from "@/types/post"; type SetPostState = React.Dispatch< React.SetStateAction<{ diff --git a/hooks/posts/usePostsFeed.ts b/hooks/posts/usePostsFeed.ts index 4804abc..1a5c915 100644 --- a/hooks/posts/usePostsFeed.ts +++ b/hooks/posts/usePostsFeed.ts @@ -1,4 +1,4 @@ -import { Post, postStateAtom } from "@/atoms/postsAtom"; +import { postStateAtom } from "@/atoms/postsAtom"; import { firestore } from "@/firebase/clientApp"; import { collection, @@ -16,6 +16,7 @@ import { useSetAtom } from "jotai"; import { useEffect, useMemo, useState } from "react"; import useCustomToast from "../useCustomToast"; import { useIntersectionObserver } from "../useIntersectionObserver"; +import { Post } from "@/types/post"; type UsePostsFeedProps = { communityId?: string; diff --git a/hooks/posts/useSavedPosts.tsx b/hooks/posts/useSavedPosts.tsx index dcc7225..7a6d0d1 100644 --- a/hooks/posts/useSavedPosts.tsx +++ b/hooks/posts/useSavedPosts.tsx @@ -1,7 +1,8 @@ import { authModalStateAtom } from "@/atoms/authModalAtom"; -import { Post } from "@/atoms/postsAtom"; -import { SavedPost, savedPostStateAtom } from "@/atoms/savedPostsAtom"; +import { savedPostStateAtom } from "@/atoms/savedPostsAtom"; import { auth, firestore } from "@/firebase/clientApp"; +import { Post } from "@/types/post"; +import { SavedPost } from "@/types/savedPost"; import { collection, deleteDoc, diff --git a/hooks/useDirectory.tsx b/hooks/useDirectory.tsx index c079700..5238bff 100644 --- a/hooks/useDirectory.tsx +++ b/hooks/useDirectory.tsx @@ -1,10 +1,7 @@ /* eslint-disable react-hooks/exhaustive-deps */ import { communityStateAtom } from "@/atoms/communitiesAtom"; -import { - defaultMenuItem, - DirectoryMenuItem, - directoryMenuAtom, -} from "@/atoms/directoryMenuAtom"; +import { defaultMenuItem, directoryMenuAtom } from "@/atoms/directoryMenuAtom"; +import { DirectoryMenuItem } from "@/types/directoryMenu"; import { useAtom, useAtomValue } from "jotai"; import { useRouter, usePathname } from "next/navigation"; import { useEffect } from "react"; diff --git a/hooks/useSearch.tsx b/hooks/useSearch.tsx index 308b74c..422f1b3 100644 --- a/hooks/useSearch.tsx +++ b/hooks/useSearch.tsx @@ -8,8 +8,8 @@ import { orderBy, } from "firebase/firestore"; import { firestore } from "@/firebase/clientApp"; -import { Community } from "@/atoms/communitiesAtom"; -import { Post } from "@/atoms/postsAtom"; +import { Community } from "@/types/community"; +import { Post } from "@/types/post"; const useSearch = (searchTerm: string) => { const [results, setResults] = useState<{ diff --git a/lib/community/fetchCommunityMembers.ts b/lib/community/fetchCommunityMembers.ts index 8f28c6b..e28bc45 100644 --- a/lib/community/fetchCommunityMembers.ts +++ b/lib/community/fetchCommunityMembers.ts @@ -1,11 +1,6 @@ import { firestore } from "@/firebase/clientApp"; import { collection, doc, getDoc, getDocs } from "firebase/firestore"; - -export type CommunityMember = { - uid: string; - email: string; - displayName: string | null; -}; +import { CommunityMember } from "@/types/communityMember"; /** * Fetches all users that belong to a community by checking the diff --git a/lib/post/getPost.ts b/lib/post/getPost.ts index 09bd228..7a3424e 100644 --- a/lib/post/getPost.ts +++ b/lib/post/getPost.ts @@ -1,7 +1,7 @@ import { firestore } from "@/firebase/clientApp"; import { doc, getDoc } from "firebase/firestore"; import safeJsonStringify from "safe-json-stringify"; -import { Post } from "@/atoms/postsAtom"; +import { Post } from "@/types/post"; export async function getPost(postId: string) { try { diff --git a/types/authModal.ts b/types/authModal.ts new file mode 100644 index 0000000..47b8c31 --- /dev/null +++ b/types/authModal.ts @@ -0,0 +1,4 @@ +export interface AuthModalState { + open: boolean; + view: "login" | "signup" | "resetPassword"; +} diff --git a/types/community.ts b/types/community.ts new file mode 100644 index 0000000..58e6efb --- /dev/null +++ b/types/community.ts @@ -0,0 +1,17 @@ +import { Timestamp } from "firebase/firestore"; + +export interface Community { + id: string; + creatorId: string; + numberOfMembers: number; + privacyType: "public" | "restricted" | "private"; + createdAt?: Timestamp; + imageURL?: string; + adminIds?: string[]; +} + +export interface CommunitySnippet { + communityId: string; + isAdmin?: boolean; + imageURL?: string; +} diff --git a/types/communityMember.ts b/types/communityMember.ts new file mode 100644 index 0000000..fe01a63 --- /dev/null +++ b/types/communityMember.ts @@ -0,0 +1,5 @@ +export type CommunityMember = { + uid: string; + email: string; + displayName: string | null; +}; diff --git a/types/directoryMenu.ts b/types/directoryMenu.ts new file mode 100644 index 0000000..573866d --- /dev/null +++ b/types/directoryMenu.ts @@ -0,0 +1,9 @@ +import { IconType } from "react-icons"; + +export type DirectoryMenuItem = { + displayText: string; + link: string; + icon: IconType; + iconColor: string | { base: string; _dark: string }; + imageURL?: string; +}; diff --git a/types/post.ts b/types/post.ts new file mode 100644 index 0000000..0c0b079 --- /dev/null +++ b/types/post.ts @@ -0,0 +1,22 @@ +import { Timestamp } from "firebase/firestore"; + +export type Post = { + id?: string; + communityId: string; + creatorId: string; + creatorUsername: string; + title: string; + body: string; + numberOfComments: number; + voteStatus: number; + imageURL?: string; + communityImageURL?: string; + createTime: Timestamp; +}; + +export type PostVote = { + id: string; + postId: string; + communityId: string; + voteValue: number; +}; diff --git a/types/savedPost.ts b/types/savedPost.ts new file mode 100644 index 0000000..5a40d9a --- /dev/null +++ b/types/savedPost.ts @@ -0,0 +1,7 @@ +export type SavedPost = { + id: string; + postId: string; + communityId: string; + postTitle: string; + communityImageURL?: string; +};