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

chatList.ts

33 lines855 Bytes

1export const CHAT_LIST_ANCHOR_OFFSET = 16;
2​
3export interface ChatListAnchoredEndSpace {
4 readonly anchorIndex: number;
5 readonly anchorOffset: number;
6}
7​
8export interface ChatListAnchorOptions {
9 readonly anchorOffset?: number;
11​
12export function resolveChatListAnchoredEndSpace<Item, AnchorId>(
13 items: ReadonlyArray<Item>,
14 anchorId: AnchorId | null,
15 getAnchorId: (item: Item) => AnchorId | null,
16 options: ChatListAnchorOptions = {},
17): ChatListAnchoredEndSpace | undefined {
18 if (anchorId === null) {
19 return undefined;
20 }
21​
22 for (let index = items.length - 1; index >= 0; index -= 1) {
23 const item = items[index];
24 if (item !== undefined && getAnchorId(item) === anchorId) {
25 return {
26 anchorIndex: index,
27 anchorOffset: options.anchorOffset ?? CHAT_LIST_ANCHOR_OFFSET,
28 };
29 }
30 }
31​
32 return undefined;