-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added BottomSheet using reanimated-bottom-sheet for Post Menu and sharing modal Code Cleanup
- Loading branch information
Showing
21 changed files
with
1,054 additions
and
310 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React from "react"; | ||
import { ToastAndroid, useWindowDimensions, View } from "react-native"; | ||
import { List } from "react-native-paper"; | ||
import { useNavigation } from "@react-navigation/native"; | ||
import PostsStore from "../../store/PostsStore"; | ||
|
||
type ModalProps = { | ||
closeModal: () => void; | ||
ownPost: boolean; | ||
postId: number; | ||
username: string; | ||
viewProfile: () => void; | ||
}; | ||
|
||
export const PostModal: React.FC<ModalProps> = ({ | ||
postId, | ||
closeModal, | ||
ownPost, | ||
viewProfile, | ||
}) => { | ||
const { width } = useWindowDimensions(); | ||
const navigation = useNavigation(); | ||
const deletePost = async () => { | ||
try { | ||
await PostsStore.deletePost(postId); | ||
closeModal(); | ||
navigation.goBack(); | ||
} catch (err) { | ||
console.error("[deletePost]", err); | ||
ToastAndroid.show("An error occured", ToastAndroid.LONG); | ||
} | ||
}; | ||
|
||
const openProfile = () => { | ||
closeModal(); | ||
viewProfile(); | ||
}; | ||
|
||
return ( | ||
<View | ||
style={{ | ||
width, | ||
backgroundColor: "#1f1f1f", | ||
justifyContent: "center", | ||
paddingVertical: 16, | ||
zIndex: 6, | ||
elevation: 6, | ||
}} | ||
> | ||
{ownPost && ( | ||
<List.Item | ||
title="Delete Post" | ||
onPress={deletePost} | ||
style={{ | ||
paddingHorizontal: 16, | ||
}} | ||
/> | ||
)} | ||
|
||
<List.Item | ||
title="View Profile" | ||
onPress={openProfile} | ||
style={{ | ||
paddingHorizontal: 16, | ||
}} | ||
/> | ||
</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,178 @@ | ||
import React, { useContext, useEffect, useState } from "react"; | ||
import { | ||
ActivityIndicator, | ||
FlatList, | ||
StatusBar, | ||
TextInput, | ||
ToastAndroid, | ||
useWindowDimensions, | ||
View, | ||
} from "react-native"; | ||
import { Divider, Text, useTheme } from "react-native-paper"; | ||
import NewChatItem, { | ||
NewChatItemType, | ||
} from "../../Screens/Messages/NewChatItem"; | ||
import { Follower } from "../../store/FollowersStore"; | ||
import MessagesStore, { Message } from "../../store/MessagesStore"; | ||
import { AppContext } from "../../utils/appContext"; | ||
import { newMessageInDb } from "../../utils/supabaseUtils"; | ||
import useChatList, { ChatList } from "../../utils/useChatList"; | ||
import useUser from "../../utils/useUser"; | ||
|
||
type ModalProps = { | ||
closeModal: () => void; | ||
postId: number; | ||
}; | ||
|
||
const PostShareModal: React.FC<ModalProps> = ({ postId, closeModal }) => { | ||
const { colors } = useTheme(); | ||
const { width, height } = useWindowDimensions(); | ||
const { messageList, loading } = useChatList(); | ||
const [searchTerm, setSearchTerm] = useState(""); | ||
|
||
const { username: currentUsername } = useContext(AppContext); | ||
const { following } = useUser(currentUsername); | ||
|
||
const [chatList, setChatList] = useState<NewChatItemType[]>([]); | ||
|
||
const getUsersList = (chatsList: ChatList[], followingList: Follower[]) => { | ||
const followingListData = followingList.map((user) => ({ | ||
username: user.following, | ||
})); | ||
|
||
const chatListData = [...chatsList, ...followingListData]; | ||
return [ | ||
...new Map( | ||
chatListData.map((item) => [item.username, item]) | ||
).values(), | ||
]; | ||
}; | ||
|
||
const [searchResults, setSearchResults] = useState< | ||
NewChatItemType[] | null | ||
>(null); | ||
|
||
useEffect(() => { | ||
if (searchTerm.length > 0) { | ||
setSearchResults( | ||
messageList.filter((item) => | ||
item.username.includes(searchTerm.toLowerCase()) | ||
) | ||
); | ||
} else { | ||
setSearchResults(null); | ||
} | ||
}, [messageList, searchTerm]); | ||
|
||
useEffect(() => { | ||
if (messageList && following) | ||
setChatList(getUsersList(messageList, following)); | ||
}, [messageList, following]); | ||
|
||
useEffect(() => { | ||
if (searchTerm.length > 0) { | ||
setSearchResults( | ||
messageList.filter((item) => | ||
item.username.includes(searchTerm.toLowerCase()) | ||
) | ||
); | ||
} else { | ||
setSearchResults(null); | ||
} | ||
}, [messageList, searchTerm]); | ||
|
||
const newMessage = async (username: string) => { | ||
const messageToSend = { | ||
imageUrl: undefined, | ||
message_type: "POST", | ||
postId: postId, | ||
receiver: username, | ||
text: undefined, | ||
}; | ||
const newMessageData = await newMessageInDb(messageToSend); | ||
if (newMessageData) { | ||
MessagesStore.addMessage(newMessageData); | ||
ToastAndroid.show("Post sent", ToastAndroid.LONG); | ||
} | ||
closeModal(); | ||
}; | ||
|
||
return ( | ||
<View | ||
style={{ | ||
height: height / 1.5, | ||
zIndex: 2, | ||
elevation: 2, | ||
backgroundColor: "#1f1f1f", | ||
paddingVertical: 16, | ||
justifyContent: "center", | ||
}} | ||
> | ||
{loading && ( | ||
<View | ||
style={{ | ||
flex: 1, | ||
alignItems: "center", | ||
justifyContent: "center", | ||
}} | ||
> | ||
<ActivityIndicator color={colors.text} /> | ||
</View> | ||
)} | ||
|
||
<FlatList | ||
ListHeaderComponent={ | ||
<> | ||
<TextInput | ||
placeholder="Search" | ||
placeholderTextColor={"gray"} | ||
onChangeText={(text) => setSearchTerm(text)} | ||
style={{ | ||
flex: 1, | ||
marginHorizontal: 16, | ||
marginVertical: 16, | ||
height: 40, | ||
backgroundColor: "#3a3a3a", | ||
borderRadius: 6, | ||
paddingHorizontal: 16, | ||
color: colors.text, | ||
}} | ||
/> | ||
<Divider /> | ||
<Text | ||
style={{ | ||
marginHorizontal: 16, | ||
marginTop: 16, | ||
}} | ||
> | ||
Suggested | ||
</Text> | ||
</> | ||
} | ||
ListEmptyComponent={ | ||
<View | ||
style={{ | ||
display: "flex", | ||
flexDirection: "column", | ||
height: height - (StatusBar.currentHeight || 0), | ||
alignItems: "center", | ||
justifyContent: "center", | ||
}} | ||
> | ||
<Text>Nothing to see here, yet.</Text> | ||
</View> | ||
} | ||
data={searchResults ? searchResults : chatList} | ||
ItemSeparatorComponent={Divider} | ||
renderItem={({ item }) => ( | ||
<NewChatItem item={item} openMessage={newMessage} /> | ||
)} | ||
keyExtractor={(item) => item.username} | ||
bouncesZoom | ||
bounces | ||
/> | ||
</View> | ||
); | ||
}; | ||
|
||
export default PostShareModal; |
Oops, something went wrong.