32 lines
701 B
TypeScript
32 lines
701 B
TypeScript
import { useCallback, useState } from "react";
|
|
|
|
export interface LocalTimelineEvent {
|
|
readonly createdAt: number;
|
|
readonly id: string;
|
|
readonly text: string;
|
|
readonly type: "client.prompt";
|
|
}
|
|
|
|
export const useGlobalTimeline = () => {
|
|
const [events, setEvents] = useState<readonly LocalTimelineEvent[]>([]);
|
|
|
|
const addPrompt = useCallback((text: string) => {
|
|
const normalizedText = text.trim();
|
|
if (!normalizedText) {
|
|
return;
|
|
}
|
|
|
|
setEvents((current) => [
|
|
...current,
|
|
{
|
|
createdAt: Date.now(),
|
|
id: crypto.randomUUID(),
|
|
text: normalizedText,
|
|
type: "client.prompt",
|
|
},
|
|
]);
|
|
}, []);
|
|
|
|
return { addPrompt, events };
|
|
};
|