Skip to content

Commit

Permalink
refactor(components/hooks): restructure components and hooks directories
Browse files Browse the repository at this point in the history
- Moved Profile-related components to 'src/components/Profile'
- Moved auth-related hooks to 'src/hooks/auth'
- Organized data-related hooks into 'src/hooks/data'
- Updated paths in various files to match the new structure
  • Loading branch information
ZL-Asica committed Oct 12, 2024
1 parent d669b32 commit 114f849
Show file tree
Hide file tree
Showing 25 changed files with 47 additions and 63 deletions.
15 changes: 7 additions & 8 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import React, { useState } from 'react';

import Footer from '@components/common/Footer';
import Header from '@components/common/Header';
import GroupsPage from '@components/GroupsPage';
import HomePage from '@components/HomePage';
import EditProfile from '@components/Profile/EditProfile';
import ProfilePage from '@components/Profile/ProfilePage';
import { ThemeProvider } from '@mui/material/styles';
import { theme } from '@utils/theme';
import { BrowserRouter, Routes, Route, useLocation } from 'react-router-dom';

import Footer from './components/common/Footer';
import Header from './components/common/Header';
import EditProfile from './components/EditProfile';
import GroupsPage from './components/GroupsPage';
import HomePage from './components/HomePage';
import ProfilePage from './components/ProfilePage';
import { theme } from './utils/theme';
import './App.css';

