diff --git a/src/hooks/shared-states.tsx b/src/hooks/shared-states.tsx index cbd1117..d3b85a7 100644 --- a/src/hooks/shared-states.tsx +++ b/src/hooks/shared-states.tsx @@ -1,42 +1,16 @@ "use client"; // src/hooks/useSharedState.tsx -import React, {createContext, MutableRefObject, useContext, useRef, useState} from 'react' -import {useTheme} from 'next-themes' +import React, {createContext, useContext, useRef, useState} from 'react' // Define the shape of our shared state interface SharedState { // UI States - isScrolled: boolean - setIsScrolled: React.Dispatch> - isSearchExpanded: boolean - setIsSearchExpanded: React.Dispatch> isDrawerOpen: boolean setIsDrawerOpen: React.Dispatch> - isCreateModalOpen: boolean - setIsCreateModalOpen: React.Dispatch> - isUserModalOpen: boolean - setIsUserModalOpen: React.Dispatch> - isNotificationsOpen: boolean - setIsNotificationsOpen: React.Dispatch> - showBackToTop: boolean - setShowBackToTop: React.Dispatch> // Refs - drawerRef: React.RefObject - userModalRef: React.RefObject - notificationsRef: React.RefObject - createModalRef: React.RefObject - fileInputRef: React.RefObject - observerRef: MutableRefObject - loadingRef: MutableRefObject - - // Theme - theme: string | undefined -} - -export function useMutableRef(initialValue: T): MutableRefObject { - return useRef(initialValue) as MutableRefObject + drawerRef: React.RefObject } // Create the context @@ -45,54 +19,19 @@ const SharedStateContext = createContext(undefined) // Create the provider component export function SharedStateProvider({children}: { children: React.ReactNode }) { // UI States - const [isScrolled, setIsScrolled] = useState(false) - const [isSearchExpanded, setIsSearchExpanded] = useState(false) const [isDrawerOpen, setIsDrawerOpen] = useState(false) - const [isCreateModalOpen, setIsCreateModalOpen] = useState(false) - const [isUserModalOpen, setIsUserModalOpen] = useState(false) - const [isNotificationsOpen, setIsNotificationsOpen] = useState(false) - const [showBackToTop, setShowBackToTop] = useState(false) // Refs const drawerRef = useRef(null) - const userModalRef = useRef(null) - const notificationsRef = useRef(null) - const createModalRef = useRef(null) - const fileInputRef = useRef(null) - const loadingRef = useMutableRef(false) - const observerRef = useMutableRef(null) // Theme - const {theme} = useTheme() const value = { // UI States - isScrolled, - setIsScrolled, - isSearchExpanded, - setIsSearchExpanded, isDrawerOpen, setIsDrawerOpen, - isCreateModalOpen, - setIsCreateModalOpen, - isUserModalOpen, - setIsUserModalOpen, - isNotificationsOpen, - setIsNotificationsOpen, - showBackToTop, - setShowBackToTop, - // Refs drawerRef, - userModalRef, - notificationsRef, - createModalRef, - fileInputRef, - observerRef, - loadingRef, - - // Theme - theme, } return ( @@ -114,58 +53,24 @@ export function useSharedState() { // Optional: Create specific hooks for different parts of the state export function useUIState() { const { - isScrolled, - setIsScrolled, - isSearchExpanded, - setIsSearchExpanded, + isDrawerOpen, setIsDrawerOpen, - isCreateModalOpen, - setIsCreateModalOpen, - isUserModalOpen, - setIsUserModalOpen, - isNotificationsOpen, - setIsNotificationsOpen, - showBackToTop, - setShowBackToTop, + } = useSharedState() return { - isScrolled, - setIsScrolled, - isSearchExpanded, - setIsSearchExpanded, isDrawerOpen, setIsDrawerOpen, - isCreateModalOpen, - setIsCreateModalOpen, - isUserModalOpen, - setIsUserModalOpen, - isNotificationsOpen, - setIsNotificationsOpen, - showBackToTop, - setShowBackToTop, } } export function useRefs() { const { drawerRef, - userModalRef, - notificationsRef, - createModalRef, - fileInputRef, - observerRef, - loadingRef, } = useSharedState() return { drawerRef, - userModalRef, - notificationsRef, - createModalRef, - fileInputRef, - observerRef, - loadingRef, } } \ No newline at end of file