Skip to content

Commit

Permalink
Merge branch 'feature/sharing_post' into 'develop'
Browse files Browse the repository at this point in the history
Feature/sharing post

See merge request snsmobile/UserHybrid!25
  • Loading branch information
Le Linh committed Apr 27, 2018
2 parents 0a18da0 + deb5629 commit ac90cdc
Show file tree
Hide file tree
Showing 13 changed files with 341 additions and 167 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"redux-form": "7.3.0",
"redux-thunk": "2.2.0",
"rxjs": "^5.5.8",
"subscriptions-transport-ws": "^0.9.7",
"subscriptions-transport-ws": "^0.9.8",
"validator": "9.4.1"
}
}
21 changes: 18 additions & 3 deletions src/components/FeedCard/FeedCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { colors } from "../../constants";
import FeedCardHeader from "./FeedCardHeader";
import FeedCardBottom from "./FeedCardBottom";
import FeedCardPhotos from "../Photos/FeedCardPhotos";
import SharedPost from "../Post/SharedPost";

const styles = StyleSheet.create({
container: {
Expand Down Expand Up @@ -36,6 +37,8 @@ const styles = StyleSheet.create({
}
});

const emptyFn = () => {};

@connect(
({ common, nav }) => ({
nav: nav,
Expand All @@ -44,6 +47,10 @@ const styles = StyleSheet.create({
dispatch => ({ dispatch })
)
class FeedCard extends Component {
static defaultProps = {
onToggleSharingModal: emptyFn,
}

_handlePressContent = () => {
const { _id, totalComments } = this.props;
this.props.dispatch(
Expand All @@ -59,7 +66,8 @@ class FeedCard extends Component {

render(){
const { _id, messagePlainText, author, isLiked, totalComments,
totalLikes, createdAt, user, building, photos } = this.props;
totalLikes, createdAt, user, building,
photos, sharing, onToggleSharingModal } = this.props;

const displayText = messagePlainText.length > 300 ? `${messagePlainText.substring(0, 300)}...` : messagePlainText;
return (
Expand All @@ -74,10 +82,17 @@ class FeedCard extends Component {
<CardItem cardBody style={styles.contentContainer}>
<TouchableOpacity style={styles.touchableContent} onPress={this._handlePressContent}>
<Text style={styles.textContent}>{displayText}</Text>
<FeedCardPhotos photos={photos}/>
<FeedCardPhotos photos={photos} height={300}/>
{ sharing ? <SharedPost postID={sharing._id}/> : null }
</TouchableOpacity>
</CardItem>
<FeedCardBottom postID={_id} isLiked={isLiked} totalComments={totalComments} totalLikes={totalLikes} />
<FeedCardBottom
postID={_id}
isLiked={isLiked}
totalComments={totalComments}
totalLikes={totalLikes}
onToggleSharingModal={onToggleSharingModal}
handlePressComment={this._handlePressContent} />
</Card>
);
}
Expand Down
33 changes: 10 additions & 23 deletions src/components/FeedCard/FeedCardBottom.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { CardItem, Text } from "native-base";
import { StyleSheet, TouchableOpacity } from "react-native";
import MaterialCommunityIcons from "react-native-vector-icons/MaterialCommunityIcons";
import { graphql, compose } from "react-apollo";
import { NavigationActions } from "react-navigation";
import { connect } from "react-redux";

import { colors } from "../../constants";
import LIKE_POST_MUTATION from "../../graphql/mutations/likePost";
Expand All @@ -31,14 +29,9 @@ const styles = StyleSheet.create({

const ICON_SIZE = 20;

const emptyFn = () => {};

@compose(
connect(
({ common, nav }) => ({
nav: nav,
orientation: common.orientation
}),
dispatch => ({ dispatch })
),
graphql(LIKE_POST_MUTATION, { name: "unlikePostMutation"}),
graphql(UNLIKE_POST_MUTATION, { name: "likePostMutation" }),
)
Expand All @@ -52,6 +45,11 @@ class FeedCardBottom extends Component{
};
}

static defaultProps = {
handlePressComment: emptyFn,
onToggleSharingModal: emptyFn,
}

_handleLike = async () => {
const { isLiked, totalLikes } = this.state;
const { postID, likePostMutation, unlikePostMutation } = this.props;
Expand Down Expand Up @@ -82,19 +80,8 @@ class FeedCardBottom extends Component{
}
}

_handlePressComment = () => {
const { postID, totalComments } = this.props;
this.props.dispatch(NavigationActions.navigate({
routeName: "PostDetail",
params: {
postID: postID,
limit: totalComments,
}
}));
}

render(){
const { totalComments } = this.props;
const { totalComments, handlePressComment, onToggleSharingModal, postID } = this.props;
const { isLiked, totalLikes } = this.state;
return (
<CardItem style={styles.container}>
Expand All @@ -103,12 +90,12 @@ class FeedCardBottom extends Component{
<Text style={styles.buttonText}> {totalLikes} </Text>
</TouchableOpacity>

<TouchableOpacity style={styles.button} onPress={this._handlePressComment}>
<TouchableOpacity style={styles.button} onPress={() => handlePressComment()}>
<MaterialCommunityIcons name="comment-processing-outline" size={ICON_SIZE} color={colors.LIGHT_GRAY}/>
<Text style={styles.buttonText}> {totalComments} </Text>
</TouchableOpacity>

<TouchableOpacity style={styles.button}>
<TouchableOpacity style={styles.button} onPress={() => onToggleSharingModal(true, postID)}>
<MaterialCommunityIcons name="share" size={ICON_SIZE} color={colors.LIGHT_GRAY}/>
</TouchableOpacity>
</CardItem>
Expand Down
34 changes: 14 additions & 20 deletions src/components/Photos/FeedCardPhotos.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
import React, { Component } from "react";
import { View, Text, StyleSheet, Image } from "react-native";
import { View, Text, Image } from "react-native";

import { colors } from "../../constants";

const styles = StyleSheet.create({
singleImageContainer: {
width: "100%",
height: 300,
margin: 2,
},
multiImagesContainer: {
height: 300,
width:"100%",
},
});

class FeedCardPhotos extends Component{
render(){
const { photos } = this.props;
const { photos, height } = this.props;

if (!photos || !photos.length) { return null; }

if (photos.length === 1) {
return <Image source={{uri: JSON.parse(photos[0]).URL}} style={styles.singleImageContainer}/>;
return <Image source={{uri: JSON.parse(photos[0]).URL}} style={{height}}/>;
}

if (photos.length === 2) {
return (
<View style={styles.multiImagesContainer}>
<Image source={{uri: JSON.parse(photos[0]).URL}} style={{width: "100%", height: "60%", margin: 2}}/>
<View style={{margin: 2, height}}>
<Image
source={{uri: JSON.parse(photos[0]).URL}}
style={{width: "100%", height: "60%", margin: 2}}/>
<View style={{width: "100%", height: "40%", margin: 2, backgroundColor: colors.LIGHT_GRAY, justifyContent:"center", alignItems:"center"}}>
<Text style={{color: colors.WHITE, fontSize: 20}}> +1 </Text>
</View>
Expand All @@ -37,10 +27,14 @@ class FeedCardPhotos extends Component{
}

return (
<View style={styles.multiImagesContainer}>
<Image source={{uri: JSON.parse(photos[0]).URL}} style={{width: "100%", height: "60%", margin: 2}}/>
<View style={{margin: 2, height}}>
<Image
source={{uri: JSON.parse(photos[0]).URL}}
style={{width: "100%", height: "60%", margin: 2}}/>
<View style={{width: "100%", height: "40%", margin: 2, flexDirection:"row"}}>
<Image source={{uri: JSON.parse(photos[1]).URL}} style={{width: "60%", height: "100%"}}/>
<Image
source={{uri: JSON.parse(photos[1]).URL}}
style={{width: "60%", height: "100%"}}/>
<View style={{width: "40%", height: "100%", backgroundColor: colors.LIGHT_GRAY, justifyContent:"center", alignItems:"center"}}>
<Text style={{color: colors.WHITE, fontSize: 20}}> +{photos.length - 2} </Text>
</View>
Expand Down
103 changes: 0 additions & 103 deletions src/components/Post/PostFeedBack.js

This file was deleted.

Loading

0 comments on commit ac90cdc

Please sign in to comment.