Add "View N comments" button below posts

This replaces the old comment button that was in the post action bar
This commit is contained in:
Nat 2021-03-02 09:58:39 -04:00
parent c4ba6e9075
commit 09424ac4eb
7 changed files with 38 additions and 18 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 986 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 814 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

View File

@ -12,6 +12,7 @@ const TEST_POSTS = [
id: 1, id: 1,
avatar: TEST_IMAGE, avatar: TEST_IMAGE,
username: "njms", username: "njms",
replies_count: 3,
favourited: false, favourited: false,
reblogged: false, reblogged: false,
content: "Also learning Claire de Lune feels a lot like reading the communist manifesto", content: "Also learning Claire de Lune feels a lot like reading the communist manifesto",
@ -26,6 +27,7 @@ const TEST_POSTS = [
username: "njms", username: "njms",
favourited: false, favourited: false,
reblogged: false, reblogged: false,
replies_count: 0,
content: "Also learning Claire de Lune feels a lot like reading the communist manifesto", content: "Also learning Claire de Lune feels a lot like reading the communist manifesto",
timestamp: 1596745156000, timestamp: 1596745156000,
media_attachments: [ media_attachments: [

View File

@ -62,10 +62,6 @@ const PostActionBarJsx = (props) => {
active: require("assets/eva-icons/post-actions/heart-active.png"), active: require("assets/eva-icons/post-actions/heart-active.png"),
inactive: require("assets/eva-icons/post-actions/heart-inactive.png") inactive: require("assets/eva-icons/post-actions/heart-inactive.png")
}, },
comment: {
active: require("assets/eva-icons/post-actions/comment-active.png"),
inactive: require("assets/eva-icons/post-actions/comment-inactive.png")
},
reblog: { reblog: {
active: require("assets/eva-icons/post-actions/reblog-active.png"), active: require("assets/eva-icons/post-actions/reblog-active.png"),
inactive: require("assets/eva-icons/post-actions/reblog-inactive.png") inactive: require("assets/eva-icons/post-actions/reblog-inactive.png")
@ -83,12 +79,6 @@ const PostActionBarJsx = (props) => {
state = { state } state = { state }
callback = { () => favouritedCallback(state, setState) } /> callback = { () => favouritedCallback(state, setState) } />
<PostActionJsx
field = "commenting"
pack = { icons.comment }
state = { state }
callback = { () => commentCallback(state, setState) } />
<PostActionJsx <PostActionJsx
field = "reblogged" field = "reblogged"
pack = { icons.reblog } pack = { icons.reblog }
@ -105,16 +95,17 @@ const PostActionBarJsx = (props) => {
) )
} }
const SCREEN_WIDTH = Dimensions.get("window").width;
const styles = { const styles = {
flexContainer: { flexContainer: {
display: "flex", display: "flex",
flexDirection: "row", flexDirection: "row",
padding: Dimensions.get("window").width / 40 padding: SCREEN_WIDTH / 40
}, },
icon: { icon: {
width: 30, width: 30,
height: 30, height: 30,
marginRight: Dimensions.get("window").width / 20 marginRight: SCREEN_WIDTH / 20
}, },
lastIcon: { lastIcon: {
marginLeft: "auto" marginLeft: "auto"

View File

@ -18,6 +18,14 @@ const TEST_IMAGE = "https://cache.desktopnexus.com/thumbseg/2255/2255124-bigthum
// This will be used in RawPostJsx // This will be used in RawPostJsx
const { SlideInMenu } = renderers; const { SlideInMenu } = renderers;
function pluralize(n, singular, plural) {
if (n < 2) {
return singular;
} else {
return plural;
}
}
function getAutoHeight(w1, h1, w2) { function getAutoHeight(w1, h1, w2) {
/* /*
Given the original dimensions and the new width, calculate what would Given the original dimensions and the new width, calculate what would
@ -44,7 +52,6 @@ function timeToAge(time1, time2) {
*/ */
const between = (n, lower, upper) => n >= lower && n < upper; const between = (n, lower, upper) => n >= lower && n < upper;
const pluralize = (n, singular, plural) => n < 2 ? singular : plural;
const diff = time1 - time2; const diff = time1 - time2;
@ -69,6 +76,17 @@ function timeToAge(time1, time2) {
} }
export const RawPostJsx = (props) => { export const RawPostJsx = (props) => {
const repliesCount = props.data.replies_count;
let commentsText;
if (repliesCount == 0) {
commentsText = "View comments";
} else {
commentsText = "View "
+ repliesCount
+ pluralize(repliesCount, " comment", " comments");
}
return ( return (
<View> <View>
<View style = { styles.postHeader }> <View style = { styles.postHeader }>
@ -107,6 +125,12 @@ export const RawPostJsx = (props) => {
<Text> <Text>
<strong>{ props.data.username }</strong>&nbsp;{ props.data.content } <strong>{ props.data.username }</strong>&nbsp;{ props.data.content }
</Text> </Text>
<TouchableWithoutFeedback>
<View>
<Text style = { styles.comments }>{ commentsText }</Text>
</View>
</TouchableWithoutFeedback>
<Text style = { styles.captionDate }> <Text style = { styles.captionDate }>
{ timeToAge((new Date()).getTime(), props.data.timestamp) } { timeToAge((new Date()).getTime(), props.data.timestamp) }
</Text> </Text>
@ -237,10 +261,13 @@ const styles = {
caption: { caption: {
padding: SCREEN_WIDTH / 24, padding: SCREEN_WIDTH / 24,
}, },
comments: {
paddingTop: SCREEN_WIDTH / 50,
color: "#666",
},
captionDate: { captionDate: {
fontSize: "0.8em", fontSize: "0.8em",
color: "#666", color: "#666",
paddingTop: 10
} }
}; };