const AppContent = ({ currentPage, setCurrentPage }) => {
Expand Down
13 changes: 6 additions & 7 deletions src/components/GroupsPage.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { useState, useEffect } from 'react';

import { useAuthState } from '@auth/useAuthState';
import ProfileCard from '@components/Profile/ProfileCard';
import StudentCard from '@components/Profile/UserCard';
import useUserProfile from '@data/useUserProfile';
import { resolveMatchRequest, getUserMatches } from '@firestore/matches';
import { fetchUserProfile } from '@firestore/userProfile';
import { Box, Stack, Typography } from '@mui/material';

import ProfileCard from './ProfileCard';
import StudentCard from './UserCard';
import { useAuthState } from '../hooks/useAuthState';
import useUserProfile from '../hooks/useUserProfile';
import { resolveMatchRequest, getUserMatches } from '../utils/firestore/matches';
import { fetchUserProfile } from '../utils/firestore/userProfile';

function GroupsPage() {
const [user] = useAuthState();
const { userProfile, loading } = useUserProfile(user);
Expand Down
3 changes: 1 addition & 2 deletions src/components/Home/StudentFilter.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';

import useMajors from '@data/useMajors';
import {
Box,
Autocomplete,
Expand All @@ -12,8 +13,6 @@ import {
OutlinedInput,
} from '@mui/material';

import useMajors from '../../hooks/useMajors';

export default function StudentFilter({
selectedMajors,
setSelectedMajors,
Expand Down
11 changes: 5 additions & 6 deletions src/components/Home/StudentList.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React from 'react';

import CustomPagination from '@components/common/CustomPagination';
import StudentCard from '@components/Profile/UserCard';
import useStudentData from '@data/useStudentData';
import usePagination from '@hooks/utils/usePagination';
import { Box, Stack, Typography } from '@mui/material';

import usePagination from '../../hooks/usePagination';
import useStudentData from '../../hooks/useStudentData';
import { createMatch } from '../../utils/firestore/matches';
import CustomPagination from '../common/CustomPagination';
import StudentCard from '../UserCard';
import { createMatch } from '@utils/firestore/matches';

export default function StudentList({
userProfile,
Expand Down
9 changes: 4 additions & 5 deletions src/components/HomePage.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React, { useState, useEffect } from 'react';

import { useAuthState } from '@auth/useAuthState';
import StudentFilter from '@components/Home/StudentFilter';
import StudentList from '@components/Home/StudentList';
import useUserProfile from '@data/useUserProfile';
import { Box, CircularProgress, Typography } from '@mui/material';
import { useNavigate } from 'react-router-dom';

import StudentFilter from './Home/StudentFilter';
import StudentList from './Home/StudentList';
import { useAuthState } from '../hooks/useAuthState';
import useUserProfile from '../hooks/useUserProfile';

export default function HomePage() {
const [user] = useAuthState();
const { userProfile, requestedUsers, setRequestedUsers, matchedUserUids, loading } =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from 'react';

import { useAuthState } from '@auth/useAuthState';
import useEditProfileForm from '@hooks/useEditProfileForm';
import ArrowBackIcon from '@mui/icons-material/ArrowBack';
import {
TextField,
Expand All @@ -11,9 +13,6 @@ import {
} from '@mui/material';
import { useNavigate } from 'react-router-dom';

import { useAuthState } from '../hooks/useAuthState';
import useEditProfileForm from '../hooks/useEditProfileForm';

const EditProfile = () => {
const [user] = useAuthState();
const {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React from 'react';

import { useCopyToClipboard } from '@hooks/utils/useCopyToClipboard';
import { Avatar, Box, Card, CardContent, CardHeader, Modal, Typography } from '@mui/material';
import { useTheme, lighten } from '@mui/system';

import { useCopyToClipboard } from '../hooks/useCopyToClipboard';

export default function ProfileCard({ profileData, open, onClose }) {
const theme = useTheme();
const { handleCopyToClipboard, SnackbarComponent } = useCopyToClipboard();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState } from 'react';

import useUserProfile from '@data/useUserProfile';
import { Email, Phone, School, CalendarToday, ListAlt } from '@mui/icons-material';
import {
Avatar,
Expand All @@ -16,7 +17,6 @@ import {
import { useParams, useNavigate } from 'react-router-dom';

import SignOutDialog from './SignOutDialog';
import useUserProfile from '../hooks/useUserProfile';

export default function ProfilePage() {
const { id } = useParams();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import {
DialogTitle,
Button,
} from '@mui/material';
import { handleSignOut } from '@utils/auth';
import { useNavigate } from 'react-router-dom';

import { handleSignOut } from '../utils/auth';

export default function SignOutDialog({ open, onClose }) {
const navigate = useNavigate();

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/components/common/Footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import GroupsIcon from '@mui/icons-material/Groups';
import HomeIcon from '@mui/icons-material/Home';
import { Box, BottomNavigation, BottomNavigationAction } from '@mui/material';
import { useTheme } from '@mui/material/styles';
import { navigateToPage } from '@utils/navigateToPage';
import { useNavigate } from 'react-router-dom';

// import MessageIcon from '@mui/icons-material/Message';
import { navigateToPage } from '../../utils/navigateToPage';

export default function Footer({ currentPage, setCurrentPage }) {
const navigate = useNavigate();
Expand Down
3 changes: 1 addition & 2 deletions src/components/common/Header.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React from 'react';

import { useAuthNavigation } from '@auth/useAuthNavigation';
import { ArrowBack } from '@mui/icons-material';
import { AppBar, Toolbar, Typography, IconButton, Avatar, Button, Box } from '@mui/material';
import { useTheme } from '@mui/material/styles';
import { useNavigate, useLocation } from 'react-router-dom';

import { useAuthNavigation } from '../../hooks/useAuthNavigation';

export default function Header() {
const { user, handleProfileClick, signInAndCheckFirstTimeUser } = useAuthNavigation();
const theme = useTheme();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { useAuthState } from '@auth/useAuthState';
import { handleSignIn } from '@utils/auth';
import { useNavigate } from 'react-router-dom';

import { useAuthState } from './useAuthState';
import { handleSignIn } from '../utils/auth';

export const useAuthNavigation = () => {
const [user] = useAuthState();
const navigate = useNavigate();
Expand Down
3 changes: 1 addition & 2 deletions src/hooks/useAuthState.js → src/hooks/auth/useAuthState.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { useEffect, useState } from 'react';

import { auth } from '@utils/firebaseConfig';
import { onAuthStateChanged } from 'firebase/auth';

import { auth } from '../utils/firebaseConfig';

// Hook to get the current user
export const useAuthState = () => {
const [user, setUser] = useState(null);
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useMajors.js → src/hooks/data/useMajors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from 'react';

import { getMajors } from '../utils/firestore/general';
import { getMajors } from '@firestore/general';

export default function useMajors() {
const [majorsList, setMajorsList] = useState([]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from 'react';

import { getAllUsers } from '../utils/firestore/general';
import { getAllUsers } from '@firestore/general';

export default function useStudentData() {
const [studentData, setStudentData] = useState(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from 'react';

import { getMatchedUserUids } from '../utils/firestore/matches';
import { fetchUserProfile } from '../utils/firestore/userProfile';
import { getMatchedUserUids } from '@firestore/matches';
import { fetchUserProfile } from '@firestore/userProfile';

export default function useUserProfile(user) {
const [userProfile, setUserProfile] = useState(null);
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useEditProfileForm.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from 'react';

import { getMajors } from '../utils/firestore/general';
import { getUserProfile, updateUserProfile } from '../utils/firestore/userProfile';
import { getMajors } from '@firestore/general';
import { getUserProfile, updateUserProfile } from '@firestore/userProfile';

const useEditProfileForm = (user) => {
const [loading, setLoading] = useState(true);
Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 3 additions & 4 deletions src/utils/auth.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { fetchAndStoreClassData } from '@firestore/classData';
import { checkUserProfile } from '@firestore/userProfile';
import { auth } from '@utils/firebaseConfig';
import { GoogleAuthProvider, signInWithPopup, signOut } from 'firebase/auth';

import { auth } from './firebaseConfig';
import { fetchAndStoreClassData } from './firestore/classData';
import { checkUserProfile } from './firestore/userProfile';

const provider = new GoogleAuthProvider();

// Google Sign-In
Expand Down
3 changes: 1 addition & 2 deletions src/utils/firestore/classData.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Functions for fetching and storing class data in Firestore
import { db } from '@utils/firebaseConfig';
import { collection, doc, getDoc, setDoc, updateDoc } from 'firebase/firestore';

import { db } from '../firebaseConfig';

// Get latest term from APi and update if necessary
const checkAndInsertLatestTerm = async () => {
try {
Expand Down
3 changes: 1 addition & 2 deletions src/utils/firestore/general.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// General Firestore functions (shared utilities)
import { db } from '@utils/firebaseConfig';
import { collection, getDocs, doc, getDoc } from 'firebase/firestore';

import { db } from '../firebaseConfig';

// Get all users from Firestore
export const getAllUsers = async () => {
try {
Expand Down
5 changes: 2 additions & 3 deletions src/utils/firestore/matches.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { fetchUserProfile } from '@firestore/userProfile';
import { db } from '@utils/firebaseConfig';
import {
doc,
getDoc,
Expand All @@ -7,9 +9,6 @@ import {
arrayRemove,
} from 'firebase/firestore';

import { fetchUserProfile } from './userProfile';
import { db } from '../firebaseConfig';

// Utility function to fetch a match document by ID
const fetchMatchDocument = async (matchId) => {
try {
Expand Down
3 changes: 1 addition & 2 deletions src/utils/firestore/userProfile.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// User profile operations (get, update, check)
import { db } from '@utils/firebaseConfig';
import { doc, setDoc, getDoc, updateDoc } from 'firebase/firestore';

import { db } from '../firebaseConfig';

// Unified function to fetch user profile by UID
// (supports both regular and transaction-based fetches)
export const fetchUserProfile = async (uid, transaction) => {
Expand Down

0 comments on commit 114f849

Please sign in to comment.