refactor: use generateId() for id creation (#736)
This commit is contained in:
parent
085f4a8ac4
commit
2d47ffbd77
8 changed files with 20 additions and 75 deletions
|
|
@ -5,7 +5,6 @@ import { useEffect, useRef } from 'react';
|
|||
import { blockDefinitions, BlockKind } from './block';
|
||||
import { Suggestion } from '@/lib/db/schema';
|
||||
import { initialBlockData, useBlock } from '@/hooks/use-block';
|
||||
import { useUserMessageId } from '@/hooks/use-user-message-id';
|
||||
|
||||
export type DataStreamDelta = {
|
||||
type:
|
||||
|
|
@ -17,14 +16,12 @@ export type DataStreamDelta = {
|
|||
| 'suggestion'
|
||||
| 'clear'
|
||||
| 'finish'
|
||||
| 'user-message-id'
|
||||
| 'kind';
|
||||
content: string | Suggestion;
|
||||
};
|
||||
|
||||
export function DataStreamHandler({ id }: { id: string }) {
|
||||
const { data: dataStream } = useChat({ id });
|
||||
const { setUserMessageIdFromServer } = useUserMessageId();
|
||||
const { block, setBlock, setMetadata } = useBlock();
|
||||
const lastProcessedIndex = useRef(-1);
|
||||
|
||||
|
|
@ -35,11 +32,6 @@ export function DataStreamHandler({ id }: { id: string }) {
|
|||
lastProcessedIndex.current = dataStream.length - 1;
|
||||
|
||||
(newDeltas as DataStreamDelta[]).forEach((delta: DataStreamDelta) => {
|
||||
if (delta.type === 'user-message-id') {
|
||||
setUserMessageIdFromServer(delta.content as string);
|
||||
return;
|
||||
}
|
||||
|
||||
const blockDefinition = blockDefinitions.find(
|
||||
(blockDefinition) => blockDefinition.kind === block.kind,
|
||||
);
|
||||
|
|
@ -97,7 +89,7 @@ export function DataStreamHandler({ id }: { id: string }) {
|
|||
}
|
||||
});
|
||||
});
|
||||
}, [dataStream, setBlock, setUserMessageIdFromServer, setMetadata, block]);
|
||||
}, [dataStream, setBlock, setMetadata, block]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue