Skip to content

Commit

Permalink
feat: chatgpt markmap
Browse files Browse the repository at this point in the history
  • Loading branch information
wkylin committed Jul 23, 2023
1 parent 88cdd92 commit bfcfb2f
Show file tree
Hide file tree
Showing 3 changed files with 232 additions and 16 deletions.
217 changes: 211 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@
"react-redux": "^8.1.1",
"react-ripples": "^2.2.1",
"react-router-dom": "^6.14.1",
"react-scroll-to-bottom": "^4.2.0",
"react-sticky": "^6.0.3",
"react-sticky-ts": "^1.0.7",
"react-tilt": "^1.0.2",
Expand Down
30 changes: 20 additions & 10 deletions src/pages/chatgpt/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,37 @@ import initSSE from './sse'
const ChatGpt = () => {
const markmapRef = useRef(null)
const [form] = Form.useForm()

// 生成概述
const apiResultRef = useRef('')
const [apiResult, setApiResult] = useState('')
const [readyState, setReadyState] = useState(-1)
const [apiKey, setApiKey] = useState('')

const bottomRef = useRef(null)

// 生成页面结构
const [structureResult, setStructureResult] = useState('')
const [structureReadyState, setStructureReadyState] = useState(-1)
const structureResultRef = useRef()
useEffect(() => {
structureResultRef.current = structureResult
}, [structureResult])

useEffect(() => {
bottomRef.current?.scrollIntoView({ behavior: 'smooth' })
}, [apiResult, structureResult])

const onChange = (event) => {
setApiKey(event.target.value)
}
const onFinish = (values) => {
const { apiText, text } = values
setApiKey(apiText)
const { text } = values
setApiResult('')
apiResultRef.current = ''
setStructureResult('')
structureResultRef.current = ''
const source = initSSE(apiText, text)
const source = initSSE(apiKey, text)
source.addEventListener('message', (e) => {
if (e.data !== '[DONE]') {
const payload = JSON.parse(e.data)
Expand All @@ -52,13 +67,6 @@ const ChatGpt = () => {
source.stream()
}

// 生成页面结构
const [structureResult, setStructureResult] = useState('')
const [structureReadyState, setStructureReadyState] = useState(-1)
const structureResultRef = useRef()
useEffect(() => {
structureResultRef.current = structureResult
}, [structureResult])
const onButtonClick = useCallback(
(key) => {
if (markmapRef.current === null) {
Expand Down Expand Up @@ -249,6 +257,8 @@ const ChatGpt = () => {
<MarkmapHooks markmap={structureResult} />
</section>
)}

<div ref={bottomRef} style={{ height: 20, marginBottom: 20 }} />
</FixTabPanel>
</>
)
Expand Down

1 comment on commit bfcfb2f

@vercel
Copy link

@vercel vercel bot commented on bfcfb2f Jul 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

pro-react-admin – ./

pro-react-admin.vercel.app
pro-react-admin-git-main-wkylin.vercel.app
pro-react-admin-wkylin.vercel.app

Please sign in to comment.