New post view + fix moment location

This commit is contained in:
Adolfo Reyna
2022-12-22 23:06:21 -05:00
parent 3d50977520
commit 1c0dbbbe84
7 changed files with 156 additions and 27 deletions

View File

@@ -1,10 +1,7 @@
import { StatusBar } from 'expo-status-bar';
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { View, ActivityIndicator, StyleSheet, SafeAreaView, FlatList } from 'react-native'; import { StyleSheet, SafeAreaView, FlatList } from 'react-native';
import API from './../API.js'; import API from './../API.js';
import Post from './../components/Post.js'; import Post from './../components/Post.js';
import NewPost from "./../components/NewPost.js";
import { useSnapshot } from 'valtio';
import GlobalState from '../contexts/GlobalState.js'; import GlobalState from '../contexts/GlobalState.js';
import AsyncStorage from '@react-native-async-storage/async-storage'; import AsyncStorage from '@react-native-async-storage/async-storage';

View File

@@ -4,6 +4,8 @@ import { Text, List, RadioButton } from "react-native-paper";
import { SafeAreaView } from "react-native-safe-area-context"; import { SafeAreaView } from "react-native-safe-area-context";
import i18n from "../i18nMessages.js"; import i18n from "../i18nMessages.js";
import Moment from 'moment'; import Moment from 'moment';
import 'moment/min/locales';
Moment.locale(i18n.locale);
let MenuView = ()=>{ let MenuView = ()=>{

View File

@@ -1,14 +1,129 @@
import { View } from "react-native"; import React, { useState } from 'react';
import NewPost from "../components/NewPost"; import { View, TextInput, Image } from "react-native";
import { Text, Button, Divider } from "react-native-paper";
import { SafeAreaView } from "react-native-safe-area-context";
import API from './../API.js';
import { useNavigation } from '@react-navigation/native';
import * as ImagePicker from 'expo-image-picker';
import i18n from "../i18nMessages";
import Media from '../components/Media';
let NewPostView = ()=>{ let NewPostView = ({writeTo})=>{
let [postContent, setPostContent] = useState('');
let [extraContent, setExtraContent] = useState([]);
const [photo, setPhoto] = React.useState(null);
const navigation = useNavigation();
const pickImage = async () => {
// No permissions request is necessary for launching the image library
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Images,
//allowsEditing: true,
//aspect: [4, 3],
//quality: 1,
allowsMultipleSelection: true,
});
if (!result.cancelled) {
setPhoto(result);
let newPhotoURL = await handleUploadPhoto(result);
let newExtraContent = ["@image:" + newPhotoURL].concat(extraContent);
setExtraContent(newExtraContent);
console.log(newExtraContent.join(" "));
setPhoto(null);
}
};
const handleUploadPhoto = async (photo) => {
if (!photo) return;
const uri =
Platform.OS === "android"
? photo.uri
: photo.uri.replace("file://", "");
const filename = photo.uri.split("/").pop();
const match = /\.(\w+)$/.exec(filename);
const ext = match?.[1];
const type = match ? `image/${match[1]}` : `image`;
const formData = new FormData();
formData.append("banner", {
uri,
name: `image.${ext}`,
type,
});
try {
let uploadedFile = await fetch("https://social.emmint.com/upload.php", {
method: "POST",
body: formData,
headers: { "Content-Type": "multipart/form-data" }
})
.then((res) => res.json())
.then((data) => {
console.log(data);
return data.fileName;
})
.catch((err) => console.error(err));
return uploadedFile;
} catch (err) {
console.log(err);
alert("Something went wrong");
}
};
const handleNewPostButton = async () => {
//setPostContent('');
API.newPost(postContent + " " + extraContent.join(" ")).then((newPost) => {
setPostContent('');
setExtraContent([]);
navigation.goBack();
//if (newPostCB) newPostCB(newPost);
});
}
return ( return (
<View> <SafeAreaView>
<NewPost > <View style={{padding: 10}}>
<View style={{flexDirection:"row", marginBottom:10, justifyContent:"space-around"}}>
</NewPost> <Text style={{fontSize: 25}}>{i18n.t("message.statusUpdate")}:</Text>
<Button icon="send" mode="outlined" onPress={handleNewPostButton}>
{i18n.t("message.post")}
</Button>
</View> </View>
<Divider bold={true}/>
<TextInput
value={postContent}
onChangeText={setPostContent}
multiline={true}
numberOfLines={8}
style={{
backgroundColor: "rgba(0,0,0,0)",
textAlignVertical: "center",
textAlign: "center",
fontSize: 20,
}}
autoFocus={true}
/>
<Divider bold={true} />
<View style={{flexDirection:"row", marginTop:10, justifyContent:"space-around"}}>
<Button icon="add-a-photo" mode="outlined" onPress={pickImage}>
Add Photos
</Button>
</View>
{photo && (
<View>
<Text>Uploading...</Text>
<Image
source={{ uri: photo.uri }}
style={{ width: 100, height: 100 }}
/>
</View>
)}
{
extraContent.length > 0 && (
<Media content={extraContent.join(" ")} />
)
}
</View>
</SafeAreaView>
) )
} }

