Skip to content

Commit

Permalink
fix: 滚动不能到底的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
weaigc committed Aug 25, 2023
1 parent be69511 commit 2742fa6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/components/chat-suggestions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export function ChatSuggestions({ setInput, suggestions = [] }: ChatSuggestionsP

useEffect(() => {
setSuggestions(suggestions)
window.scrollBy(0, 800)
setTimeout(() => {
window.scrollBy(0, 800)
}, 200)
}, [])

return currentSuggestions?.length ? (
Expand Down
5 changes: 4 additions & 1 deletion src/lib/hooks/chat-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,13 @@ export function useChatHistory() {
uri.searchParams.append('source', 'cib')
const data = await fetchProxy({
url: uri.toString(),
headers: {
'Content-Type': 'application/json',
},
method: 'GET',
})
console.log('data', data)
updateStorage(data)
updateStorage({ clientId: chatHistory?.clientId || '', conversationId, history: [{ id: '0', text: 'hello', author: 'user' }] })
}, [chatHistory])

const refreshChats = useCallback(async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
})
const text = await response.text()
res.writeHead(200, {
'Content-Type': 'application/text',
'Content-Type': 'application/text; charset=UTF-8',
'x-url': response.url,
'x-status': response.status,
})
Expand Down
8 changes: 6 additions & 2 deletions src/state/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BingWebBot } from '@/lib/bots/bing'
import { BingConversationStyle, ChatMessageModel, BotId } from '@/lib/bots/bing/types'
import { nanoid } from '@/lib/utils'
import { atom } from 'jotai'
import { atom, useAtom } from 'jotai'
import { atomWithImmer } from 'jotai-immer'
import { atomWithStorage, createJSONStorage } from 'jotai/utils'
import { atomFamily } from 'jotai/utils'
Expand Down Expand Up @@ -38,18 +38,22 @@ const createBotInstance = () => {

export const chatHistoryAtom = atomWithStorage<{
clientId: string;
conversationId: string;
history?: ChatMessageModel[],
}>('chatHistory', {
clientId: '',
conversationId: '',
history: [],
}, createJSONStorage(storage))

// const [messages] = useAtom(chatHistoryAtom)

export const chatFamily = atomFamily(
(param: Param) => {
return atomWithImmer({
botId: param.botId,
bot: createBotInstance(),
messages: [] as ChatMessageModel[],
messages: [],
generatingMessageId: '',
abortController: undefined as AbortController | undefined,
conversationId: nanoid(),
Expand Down

0 comments on commit 2742fa6

Please sign in to comment.