diff --git a/Views/Feed.js b/Views/Feed.js index 056eb0d..5ae7a3c 100644 --- a/Views/Feed.js +++ b/Views/Feed.js @@ -1,10 +1,7 @@ -import { StatusBar } from 'expo-status-bar'; 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 Post from './../components/Post.js'; -import NewPost from "./../components/NewPost.js"; -import { useSnapshot } from 'valtio'; import GlobalState from '../contexts/GlobalState.js'; import AsyncStorage from '@react-native-async-storage/async-storage'; diff --git a/Views/Menu.js b/Views/Menu.js index 7bf98d4..c9ab803 100644 --- a/Views/Menu.js +++ b/Views/Menu.js @@ -4,6 +4,8 @@ import { Text, List, RadioButton } from "react-native-paper"; import { SafeAreaView } from "react-native-safe-area-context"; import i18n from "../i18nMessages.js"; import Moment from 'moment'; +import 'moment/min/locales'; +Moment.locale(i18n.locale); let MenuView = ()=>{ diff --git a/Views/NewPost.js b/Views/NewPost.js index f5d276f..73d9143 100644 --- a/Views/NewPost.js +++ b/Views/NewPost.js @@ -1,14 +1,129 @@ -import { View } from "react-native"; -import NewPost from "../components/NewPost"; +import React, { useState } from 'react'; +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 ( - - - - - + + + + {i18n.t("message.statusUpdate")}: + + + + + + + + + {photo && ( + + Uploading... + + + )} + { + extraContent.length > 0 && ( + + ) + } + + ) } diff --git a/components/Comment.js b/components/Comment.js index 9422fc1..30bf8ad 100644 --- a/components/Comment.js +++ b/components/Comment.js @@ -5,7 +5,10 @@ import API from './../API.js'; import UserName from './UserName.js'; import { useSnapshot } from 'valtio'; 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 }) => { const gState = useSnapshot(GlobalState); @@ -30,7 +33,7 @@ let Comment = ({ comment, postid }) => { - + {Moment(comment.createdAt).fromNow()} @@ -42,6 +45,7 @@ let Comment = ({ comment, postid }) => { {comment.content} + ); diff --git a/components/ProfileCardHorizontal.js b/components/ProfileCardHorizontal.js index 9fe67d7..317d10b 100644 --- a/components/ProfileCardHorizontal.js +++ b/components/ProfileCardHorizontal.js @@ -62,20 +62,29 @@ let ProfileCardHorizontal = ({ profileid, hideIcon, profileObj }) => { - - + - + <Text> {profile.profile && profile.profile.firstName} {profile.profile && profile.profile.lastName} </Text> - {profile.profile?.description} - - - + {profile.profile?.description} + + + + diff --git a/components/basics/FollowButton.js b/components/basics/FollowButton.js index 96e111e..8b3d57e 100644 --- a/components/basics/FollowButton.js +++ b/components/basics/FollowButton.js @@ -44,7 +44,7 @@ const unfollowProfile = async (profileid, me, setFollowing, setPending) => { } -let FollowButton = ({ profile }) => { +let FollowButton = ({ profile, iconSize }) => { const viewer = useSnapshot(GlobalState).me; const [following, setFollowing] = useState(false); const [pending, setPending] = useState(false); @@ -70,9 +70,11 @@ let FollowButton = ({ profile }) => { { profile._id && profile._id !== viewer._id ? : + onPress={toggleFollowThisProfile} + size={iconSize || 25} + iconColor={following ? "#c44d56" : "#93faa5"} + /> : <> } diff --git a/i18nMessages.js b/i18nMessages.js index 157ee39..9349c7d 100644 --- a/i18nMessages.js +++ b/i18nMessages.js @@ -1,7 +1,7 @@ //import { getLocales } from 'expo-localization'; import { I18n } from 'i18n-js'; -import Moment from 'moment'; -import 'moment/min/locales.min'; +import moment from 'moment' +import 'moment/min/locales' const messages = { en: { @@ -129,6 +129,6 @@ const i18n = new I18n(messages); // Set the locale once at the beginning of your app. i18n.locale = 'es';//getLocales()[0].languageCode; -Moment.updateLocale(i18n.locale); +moment.locale(i18n.locale); export default i18n; \ No newline at end of file