MCPcopy Create free account
hub / github.com/ChatGPTBox-dev/chatGPTBox / App

Function App

src/pages/IndependentPanel/App.jsx:20–187  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18import FileSaver from 'file-saver'
19
20function App() {
21 const { t } = useTranslation()
22 const [collapsed, setCollapsed] = useState(true)
23 const config = useConfig(null, false)
24 const [sessions, setSessions] = useState([])
25 const [sessionId, setSessionId] = useState(null)
26 const [currentSession, setCurrentSession] = useState(null)
27 const [renderContent, setRenderContent] = useState(false)
28 const currentPort = useRef(null)
29
30 const setSessionIdSafe = async (sessionId) => {
31 if (currentPort.current) {
32 try {
33 currentPort.current.postMessage({ stop: true })
34 currentPort.current.disconnect()
35 } catch (e) {
36 /* empty */
37 }
38 currentPort.current = null
39 }
40 const { session, currentSessions } = await getSession(sessionId)
41 if (session) setSessionId(sessionId)
42 else if (currentSessions.length > 0) setSessionId(currentSessions[0].sessionId)
43 }
44
45 useEffect(() => {
46 document.documentElement.dataset.theme = config.themeMode
47 }, [config.themeMode])
48
49 useEffect(() => {
50 // eslint-disable-next-line
51 ;(async () => {
52 const urlFrom = new URLSearchParams(window.location.search).get('from')
53 const sessions = await getSessions()
54 if (
55 urlFrom !== 'store' &&
56 sessions[0].conversationRecords &&
57 sessions[0].conversationRecords.length > 0
58 ) {
59 await createNewChat()
60 } else {
61 setSessions(sessions)
62 await setSessionIdSafe(sessions[0].sessionId)
63 }
64 })()
65 }, [])
66
67 useEffect(() => {
68 if ('sessions' in config && config['sessions']) setSessions(config['sessions'])
69 }, [config])
70
71 useEffect(() => {
72 // eslint-disable-next-line
73 ;(async () => {
74 if (sessions.length > 0) {
75 setCurrentSession((await getSession(sessionId)).session)
76 setRenderContent(false)
77 setTimeout(() => {

Callers

nothing calls this directly

Calls 9

useConfigFunction · 0.90
getSessionsFunction · 0.90
getSessionFunction · 0.90
deleteSessionFunction · 0.90
openUrlFunction · 0.90
updateSessionFunction · 0.90
createNewChatFunction · 0.85
setSessionIdSafeFunction · 0.85
tFunction · 0.85

Tested by

no test coverage detected