-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a0e2ae
commit 7dc86ee
Showing
10 changed files
with
328 additions
and
119 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 was deleted.
Oops, something went wrong.
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,66 @@ | ||
import React, { useState } from "react"; | ||
import { | ||
Text, | ||
View, | ||
FlatList, | ||
TouchableOpacity, | ||
KeyboardAvoidingView, | ||
} from "react-native"; | ||
import { Overlay, Icon, ListItem, Input } from "react-native-elements"; | ||
|
||
import MaximisedComment from "./MaximisedComment"; | ||
import MainComment from "./MainComment"; | ||
|
||
type Props = { | ||
isVisible: boolean; | ||
onBack: () => void; | ||
comment: IComment; | ||
}; | ||
|
||
const CommentBox = (props: Props) => { | ||
const onBackHandler = () => { | ||
props.onBack(); | ||
}; | ||
|
||
return ( | ||
<Overlay isVisible={true} fullScreen={true}> | ||
<View style={{ height: "100%" }}> | ||
<TouchableOpacity onPress={onBackHandler}> | ||
<ListItem | ||
leftIcon={{ name: "arrow-back" }} | ||
title="Back" | ||
containerStyle={{ | ||
padding: 3, | ||
marginTop: 0, | ||
marginBottom: 0, | ||
}} | ||
/> | ||
</TouchableOpacity> | ||
<MainComment comment={props.comment} /> | ||
<View style={{ paddingLeft: "5%" }}> | ||
<FlatList | ||
style={{ | ||
marginBottom: 30, | ||
height: "76.5%", | ||
}} | ||
data={props.comment.replies} | ||
keyExtractor={(comment) => comment.pk.toString()} | ||
renderItem={({ item }) => ( | ||
<MaximisedComment comment={item} showReplies={true} /> | ||
)} | ||
/> | ||
</View> | ||
<KeyboardAvoidingView | ||
behavior="position" | ||
style={{ flex: 1, justifyContent: "flex-end" }} | ||
> | ||
<View> | ||
<Input placeholder="Write a comment..." /> | ||
</View> | ||
</KeyboardAvoidingView> | ||
</View> | ||
</Overlay> | ||
); | ||
}; | ||
|
||
export default CommentBox; |
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 |
---|---|---|
@@ -1,38 +1,22 @@ | ||
import React, { useState } from "react"; | ||
import { View, Text, StyleSheet, TouchableOpacity } from "react-native"; | ||
import Comment from "./Comment"; | ||
import MinimisedComment from "./MinimisedComment"; | ||
|
||
type Props = { | ||
comments: Array<IComment>; | ||
}; | ||
|
||
const CommentList = (props: Props) => { | ||
let [isHidden, setIsHidden] = useState(true); | ||
const maxHiddenChats = 3; | ||
|
||
if (!props.comments) return <> </>; | ||
if (isHidden) | ||
return ( | ||
<TouchableOpacity | ||
onPress={() => { | ||
setIsHidden(false); | ||
}} | ||
> | ||
<View> | ||
{props.comments.slice(0, maxHiddenChats).map((comment: IComment) => ( | ||
<Comment isHidden={true} comment={comment} key={comment.pk} /> | ||
))} | ||
</View> | ||
</TouchableOpacity> | ||
); | ||
else | ||
return ( | ||
<View> | ||
{props.comments.map((comment: IComment) => ( | ||
<Comment isHidden={false} comment={comment} key={comment.pk} /> | ||
))} | ||
</View> | ||
); | ||
return ( | ||
<View> | ||
{props.comments.slice(0, maxHiddenChats).map((comment: IComment) => ( | ||
<MinimisedComment comment={comment} key={comment.pk} /> | ||
))} | ||
</View> | ||
); | ||
}; | ||
|
||
export default CommentList; |
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,63 @@ | ||
import React from "react"; | ||
import { Card } from "react-native-elements"; | ||
import { StyleSheet, View, Text } from "react-native"; | ||
import Title from "./Title"; | ||
|
||
import moment from "moment"; | ||
|
||
type CommentProps = { | ||
comment: IComment; | ||
}; | ||
|
||
const commentCreationTime = (created_at: string) => { | ||
let creationTime = moment(created_at); | ||
let currentTime = moment(); | ||
|
||
if (currentTime.diff(creationTime, "seconds") < 60) { | ||
return "now"; | ||
} else if (currentTime.diff(creationTime, "minutes") < 60) | ||
return currentTime.diff(creationTime, "minutes") + " min"; | ||
else if (currentTime.diff(creationTime, "hours") < 24) | ||
return currentTime.diff(creationTime, "hours") + " hrs"; | ||
else if (currentTime.diff(creationTime, "months") === 0) | ||
return currentTime.diff(creationTime, "days") + " days"; | ||
else if (currentTime.diff(creationTime, "years") === 0) | ||
return currentTime.diff(creationTime, "months") + " months"; | ||
else return currentTime.diff(creationTime, "years") + " yrs"; | ||
}; | ||
|
||
const MainComment = (props: CommentProps) => { | ||
return ( | ||
<Card | ||
title={ | ||
<Title | ||
name={props.comment.user.name} | ||
avatarSize={40} | ||
titleStyle={{ fontSize: 20, paddingTop: 5 }} | ||
/> | ||
} | ||
containerStyle={styles.container} | ||
> | ||
<View style={styles.content}> | ||
<Text style={{ marginTop: 5 }}>{props.comment.content}</Text> | ||
</View> | ||
</Card> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
padding: "1%", | ||
margin: "0.5%", | ||
marginTop: 10, | ||
marginBottom: "3%", | ||
borderBottomLeftRadius: 15, | ||
backgroundColor: "#f5f5f5", | ||
}, | ||
content: { | ||
marginBottom: 2, | ||
marginLeft: 16, | ||
}, | ||
}); | ||
|
||
export default MainComment; |
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
Oops, something went wrong.