Skip to content

Commit

Permalink
problem in including inputbox
Browse files Browse the repository at this point in the history
  • Loading branch information
devanshusingla committed Jul 24, 2020
1 parent 1a0e2ae commit 7dc86ee
Show file tree
Hide file tree
Showing 10 changed files with 328 additions and 119 deletions.
23 changes: 20 additions & 3 deletions App.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
import { StatusBar } from "expo-status-bar";
import React from "react";
import { StyleSheet, Text, View } from "react-native";
import React, { useState } from "react";
import { StyleSheet, Text, View, Button } from "react-native";
import CommentBox from "./ui/Comments";
import comments from "./ui/Comments/CommentExample";

export default function App() {
const [isCommentOpen, setIsCommentOpen] = useState(true);
return (
<View style={styles.container}>
<Text>Open up App.tsx to start working on your app!</Text>
<CommentBox isVisible={true} comments={comments} />
<Button
title="Open Comments"
onPress={() => {
setIsCommentOpen(true);
}}
></Button>
{isCommentOpen ? (
<CommentBox
isVisible={true}
comments={comments}
onBack={() => {
setIsCommentOpen(false);
}}
/>
) : (
<></>
)}
<StatusBar style="auto" />
</View>
);
Expand Down
16 changes: 0 additions & 16 deletions ui/Comments/Comment.tsx

This file was deleted.

66 changes: 66 additions & 0 deletions ui/Comments/CommentBlock.tsx
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;
20 changes: 20 additions & 0 deletions ui/Comments/CommentExample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,26 @@ const comments: Array<IComment> = [
[]
),
]),
comment("dosa0", 10, "next sem to be online", 0, []),
comment("dosa1", 11, "next sem to be online", 0, []),
comment("dosa2", 12, "next sem to be online", 0, []),
comment("dosa3", 13, "next sem to be online", 0, []),
comment("dosa4", 14, "next sem to be online", 0, []),
comment("dosa5", 15, "next sem to be online", 0, []),
comment("dosa6", 16, "next sem to be online", 0, []),
comment("dosa7", 17, "next sem to be online", 0, []),
comment("dosa8", 18, "next sem to be online", 0, []),
comment("dosa9", 19, "next sem to be online", 0, []),
comment("dosa10", 20, "next sem to be online", 0, []),
comment("dosa11", 21, "next sem to be online", 0, []),
comment("dosa12", 22, "next sem to be online", 0, []),
comment("dosa13", 23, "next sem to be online", 0, []),
comment("dosa14", 24, "next sem to be online", 0, []),
comment("dosa15", 25, "next sem to be online", 0, []),
comment("dosa16", 26, "next sem to be online", 0, []),
comment("dosa17", 27, "next sem to be online", 0, []),
comment("dosa18", 28, "next sem to be online", 0, []),
comment("dosa19", 29, "next sem to be online", 0, []),
];

export default comments;
32 changes: 8 additions & 24 deletions ui/Comments/CommentList.tsx
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;
63 changes: 63 additions & 0 deletions ui/Comments/MainComment.tsx
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;
94 changes: 43 additions & 51 deletions ui/Comments/MaximisedComment.tsx
Original file line number Diff line number Diff line change
@@ -1,78 +1,70 @@
import React from "react";
import { View, Text, StyleSheet } from "react-native";
import { Card } from "react-native-elements";
import React, { useState } from "react";
import { View, Text, StyleSheet, TouchableOpacity } from "react-native";

import moment from "moment";

import CommentList from "./CommentList";
import Title from "./Title";
import CommentBlock from "./CommentBlock";
import SideComment from "./SideComment";

type Props = {
comment: IComment;
showReplies: boolean;
};

type RepliesProps = {
replies: Array<IComment>;
};

const Replies = (props: RepliesProps) => {
return (
<View style={styles.commentList}>
<CommentList comments={props.replies} />
</View>
);
};

const MaximisedComment = (props: Props) => {
const commentCreationTime = () => {
let creationTime = moment(props.comment.created_at);
let currentTime = moment();
let [selfExpanded, setSelfExpanded] = useState(false);

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 onSelectedHandler = () => {
setSelfExpanded(true);
};

return (
<View style={styles.outer}>
<Card
title={<Title name={props.comment.user.name} />}
dividerStyle={{ marginBottom: 0 }}
containerStyle={styles.container}
>
<View style={styles.content}>
<Text>{props.comment.content}</Text>
<>
<TouchableOpacity onPress={onSelectedHandler}>
<View style={styles.outer}>
<SideComment comment={props.comment} />
<Replies replies={props.comment.replies} />
</View>
</Card>
<View
style={{
paddingLeft: "5%",
flexDirection: "row",
justifyContent: "space-between",
}}
>
<Text style={{ fontWeight: "bold" }}>Reply</Text>
<Text style={{ color: "grey" }}>{commentCreationTime()}</Text>
</View>
<View style={styles.commentList}>
<CommentList comments={props.comment.replies} />
</View>
</View>
</TouchableOpacity>
{selfExpanded ? (
<CommentBlock
isVisible={true}
comment={props.comment}
onBack={() => {
setSelfExpanded(false);
}}
/>
) : (
<></>
)}
</>
);
};

const styles = StyleSheet.create({
outerWithoutReplies: {
width: "100%",
paddingLeft: "2%",
marginTop: 10,
},
outer: {
width: "100%",
paddingLeft: "5%",
marginTop: 10,
},
container: {
padding: 0,
margin: "0.5%",
borderBottomLeftRadius: 15,
backgroundColor: "#f5f5f5",
},
content: {
marginBottom: 2,
marginLeft: 16,
},
commentList: {
width: "100%",
paddingLeft: "5%",
Expand Down
Loading

0 comments on commit 7dc86ee

Please sign in to comment.