Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

thread-feed-scroll-position.ts

32 lines1.1 KB

1export interface ThreadWorkGroupScrollPosition {
2 readonly rowId: string;
3 readonly offsetWithinRow: number;
4 readonly scrollOffset: number;
5}
6​
7export function resolveThreadWorkGroupInitialScroll(
8 rows: ReadonlyArray<{ readonly id: string }>,
9 position: ThreadWorkGroupScrollPosition | undefined,
10) {
11 const index = position ? rows.findIndex((row) => row.id === position.rowId) : -1;
12 return index >= 0 && position ? { index, viewOffset: -position.offsetWithinRow } : undefined;
14​
15export function resolveThreadFeedSubmissionAnchor<AnchorId>(input: {
16 readonly currentAnchorMessageId: AnchorId | null;
17 readonly submittedMessageId: AnchorId;
18 readonly hasStartedTurn: boolean;
19 readonly hasUserMessage: boolean;
20 readonly queuedMessageCount: number;
21 readonly deliveryDeferred: boolean;
22}): AnchorId | null {
23 if (input.deliveryDeferred || input.hasStartedTurn || input.hasUserMessage) {
24 return null;
25 }
26​
27 if (input.currentAnchorMessageId !== null) {
28 return input.currentAnchorMessageId;
29 }
30​
31 return input.queuedMessageCount > 0 ? null : input.submittedMessageId;