View File

@@ -5,7 +5,10 @@ import API from './../API.js';
import UserName from './UserName.js'; import UserName from './UserName.js';
import { useSnapshot } from 'valtio'; import { useSnapshot } from 'valtio';
import GlobalState from '../contexts/GlobalState.js'; import GlobalState from '../contexts/GlobalState.js';
import Moment from 'moment';
import i18n from "../i18nMessages.js";
import 'moment/min/locales';
Moment.locale(i18n.locale);
let Comment = ({ comment, postid }) => { let Comment = ({ comment, postid }) => {
const gState = useSnapshot(GlobalState); const gState = useSnapshot(GlobalState);
@@ -30,7 +33,7 @@ let Comment = ({ comment, postid }) => {
<View style={{flex:8}}> <View style={{flex:8}}>
<Text style={styles.userName}> <Text style={styles.userName}>
<UserName profileid={comment.profileid} key={comment.profileid} /> <UserName profileid={comment.profileid} key={comment.profileid} />
<Text style={{fontSize: 12, fontWeight: "normal"}}> {Moment(comment.createdAt).fromNow()}</Text>
</Text> </Text>
</View> </View>
<View style={{flex:2}}> <View style={{flex:2}}>
@@ -42,6 +45,7 @@ let Comment = ({ comment, postid }) => {
</View> </View>
</View> </View>
<Text style={{fontSize: 16}}>{comment.content}</Text> <Text style={{fontSize: 16}}>{comment.content}</Text>
</Card.Content> </Card.Content>
</Card> </Card>
); );

View File

@@ -62,8 +62,7 @@ let ProfileCardHorizontal = ({ profileid, hideIcon, profileObj }) => {
<Card.Content> <Card.Content>
<View style={{ flexDirection: "row" }}> <View style={{ flexDirection: "row" }}>
<View onPress={onPress}> <View onPress={onPress}>
<Avatar.Image size={100} source={{ uri: photoUrl }} /> <Avatar.Image size={75} source={{ uri: photoUrl }} />
</View> </View>
<View style={{ paddingLeft: 10 }}> <View style={{ paddingLeft: 10 }}>
<Title onPress={onPress} numberOfLines={1}> <Title onPress={onPress} numberOfLines={1}>
@@ -73,9 +72,19 @@ let ProfileCardHorizontal = ({ profileid, hideIcon, profileObj }) => {
</Title> </Title>
<Paragraph lineBreakMode="clip" numberOfLines={3} style={{ width: 250 }}>{profile.profile?.description}</Paragraph> <Paragraph lineBreakMode="clip" numberOfLines={3} style={{ width: 250 }}>{profile.profile?.description}</Paragraph>
</View> </View>
<View>
<FollowButton profile={profile._id ? profile : {_id: profileid}} />
</View> </View>
<View style={{
position: "absolute",
top: 0,
right: 0,
width: 50,
height: 50,
backgroundColor:"#ddd",
borderRadius: 25,
opacity: 0.7
}}>
<FollowButton profile={profile._id ? profile : { _id: profileid }} />
</View> </View>
</Card.Content> </Card.Content>
</Card> </Card>

View File

@@ -44,7 +44,7 @@ const unfollowProfile = async (profileid, me, setFollowing, setPending) => {
} }
let FollowButton = ({ profile }) => { let FollowButton = ({ profile, iconSize }) => {
const viewer = useSnapshot(GlobalState).me; const viewer = useSnapshot(GlobalState).me;
const [following, setFollowing] = useState(false); const [following, setFollowing] = useState(false);
const [pending, setPending] = useState(false); const [pending, setPending] = useState(false);
@@ -70,9 +70,11 @@ let FollowButton = ({ profile }) => {
{ {
profile._id && profile._id !== viewer._id ? profile._id && profile._id !== viewer._id ?
<IconButton <IconButton
mode='outlined'
icon={following ? 'person-remove' : 'person-add'} icon={following ? 'person-remove' : 'person-add'}
onPress={toggleFollowThisProfile} /> : onPress={toggleFollowThisProfile}
size={iconSize || 25}
iconColor={following ? "#c44d56" : "#93faa5"}
/> :
<></> <></>
} }
</> </>

View File

@@ -1,7 +1,7 @@
//import { getLocales } from 'expo-localization'; //import { getLocales } from 'expo-localization';
import { I18n } from 'i18n-js'; import { I18n } from 'i18n-js';
import Moment from 'moment'; import moment from 'moment'
import 'moment/min/locales.min'; import 'moment/min/locales'
const messages = { const messages = {
en: { en: {
@@ -129,6 +129,6 @@ const i18n = new I18n(messages);
// Set the locale once at the beginning of your app. // Set the locale once at the beginning of your app.
i18n.locale = 'es';//getLocales()[0].languageCode; i18n.locale = 'es';//getLocales()[0].languageCode;
Moment.updateLocale(i18n.locale); moment.locale(i18n.locale);
export default i18n; export default i18n;