Skip to content

Commit

Permalink
fix: Fixed an issue where quotes in messages could not be displayed #…
Browse files Browse the repository at this point in the history
…2677 (#2683)

### What problem does this PR solve?

fix: Fixed an issue where quotes in messages could not be displayed
#2677

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
- [ ] New Feature (non-breaking change which adds functionality)
- [ ] Documentation Update
- [ ] Refactoring
- [ ] Performance Improvement
- [ ] Other (please describe):
  • Loading branch information
cike8899 authored Sep 30, 2024
1 parent 2368d73 commit 92a4a09
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions web/src/hooks/logic-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,16 @@ export const useSendMessageWithSse = (
) => {
const [answer, setAnswer] = useState<IAnswer>({} as IAnswer);
const [done, setDone] = useState(true);
const timer = useRef<any>();

const resetAnswer = useCallback(() => {
setAnswer({} as IAnswer);
if (timer.current) {
clearTimeout(timer.current);
}
timer.current = setTimeout(() => {
setAnswer({} as IAnswer);
clearTimeout(timer.current);
}, 1000);
}, []);

const send = useCallback(
Expand Down Expand Up @@ -251,7 +258,7 @@ export const useSendMessageWithSse = (
const { done, value } = x;
if (done) {
console.info('done');
setAnswer({} as IAnswer);
resetAnswer();
break;
}
try {
Expand All @@ -271,16 +278,16 @@ export const useSendMessageWithSse = (
}
console.info('done?');
setDone(true);
setAnswer({} as IAnswer);
resetAnswer();
return { data: await res, response };
} catch (e) {
setDone(true);
setAnswer({} as IAnswer);
resetAnswer();

console.warn(e);
}
},
[url],
[url, resetAnswer],
);

return { send, answer, done, setDone, resetAnswer };
Expand Down

0 comments on commit 92a4a09

Please sign in to comment.