Skip to content

Commit

Permalink
feat: Added unsafe way to use the config with the possibility to have…
Browse files Browse the repository at this point in the history
… a null config and a safe way

Signed-off-by: Tom Lanser <[email protected]>
  • Loading branch information
Tommylans committed Jan 4, 2023
1 parent 9ac1380 commit 61119c7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions packages/toolbox-ui/src/ToolboxApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React from 'react'
import { RouterProvider } from 'react-router-dom'

import { GlobalErrorHandler } from './components/GlobalErrorHandler'
import { useConfig } from './contexts/ConfigProvider'
import { useConfig, useConfigUnsafe } from './contexts/ConfigProvider'

interface ToolboxAppProps {
router: RouterProviderProps['router']
Expand All @@ -31,9 +31,9 @@ const toolboxTheme = (colorScheme: ColorScheme): MantineThemeOverride => ({
})

export const ToolboxApp = ({ router }: ToolboxAppProps) => {
const { config, setColorScheme, loading } = useConfig()
const { config, setColorScheme } = useConfigUnsafe()

const colorScheme = loading ? 'light' : config.colorScheme
const colorScheme = config?.colorScheme ?? 'light'
const toggleColorScheme = (value?: ColorScheme) => setColorScheme(value || colorScheme === 'dark' ? 'light' : 'dark')

return (
Expand Down
4 changes: 2 additions & 2 deletions packages/toolbox-ui/src/contexts/AgentManagerContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { ReactNode } from 'react'

import React, { createContext, useContext, useMemo, useState } from 'react'

import { useConfig } from './ConfigProvider'
import { useConfig, useConfigUnsafe } from './ConfigProvider'

export interface IAgentContext {
agents: AgentConfigRecord[]
Expand Down Expand Up @@ -33,7 +33,7 @@ interface AgentManagerProviderProps {
}

export const AgentManagerProvider = ({ children }: AgentManagerProviderProps) => {
const { config, addAgent, loading } = useConfig()
const { config, addAgent, loading } = useConfigUnsafe()
const [currentAgentId, setCurrentAgentId] = useState<string>()

const logout = () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/toolbox-ui/src/contexts/ConfigProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export const useConfig = () => {
}
}

export const useConfigUnsafe = () => {
return useContext(configContext)
}

interface ConfigProviderProps {
children: ReactNode
configRepository: ConfigFileRepository
Expand Down

0 comments on commit 61119c7

Please sign in to comment.