Skip to content

Commit

Permalink
feat: 细节优化
Browse files Browse the repository at this point in the history
  • Loading branch information
weaigc committed Aug 23, 2023
1 parent 6747f79 commit 8e9e6c1
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 35 deletions.
29 changes: 5 additions & 24 deletions src/app/loading.css
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
::-webkit-scrollbar {
width: 10px;
height: 10px;
display: none;
}

::-webkit-scrollbar-button:start:decrement,
::-webkit-scrollbar-button:end:increment {
height: 30px;
background-color: transparent;
}

::-webkit-scrollbar-track-piece {
background-color: #3b3b3b;
-webkit-border-radius: 16px;
}

::-webkit-scrollbar-thumb:vertical {
height: 50px;
background-color: #666;
border: 1px solid #eee;
-webkit-border-radius: 6px;
}

/* loading start */
.loading-spinner {
display: flex;
Expand All @@ -30,6 +6,11 @@
height: 100vh;
opacity: 1;
transition: opacity .8s ease-out;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
}

.loading-spinner.hidden {
Expand Down
17 changes: 10 additions & 7 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import dynamic from 'next/dynamic'
import './loading.css'

const DynamicComponentWithNoSSR = dynamic(
() => import('../components/chat'),
{ ssr: false }
{
ssr: false,
loading: () => (
<div className="loading-spinner">
{Array.from({length: 3}).map((_, index) => <div className={`bounce${index+1}`}/>)}
</div>
)
}
)

export default function IndexPage() {
return (
<>
<div className="loading-spinner" />
<DynamicComponentWithNoSSR />
</>
)
return <DynamicComponentWithNoSSR />
}
2 changes: 1 addition & 1 deletion src/components/chat-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export function ChatPanel({
</ChatImage>
<Voice setInput={setInput} sendMessage={sendMessage} isSpeaking={isSpeaking} input={input} />
<button type="submit">
<SVG alt="send" src={SendIcon} width={18} height={22} />
<SVG alt="send" src={SendIcon} width={18} height={21} />
</button>
</div>
<ChatAttachments attachmentList={attachmentList} setAttachmentList={setAttachmentList} uploadImage={uploadImage} />
Expand Down
1 change: 1 addition & 0 deletions src/components/chat-suggestions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export function ChatSuggestions({ setInput, suggestions = [] }: ChatSuggestionsP

useMemo(() => {
setSuggestions(suggestions)
window.scrollBy(0, 400)
}, [suggestions.length, setSuggestions])

return currentSuggestions?.length ? (
Expand Down
6 changes: 5 additions & 1 deletion src/components/voice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ const Voice = ({ setInput, input, sendMessage, isSpeaking }: Pick<ReturnType<typ
sr.transcript = !isSpeaking
}, [isSpeaking])

useEffect(() => {
setListen(sr.listening)
}, [sr.listening])

useEffect(() => {
sr.onchange = (msg: string, command?: string) => {
switch (command) {
Expand Down Expand Up @@ -48,7 +52,7 @@ const Voice = ({ setInput, input, sendMessage, isSpeaking }: Pick<ReturnType<typ
sr.listening ? (
<VoiceButton className="voice-button-theme" onClick={() => switchSR(false)} />
) : (
<SVG className="cursor-pointer" alt="start voice" src={VoiceIcon} width={26} height={22} onClick={() => switchSR(true)} />
<SVG className="cursor-pointer" alt="start voice" src={VoiceIcon} width={20} height={20} onClick={() => switchSR(true)} />
)
}
</div>
Expand Down
9 changes: 7 additions & 2 deletions src/lib/bots/bing/sr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,14 @@ export class SR {

start = async () => {
if (this.recognition && !this.listening) {
await this.recognition.start()
this.transcript = true
this.listening = true
try {
await this.recognition.start()
this.transcript = true
} catch(e) {
console.error('start sr error', e)
this.listening = false
}
}
}

Expand Down

0 comments on commit 8e9e6c1

Please sign in to comment.