1- import { useRef , useState , useContext } from 'react' ;
2- import { View , Text , Image , ScrollView , Pressable , StyleSheet , ViewStyle , StyleProp , TouchableOpacity } from 'react-native' ;
1+ import { useRef , useState , useContext , useEffect } from 'react' ;
2+ import { View , Text , Image , Pressable , StyleSheet , ViewStyle , StyleProp , TouchableOpacity } from 'react-native' ;
3+ import { ScrollView } from 'react-native-gesture-handler' ;
34import { observer } from 'mobx-react-lite' ;
45
56import type BottomSheetCore from '@gorhom/bottom-sheet' ;
67import { BottomSheet } from '@clerotri/components/common/BottomSheet' ;
78import { BottomSheetScrollView } from '@gorhom/bottom-sheet' ;
89import { app , setFunction } from '@clerotri/Generic' ;
9- import { Message } from 'revolt.js' ;
10+ import { Member , Message , User } from 'revolt.js' ;
1011import { client } from '@clerotri/lib/client' ;
1112import { commonValues , ThemeContext , Theme } from '@clerotri/lib/themes' ;
12- import { Style } from 'util' ;
1313import { MiniProfile } from '../common/profile' ;
1414
1515type ReactionPile = {
1616 emoji : string ;
1717 reactors : string [ ] ;
1818} ;
1919
20- const Reactors = observer ( ( { message, reaction, style} : { message : Message | null , reaction : string | null , style : StyleProp < ViewStyle > } ) => {
21- if ( ! message || ! reaction || ! message . reactions . get ( reaction ) ) return < > </ > ;
22-
23- const rawReactors = Array . from ( message . reactions . get ( reaction ) ! . values ( ) ) ;
24- let reactors : string [ ] = [ ] ;
25- for ( const r of rawReactors ) {
26- reactors . push ( r ) ;
27- }
28-
29- return ( < >
30- { reactors . map ( ( e ) => {
31- const user = client . users . get ( e ) ;
32- if ( user && user . relationship != 'Blocked' )
33- return < TouchableOpacity
34- style = { style }
35- onPress = { ( ) => {
36- app . openProfile ( user ) ;
37- } }
38- >
39- < MiniProfile key = { `viewreactions-content-${ user . _id } ` } user = { user } />
40- </ TouchableOpacity >
41- } ) }
42- </ > ) ;
43- } ) ;
44-
4520export const ViewReactionsSheet = observer ( ( ) => {
4621 const { currentTheme} = useContext ( ThemeContext ) ;
4722 const localStyles = generateLocalStyles ( currentTheme ) ;
4823
4924 const [ message , setMessage ] = useState ( null as Message | null ) ;
5025 const [ reaction , setReaction ] = useState ( null as string | null ) ;
51- const currentReaction = ( ) => message && ( reaction && message . reactions . get ( reaction ) && message . reactions . get ( reaction ) ! . size > 0 && reaction ) || message ?. reactions . keys ( ) . next ( ) ?. toString ( ) ;
5226
5327 const sheetRef = useRef < BottomSheetCore > ( null ) ;
5428
5529 setFunction ( 'openViewReactions' , async ( m : Message | null , emoji : string ) => {
5630 setMessage ( m ) ;
57- setReaction ( emoji ) ;
31+ setReaction ( emoji || ( m ?. reactions . keys ( ) . next ( ) . value ?? null ) ) ;
5832 m ? sheetRef . current ?. expand ( ) : sheetRef . current ?. close ( ) ;
5933 } ) ;
6034
61- // const [messageReactions, setMessageReactions] = useState([] as ReactionPile[] | null);
35+ const [ reactors , setReactors ] = useState ( [ ] as User [ ] ) ;
36+
37+ useEffect ( ( ) => {
38+ if ( ! message || ! reaction || ! message . reactions . get ( reaction ) ) return ;
39+
40+ const rawReactors = Array . from ( message . reactions . get ( reaction ) ! . values ( ) ) ;
41+ setReactors ( [ ] ) ;
42+ const fetchedReactors = [ ] as User [ ] ;
43+ for ( const r of rawReactors ) {
44+ client . users . fetch ( r ) . then ( ( u ) => {
45+ fetchedReactors . push ( u ) ;
46+ setReactors ( [ ...fetchedReactors ] ) ;
47+ } ) ;
48+ }
49+ } , [ message , reaction ] ) ;
6250
6351 const rawReactions = Array . from ( message ?. reactions ?? [ ] ) ;
6452 let reactions : ReactionPile [ ] = [ ] ;
@@ -69,7 +57,7 @@ export const ViewReactionsSheet = observer(() => {
6957 return (
7058 < BottomSheet outerScroll = { 'custom' } sheetRef = { sheetRef } >
7159 { ! message ? < > </ > : (
72- < View style = { { paddingHorizontal : 16 , height : 200 } } >
60+ < View style = { { paddingHorizontal : 16 , flex : 1 } } >
7361 < ScrollView horizontal style = { {
7462 marginVertical : commonValues . sizes . small ,
7563 maxHeight : 36 ,
@@ -81,7 +69,7 @@ export const ViewReactionsSheet = observer(() => {
8169 style = { {
8270 padding : commonValues . sizes . small ,
8371 borderRadius : commonValues . sizes . small ,
84- borderColor : currentReaction ( ) && r . emoji == currentReaction ( )
72+ borderColor : reaction && r . emoji == reaction
8573 ? currentTheme . accentColor
8674 : currentTheme . backgroundTertiary ,
8775 backgroundColor : currentTheme . backgroundSecondary ,
@@ -109,7 +97,17 @@ export const ViewReactionsSheet = observer(() => {
10997 } ) }
11098 </ ScrollView >
11199 < BottomSheetScrollView >
112- < Reactors message = { message } reaction = { reaction } style = { localStyles . reactorButton } />
100+ { reactors . map ( ( user ) => {
101+ if ( user && user . relationship != 'Blocked' )
102+ return < TouchableOpacity
103+ style = { localStyles . reactorButton }
104+ onPress = { ( ) => {
105+ app . openProfile ( user ) ;
106+ } }
107+ >
108+ < MiniProfile key = { `viewreactions-content-${ user . _id } ` } user = { user } />
109+ </ TouchableOpacity >
110+ } ) }
113111 </ BottomSheetScrollView >
114112 </ View >
115113 ) }
0 commit comments