Skip to content

Commit

Permalink
fix: show chat box in popup
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-jianliang committed May 27, 2024
1 parent 5efe8a7 commit 2f6b17a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "popup",
"version": "0.0.4",
"version": "0.0.6",
"description": "An assistant powered by ChatGPT",
"license": "MIT",
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/popup/Popup.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.App {
.Popup-App {
position: absolute;
top: 0;
bottom: 0;
Expand All @@ -7,7 +7,7 @@
text-align: center;
height: 100%;
padding: 10px;
background-color: #282c34;
background-color: #ffffff;
}

.App-logo {
Expand Down
42 changes: 34 additions & 8 deletions src/pages/popup/Popup.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,51 @@
import React from 'react';
import React, { useEffect, useState } from 'react';
import logo from '@assets/img/logo.png';
import '@pages/popup/Popup.css';
import useStorage from '@src/shared/hooks/useStorage';
import exampleThemeStorage from '@src/shared/storages/exampleThemeStorage';
import withSuspense from '@src/shared/hoc/withSuspense';
import withErrorBoundary from '@src/shared/hoc/withErrorBoundary';
import Settings from '@pages/content/Settings/Settings';
import ChatBox from '@pages/components/ChatBox';
import { getSystemPrompt } from '@src/agent/agent';
import AgentsLoader from '@src/agent/agentsRegister';
import { Divider, Spinner } from '@chakra-ui/react';
import { createNewSession } from '@pages/content/storageUtils';

const Popup = () => {
const theme = useStorage(exampleThemeStorage);
const [agent, setAgent] = useState(null);
const [sessionId, setSessionId] = useState(-1);

useEffect(() => {
const agentsRegistry = new AgentsLoader();
agentsRegistry.loadAgents().then(agents => {
const agent = agents.get('chat-with-the-bot');
setAgent(agent);
createNewSession('Chat with the bot', agent).then(sessionId => {
setSessionId(sessionId);
});
});
}, []);

return (
<div
className="App"
style={{
backgroundColor: theme === 'light' ? '#fff' : '#000',
}}>
<div className="Popup-App">
<header className="App-header" style={{ color: theme === 'light' ? '#fff' : '#000' }}>
<img src={logo} className="App-logo" alt="logo" />
</header>
<Settings />
<Divider mb={2} />
{agent && sessionId > 0 ? (
<ChatBox
preInput=""
inputType="default"
systemPrompt={getSystemPrompt(agent, 'default')}
sessionId={sessionId}
newMessages={[]}
minW="400px"
maxH="600px"
/>
) : (
<Spinner />
)}
</div>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/pages/popup/index.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
body {
width: 580px;
height: 260px;
height: 360px;
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans',
'Droid Sans', 'Helvetica Neue', sans-serif;
Expand Down

0 comments on commit 2f6b17a

Please sign in to comment.