rendering topics

This commit is contained in:
balzack 2022-09-29 23:19:15 -07:00
parent 0251b648ef
commit 9dce08ff64
4 changed files with 21 additions and 4 deletions

View File

@ -15,6 +15,10 @@ import { ChannelContextProvider } from 'context/ChannelContext';
import { SafeAreaProvider, SafeAreaView } from 'react-native-safe-area-context';
import { NavigationContainer } from '@react-navigation/native';
import { ConversationContextProvider } from 'context/ConversationContext';
import { LogBox } from 'react-native';
// silence warning: Sending `onAnimatedValueUpdate` with no listeners registered
//LogBox.ignoreLogs(['Sending']);
export default function App() {

View File

@ -152,6 +152,7 @@ export function useConversationContext() {
// update revision
revision.current = channelItem.revision;
if (curView == setView.current) {
console.log("update:", topics.current.size);
updateState({ topics: topics.current });
}

View File

@ -36,8 +36,8 @@ export function ConversationBody({ channel }) {
<FlatList style={styles.topics}
data={state.topics}
inverted={true}
renderItem={({item}) => <View style={{ height: item.id }}><Text>ITEM { item.id }</Text></View>}
keyExtractor={item => item.id}
renderItem={({item}) => <View><Text>ITEM { item?.detail?.data }</Text></View>}
keyExtractor={item => item.topicId}
/>
);
}

View File

@ -16,8 +16,20 @@ export function useConversation(cardId, channelId) {
}
useEffect(() => {
const { topics, subject, logo } = conversation.state;
updateState({ topics, subject, logo });
const { subject, logo, topics } = conversation.state;
const items = Array.from(topics.values());
const sorted = items.sort((a, b) => {
const aTimestamp = a?.detail?.created;
const bTimestamp = b?.detail?.created;
if(aTimestamp === bTimestamp) {
return 0;
}
if(aTimestamp == null || aTimestamp < bTimestamp) {
return 1;
}
return -1;
});
updateState({ topics, subject, logo, topics: sorted });
}, [conversation]);
const actions = {