From 93b84ada33e2bc978eb4ddfdc3e7884bbe74a000 Mon Sep 17 00:00:00 2001 From: Adolfo Reyna Date: Tue, 24 Jan 2023 22:42:22 -0500 Subject: [PATCH] Adding change of profiles and Profile on tab bar --- App.js | 17 ++++++-- Views/Menu.js | 99 +++++++++++++++++++++++++++++++----------- Views/NewPost.js | 2 +- Views/SelectProfile.js | 70 +++++++++++++++++++++++++++++ 4 files changed, 158 insertions(+), 30 deletions(-) create mode 100644 Views/SelectProfile.js diff --git a/App.js b/App.js index f4f9618..65efaad 100644 --- a/App.js +++ b/App.js @@ -207,15 +207,20 @@ const MainNavigation = () => { }} /> ( - + ), header: () => { <> }, }} + listeners={({ navigation, route }) => ({ + tabPress: e => { + navigation.navigate('MyProfile', {profileid: viewer._id}); + }, + })} /> {/* + { +let MenuView = ({ navigation }) => { const [value, setValue] = React.useState('es'); + const [myProfiles, setMyProfiles] = React.useState([]); + const gState = useSnapshot(GlobalState); + const viewer = gState.me; - let changeLang = (locale) =>{ + React.useEffect(() => { + let subscribed = true; + let getData = async () => { + const r = await API.getMyProfiles(); + if (!subscribed) return; + setMyProfiles(r.profiles); + } + getData(); + return () => { + subscribed = false; + } + }, []); + + let changeLang = (locale) => { i18n.locale = locale; Moment.locale(locale); setValue(locale); } - + const profileLists = myProfiles.map((profile) => { + const DefaultPhoto = "https://social.emmint.com/uploads/e6f9be6d665dc43417701bf16a90122c.png"; + let photoUrl = profile.profile?.photo ? 'https://social.emmint.com/' + profile.profile.photo : DefaultPhoto; + let icon = profile._id ? (!profile.isGroup ? "person-outline" : "group") : ''; + icon = icon === "person-outline" && profile.subscription && profile.subscription > (new Date() - 0) ? "assignment-ind" : icon; + icon = icon === "group" && profile.isCourse ? "subscriptions" : icon; + icon = icon === "group" && profile.isPrivate ? "screen-lock-portrait" : icon; + return <> + { + await API.changeProfile(profile._id); + GlobalState.me = await API.getMe(); + }} + left={props => } + titleStyle={{fontWeight:"bold"}} + descriptionNumberOfLines={3} + /> + + }) + return ( - - + - - {navigation.navigate("ProfileSettings")}} left={props => } /> - } /> - {navigation.navigate("Logout")}} left={props => } /> - - - {navigation.navigate("Invite")}} left={props => } /> - } /> - - - Language: - changeLang(newValue)} value={value}> - - - - + + } + + > + {profileLists} + + + { navigation.navigate("ProfileSettings") }} left={props => } /> + } /> + { navigation.navigate("Logout") }} left={props => } /> + + + { navigation.navigate("Invite") }} left={props => } /> + } /> + + + App Language: + changeLang(newValue)} value={value}> + + + + - + ) } diff --git a/Views/NewPost.js b/Views/NewPost.js index b809b1b..2fe4ccb 100644 --- a/Views/NewPost.js +++ b/Views/NewPost.js @@ -96,7 +96,7 @@ let NewPostView = (props) => { API.newPost(postContent + " " + extraContent.join(" "), props.route.params?.toProfile).then((newPost) => { setPostContent(''); setExtraContent([]); - navigation.goBack(); + navigation.navigate('Feed', {reRender: Math.random()}); //if (newPostCB) newPostCB(newPost); }); } diff --git a/Views/SelectProfile.js b/Views/SelectProfile.js new file mode 100644 index 0000000..65e4f4f --- /dev/null +++ b/Views/SelectProfile.js @@ -0,0 +1,70 @@ +import React from "react"; +import { View, ImageBackground, ScrollView } from "react-native"; +import { Text, List, RadioButton } from "react-native-paper"; +import i18n from "../i18nMessages.js"; +import Moment from 'moment'; +import 'moment/min/locales'; +Moment.locale(i18n.locale); +import API from '../API.js'; +import { useSnapshot } from 'valtio'; +import GlobalState from '../contexts/GlobalState.js'; +import ProfileCardHorizontal from "../components/ProfileCardHorizontal.js"; + + +let MenuView = ({ navigation }) => { + const [value, setValue] = React.useState('es'); + const [myProfiles, setMyProfiles] = React.useState([]); + const gState = useSnapshot(GlobalState); + const viewer = gState.me; + + React.useEffect(() => { + let subscribed = true; + let getData = async () => { + const r = await API.getMyProfiles(); + if (!subscribed) return; + console.log("profiles", r) + setMyProfiles(r); + } + getData(); + return () => { + subscribed = false; + } + }, []); + + let changeLang = (locale) => { + i18n.locale = locale; + Moment.locale(locale); + setValue(locale); + } + + return ( + + + + + + + { navigation.navigate("ProfileSettings") }} left={props => } /> + } /> + { navigation.navigate("Logout") }} left={props => } /> + + + { navigation.navigate("Invite") }} left={props => } /> + } /> + + + Language: + changeLang(newValue)} value={value}> + + + + + + + ) +} + +export default MenuView; \ No newline at end of file