-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: notifications and mentions screen
- Loading branch information
1 parent
98790db
commit 6882ea3
Showing
10 changed files
with
396 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './notification-screen'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { useNavigation } from '@react-navigation/native'; | ||
import axios from 'axios'; | ||
import { useCallback, useEffect, useState } from 'react'; | ||
import { FlatList, RefreshControl } from 'react-native'; | ||
|
||
import type { Snap } from '@/api'; | ||
import { useMentions } from '@/api'; | ||
import { getUserState } from '@/core'; | ||
import { EmptyList, FocusAwareStatusBar, Text, View } from '@/ui'; | ||
|
||
import { Card } from '../feed/card'; | ||
|
||
const INCREMENT_RENDER = 10; | ||
const INITIAL_RENDER = 20; | ||
|
||
const BASE_INTERACTION_URL = | ||
'https://api-content-discovery-luiscusihuaman.cloud.okteto.net/api/interactions/'; | ||
|
||
const MentionScreen = () => { | ||
const currentUser = getUserState(); | ||
|
||
const { data, isLoading, isError, refetch } = useMentions({ | ||
variables: { user_id: currentUser?.id }, | ||
}); | ||
|
||
const [mentionSnaps, setMentionSnaps] = useState<Snap[]>([]); | ||
|
||
useEffect(() => { | ||
setMentionSnaps(data ? data : []); | ||
}, [data]); | ||
|
||
const { navigate } = useNavigation(); | ||
|
||
// State to track the number of items to render | ||
const [renderCount, setRenderCount] = useState(INITIAL_RENDER); | ||
const [refresh, setRefresh] = useState(false); | ||
|
||
// The useCallback hook | ||
const onRefresh = useCallback(() => { | ||
setRefresh(true); | ||
refetch().then(() => setRefresh(false)); | ||
}, [refetch]); | ||
|
||
// Early return in case of error | ||
if (isError) { | ||
return ( | ||
<View> | ||
<Text> Error Loading data </Text> | ||
</View> | ||
); | ||
} | ||
|
||
const client = axios.create({ | ||
baseURL: BASE_INTERACTION_URL, | ||
}); | ||
|
||
// Corrected renderItem function | ||
const renderItem = ({ item, index }: { item: Snap; index: number }) => { | ||
if (index < renderCount) { | ||
return ( | ||
<Card | ||
snap={item} | ||
client={client} | ||
onPress={() => navigate('Snap', { snap: item })} | ||
/> | ||
); | ||
} | ||
return null; | ||
}; | ||
|
||
const handleEndReached = () => { | ||
console.log(`handleEndReached before: ${renderCount}`); | ||
|
||
// Load more items when the user reaches the end | ||
if (renderCount < (data ? data.length : 0)) { | ||
setRenderCount(renderCount + INCREMENT_RENDER); | ||
} | ||
|
||
// console.log(`handleEndReached after: ${renderCount}`); | ||
}; | ||
|
||
return ( | ||
<View> | ||
<FocusAwareStatusBar /> | ||
|
||
<FlatList | ||
data={mentionSnaps} | ||
renderItem={renderItem} | ||
keyExtractor={(_, index) => `item-${index}`} | ||
ListEmptyComponent={<EmptyList isLoading={isLoading} />} | ||
onEndReached={handleEndReached} | ||
onEndReachedThreshold={0.1} | ||
refreshControl={ | ||
<RefreshControl refreshing={refresh} onRefresh={onRefresh} /> | ||
} | ||
getItemLayout={(_data, index) => ({ | ||
length: 100, | ||
offset: 100 * index, | ||
index, | ||
})} | ||
/> | ||
</View> | ||
); | ||
}; | ||
|
||
export default MentionScreen; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { Text, TouchableOpacity, View } from 'react-native'; | ||
|
||
import { Image } from '@/ui'; | ||
|
||
import type { Notification } from './types'; | ||
|
||
export type NotificationCardProps = { | ||
uri: string; | ||
title: string; | ||
description: string; | ||
onPress: () => void; | ||
}; | ||
|
||
export default function NotificationCard({}: { | ||
notification: Notification | null; | ||
}) { | ||
return ( | ||
<View className="max-w-md flex-1 overflow-hidden rounded-lg bg-white shadow-black"> | ||
<View style={{ width: 2, backgroundColor: 'gray-800' }} /> | ||
<View style={{ flexDirection: 'row', alignItems: 'center', padding: 6 }}> | ||
<Image | ||
style={{ width: 48, height: 48, borderRadius: 24 }} | ||
source={{ | ||
uri: 'https://images.unsplash.com/photo-1477118476589-bff2c5c4cfbb?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60', | ||
}} | ||
/> | ||
<View style={{ marginLeft: 9 }}> | ||
<Text style={{ fontSize: 18, fontWeight: '600', color: 'gray-800' }}> | ||
Hello john | ||
</Text> | ||
<Text style={{ color: 'gray-600' }}> | ||
Sara was replied on the{' '} | ||
<TouchableOpacity> | ||
<Text style={{ color: 'blue-500' }}>Upload Image</Text> | ||
</TouchableOpacity> | ||
. | ||
</Text> | ||
</View> | ||
</View> | ||
|
||
<View style={{ width: 2, backgroundColor: 'gray-800' }} /> | ||
<View style={{ flexDirection: 'row', alignItems: 'center', padding: 6 }}> | ||
<Image | ||
style={{ width: 48, height: 48, borderRadius: 24 }} | ||
source={{ | ||
uri: 'https://images.unsplash.com/photo-1477118476589-bff2c5c4cfbb?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60', | ||
}} | ||
/> | ||
<View style={{ marginLeft: 9 }}> | ||
<Text style={{ fontSize: 18, fontWeight: '600', color: 'gray-800' }}> | ||
Hello john | ||
</Text> | ||
<Text style={{ color: 'gray-600' }}> | ||
Sara was replied on the{' '} | ||
<TouchableOpacity> | ||
<Text style={{ color: 'blue-500' }}>Upload Image</Text> | ||
</TouchableOpacity> | ||
. | ||
</Text> | ||
</View> | ||
</View> | ||
<View style={{ width: 2, backgroundColor: 'gray-800' }} /> | ||
<View style={{ flexDirection: 'row', alignItems: 'center', padding: 6 }}> | ||
<Image | ||
style={{ width: 48, height: 48, borderRadius: 24 }} | ||
source={{ | ||
uri: 'https://images.unsplash.com/photo-1477118476589-bff2c5c4cfbb?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60', | ||
}} | ||
/> | ||
<View style={{ marginLeft: 9 }}> | ||
<Text style={{ fontSize: 18, fontWeight: '600', color: 'gray-800' }}> | ||
Hello john | ||
</Text> | ||
<Text style={{ color: 'gray-600' }}> | ||
Sara was replied on the{' '} | ||
<TouchableOpacity> | ||
<Text style={{ color: 'blue-500' }}>Upload Image</Text> | ||
</TouchableOpacity> | ||
. | ||
</Text> | ||
</View> | ||
</View> | ||
<View style={{ width: 2, backgroundColor: 'gray-800' }} /> | ||
<View style={{ flexDirection: 'row', alignItems: 'center', padding: 6 }}> | ||
<Image | ||
style={{ width: 48, height: 48, borderRadius: 24 }} | ||
source={{ | ||
uri: 'https://images.unsplash.com/photo-1477118476589-bff2c5c4cfbb?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60', | ||
}} | ||
/> | ||
<View style={{ marginLeft: 9 }}> | ||
<Text style={{ fontSize: 18, fontWeight: '600', color: 'gray-800' }}> | ||
Hello john | ||
</Text> | ||
<Text style={{ color: 'gray-600' }}> | ||
Sara was replied on the{' '} | ||
<TouchableOpacity> | ||
<Text style={{ color: 'blue-500' }}>Upload Image</Text> | ||
</TouchableOpacity> | ||
. | ||
</Text> | ||
</View> | ||
</View> | ||
</View> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { createNativeStackNavigator } from '@react-navigation/native-stack'; | ||
import * as React from 'react'; | ||
|
||
import type { Snap as SnapType } from '@/api'; | ||
import { Snap } from '@/screens'; | ||
|
||
import NotionficationScreen from './notification-screen'; | ||
|
||
export type NotificationStackParamList = { | ||
Notifications: {}; | ||
Snap: { snap: SnapType }; | ||
}; | ||
|
||
const Stack = createNativeStackNavigator<NotificationStackParamList>(); | ||
|
||
export const NotificationNavigator = () => { | ||
return ( | ||
<Stack.Navigator> | ||
<Stack.Screen name="Notifications" component={NotionficationScreen} /> | ||
<Stack.Screen name="Snap" component={Snap} /> | ||
</Stack.Navigator> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react'; | ||
|
||
import { FocusAwareStatusBar, View } from '@/ui'; | ||
|
||
import NotificationView from './notification-view'; | ||
|
||
const NotionficationScreen = () => { | ||
return ( | ||
<> | ||
<FocusAwareStatusBar /> | ||
<View> | ||
<NotificationView /> | ||
</View> | ||
{/* <View> | ||
<Text>Mentions</Text> | ||
<MentionScreen /> | ||
</View> */} | ||
</> | ||
); | ||
}; | ||
|
||
export default NotionficationScreen; |
Oops, something went wrong.