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

thread-feed-scroll-position.ts

33 lines1.2 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 // Keeping the first message's anchor holds a short thread in place; a follow-up never anchors.
24 if (input.currentAnchorMessageId !== null) {
25 return input.currentAnchorMessageId;
26 }
27​
28 if (input.deliveryDeferred || input.hasStartedTurn || input.hasUserMessage) {
29 return null;
30 }
31​
32 return input.queuedMessageCount > 0 ? null : input.submittedMessageId;