feat: add global _activeAssistant and_activeTopic variable to persist state across re-renders
This commit is contained in:
parent
40e76f3e53
commit
2fdf0acec6
@ -1,9 +1,13 @@
|
|||||||
import { Assistant } from '@renderer/types'
|
import { Assistant, Topic } from '@renderer/types'
|
||||||
import { find } from 'lodash'
|
import { find } from 'lodash'
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
|
|
||||||
|
let _activeTopic: Topic
|
||||||
|
|
||||||
export function useActiveTopic(assistant: Assistant) {
|
export function useActiveTopic(assistant: Assistant) {
|
||||||
const [activeTopic, setActiveTopic] = useState(assistant?.topics[0])
|
const [activeTopic, setActiveTopic] = useState(_activeTopic || assistant?.topics[0])
|
||||||
|
|
||||||
|
_activeTopic = activeTopic
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// activeTopic not in assistant.topics
|
// activeTopic not in assistant.topics
|
||||||
|
|||||||
@ -8,14 +8,19 @@ import { uuid } from '@renderer/utils'
|
|||||||
import { useShowAssistants, useShowRightSidebar } from '@renderer/hooks/useStore'
|
import { useShowAssistants, useShowRightSidebar } from '@renderer/hooks/useStore'
|
||||||
import Navigation from './components/NavigationCenter'
|
import Navigation from './components/NavigationCenter'
|
||||||
import { isMac, isWindows } from '@renderer/config/constant'
|
import { isMac, isWindows } from '@renderer/config/constant'
|
||||||
|
import { Assistant } from '@renderer/types'
|
||||||
|
|
||||||
|
let _activeAssistant: Assistant
|
||||||
|
|
||||||
const HomePage: FC = () => {
|
const HomePage: FC = () => {
|
||||||
const { assistants, addAssistant } = useAssistants()
|
const { assistants, addAssistant } = useAssistants()
|
||||||
const [activeAssistant, setActiveAssistant] = useState(assistants[0])
|
const [activeAssistant, setActiveAssistant] = useState(_activeAssistant || assistants[0])
|
||||||
const { rightSidebarShown, toggleRightSidebar } = useShowRightSidebar()
|
const { rightSidebarShown, toggleRightSidebar } = useShowRightSidebar()
|
||||||
const { showAssistants, toggleShowAssistants } = useShowAssistants()
|
const { showAssistants, toggleShowAssistants } = useShowAssistants()
|
||||||
const { defaultAssistant } = useDefaultAssistant()
|
const { defaultAssistant } = useDefaultAssistant()
|
||||||
|
|
||||||
|
_activeAssistant = activeAssistant
|
||||||
|
|
||||||
const onCreateAssistant = () => {
|
const onCreateAssistant = () => {
|
||||||
const assistant = { ...defaultAssistant, id: uuid() }
|
const assistant = { ...defaultAssistant, id: uuid() }
|
||||||
addAssistant(assistant)
|
addAssistant(assistant)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user