Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

context.tsx 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. 'use client'
  2. import type { ReactNode } from 'react'
  3. import React, { createContext, useContext, useEffect, useState } from 'react'
  4. import { usePathname } from 'next/navigation'
  5. /**
  6. * Interface for the GotoAnything context
  7. */
  8. type GotoAnythingContextType = {
  9. /**
  10. * Whether the current page is a workflow page
  11. */
  12. isWorkflowPage: boolean
  13. }
  14. // Create context with default values
  15. const GotoAnythingContext = createContext<GotoAnythingContextType>({
  16. isWorkflowPage: false,
  17. })
  18. /**
  19. * Hook to use the GotoAnything context
  20. */
  21. export const useGotoAnythingContext = () => useContext(GotoAnythingContext)
  22. type GotoAnythingProviderProps = {
  23. children: ReactNode
  24. }
  25. /**
  26. * Provider component for GotoAnything context
  27. */
  28. export const GotoAnythingProvider: React.FC<GotoAnythingProviderProps> = ({ children }) => {
  29. const [isWorkflowPage, setIsWorkflowPage] = useState(false)
  30. const pathname = usePathname()
  31. // Update context based on current pathname
  32. useEffect(() => {
  33. // Check if current path contains workflow
  34. const isWorkflow = pathname?.includes('/workflow') || false
  35. setIsWorkflowPage(isWorkflow)
  36. }, [pathname])
  37. return (
  38. <GotoAnythingContext.Provider value={{ isWorkflowPage }}>
  39. {children}
  40. </GotoAnythingContext.Provider>
  41. )
  42. }