import LoadingBar from "@/components/ui/loading-bar"; import React, { createContext, useContext, useState, ReactNode } from "react"; interface LoadingContextType { showLoading: () => void; hideLoading: () => void; } interface LoadingProviderProps { children: ReactNode; color?: string; // Color for the loading bar } const LoadingContext = createContext(undefined); export const LoadingProvider: React.FC = ({ children, color = "#007AFF", // Default blue color }) => { const [loading, setLoading] = useState(false); const showLoading = () => setLoading(true); const hideLoading = () => setLoading(false); return ( {children} {loading && } ); }; export const useTopLoadingBar = (): LoadingContextType => { const context = useContext(LoadingContext); if (!context) { throw new Error("useLoading must be used within a LoadingProvider"); } return context; };