1
1
import React , { useEffect } from 'react' ;
2
2
import { ComputeItemKey , Virtuoso } from 'react-virtuoso' ;
3
- import { StreamChat } from 'stream-chat' ;
4
3
5
4
import type { ComponentType , PointerEvent } from 'react' ;
6
- import type { InferStoreValueType , Thread } from 'stream-chat' ;
5
+ import type { InferStoreValueType , Thread , ThreadManager } from 'stream-chat' ;
7
6
8
7
import { ThreadListItem } from './ThreadListItem' ;
9
8
import { useChatContext } from '../../../context' ;
10
9
import { useSimpleStateStore } from '../hooks/useSimpleStateStore' ;
11
10
12
11
import type { ThreadListItemProps } from './ThreadListItem' ;
13
12
14
- const selector = ( v : InferStoreValueType < StreamChat [ 'threads' ] > ) => [ v . threads ] as const ;
13
+ /**
14
+ * TODO:
15
+ * - add virtuosoProps override \w support for supplying custom threads array (typed virtuoso props, Thread[] only)
16
+ * - register event handlers of each of the threads (ThreadManager - threads.<de/register>EventHandlers(), maybe simplify API)
17
+ * - add Header with re-query button + logic to ThreadManager
18
+ * - add Footer with "Loading"
19
+ * - move str-chat someplace else, think of a different name (str-chat__thread-list already used)
20
+ * - move itemContent to a component instead
21
+ *
22
+ * NICE TO HAVE:
23
+ * - probably good idea to move component context up to a Chat component
24
+ */
25
+
26
+ const selector = ( nextValue : InferStoreValueType < ThreadManager > ) => [ nextValue . threads ] as const ;
15
27
16
28
const computeItemKey : ComputeItemKey < Thread , unknown > = ( _ , item ) => item . id ;
17
29
18
30
type ThreadListProps = {
19
31
onItemPointerDown ?: ( event : PointerEvent < HTMLButtonElement > , thread : Thread ) => void ;
20
32
ThreadListItem ?: ComponentType < ThreadListItemProps > ;
21
- // TODO: should support supplying custom threads array
22
33
// threads?: Thread[]
23
34
} ;
24
35
25
- // TODO: probably good idea to move component context up to a Chat component
26
-
27
36
export const ThreadList = ( {
28
37
ThreadListItem : PropsThreadListItem = ThreadListItem ,
29
38
onItemPointerDown,
@@ -37,11 +46,7 @@ export const ThreadList = ({
37
46
38
47
return (
39
48
< Virtuoso
40
- atBottomStateChange = { ( atBottom ) =>
41
- // TODO: figure out - handle next page load blocking client-side or here?
42
- atBottom && client . threads . loadNextPage ( )
43
- }
44
- // TODO: str-chat class name does not belong here, str-chat__thread-list is already used (FUCK ME SIDEWAYS)
49
+ atBottomStateChange = { ( atBottom ) => atBottom && client . threads . loadNextPage ( ) }
45
50
className = 'str-chat str-chat__thread-list'
46
51
computeItemKey = { computeItemKey }
47
52
data = { threads }
0 commit comments