Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/Navigation/_layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function () {
// these axios calls need to move somewhere else
useEffect(() => {
axios
.get(`http://18.219.151.178:3000/users/vY1hQh5wpwgI1zzaweeooEqyJAi1`)
.get(`http://127.0.0.1:3000/users/vY1hQh5wpwgI1zzaweeooEqyJAi1`)
.then((response) => {
// set message count to equal number of notifications
setMessageCount(response.data.notifications);
Expand All @@ -29,7 +29,7 @@ export default function () {
const handleBadgePress = () => {
// insted of resetting the state, send a put request using axios to users/notifications/reset/:uid
axios
.patch(`http://18.219.151.178:3000/users/notifications/reset/vY1hQh5wpwgI1zzaweeooEqyJAi1`)
.patch(`http://127.0.0.1:3000/users/notifications/reset/vY1hQh5wpwgI1zzaweeooEqyJAi1`)
.then((response) => {
// set message count to equal number of notifications
setMessageCount(0);
Expand Down
53 changes: 53 additions & 0 deletions app/Screens/message/Data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const Messages = [
{
id: '1',
userName: 'Brandon',
ProfileImg: require('../../../assets/users/Brandon.png'),
messageTime: '4 mins ago',
messageText: 'Approvals are looking great',
},
{
id: '2',
userName: 'Kyle',
ProfileImg: 'https://i.imgur.com/O9IwNcx.png',
messageTime: '2 hours ago',
messageText: 'I created a new profile recently',
},
{
id: '3',
userName: 'Nam',
ProfileImg: 'https://i.imgur.com/swnqERH.png',
messageTime: '1 hours ago',
messageText: 'The design is finished on Figma',
},
{
id: 'pbbQjIfF7abqfvKD38DOBAbgoHr2',
userName: 'Mev',
ProfileImg: 'https://i.imgur.com/Biw5Jsb.png',
messageTime: '1 day ago',
messageText: 'Thanks!',
},
{
id: '5',
userName: 'Jenessa',
ProfileImg: require('../../../assets/users/Jenessa.png'),
messageTime: '2 days ago',
messageText: 'I finished setting up the database',
},
{
id: '6',
userName: 'Majd',
ProfileImg: require('../../../assets/users/Majd.png'),
messageTime: '2 days ago',
messageText: 'my code is polished',
},
{
id: '7',
userName: 'Donn',
ProfileImg: require('../../../assets/users/Donn.png'),
messageTime: '2 days ago',
messageText: 'Navigation is good to go',
},
];

export default Messages;
28 changes: 6 additions & 22 deletions app/Screens/message/MessageScreens/ChatScreen.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
import React, { useCallback, useEffect, useState } from 'react';
import { Button, ScrollView, StyleSheet, Text, View } from 'react-native';
import { View } from 'react-native';

import axios from 'axios';
import { nanoid } from 'nanoid';
import { Bubble, GiftedChat, Send } from 'react-native-gifted-chat';
import FontAwesome from 'react-native-vector-icons/FontAwesome';
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
import { useDispatch, useSelector } from 'react-redux';
import { useSelector } from 'react-redux';

function ChatScreen({ route }) {
const uid = useSelector((store) => store.currentUser.uid) || 'vY1hQh5wpwgI1zzaweeooEqyJAi1';
const { id } = route.params;

// console.log('id: ', id);
// console.log('userId: ', uid);

const [messages, setMessages] = useState([]);

// redux message data
// const { message } = useSelector((state) => state.message);

useEffect(() => {
// Fetch messages every 1 second
const fetchMessages = () => {
axios
.get(`http://18.219.151.178:3000/users/${uid}`)
.get(`http://127.0.0.1:3000/users/${uid}`)
.then((response) => {
const messagesThread = response.data.messages[id];
// reverse the order of messages
Expand All @@ -49,17 +40,10 @@ function ChatScreen({ route }) {
}, []);

const onSend = useCallback((messages = []) => {
// console.log('on send', messages);
const postObj = { message: messages[0] };
// setSentMessages(postObj);
axios
.post(`http://18.219.151.178:3000/users/messages/${uid}/${id}`, postObj)
.then((response) => {
// console.log('post sucessful', response);
})
.catch((error) => {
console.log(error);
});
axios.post(`http://127.0.0.1:3000/users/messages/${uid}/${id}`, postObj).catch((error) => {
console.log(error);
});

setMessages((previousMessages) => GiftedChat.append(previousMessages, messages));
}, []);
Expand Down
41 changes: 3 additions & 38 deletions app/Screens/message/MessageScreens/Connections.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { Button, FlatList, StyleSheet, Text, View } from 'react-native';
import { FlatList, StyleSheet } from 'react-native';

import Messages from '../Data';
import {
Container,
ProfileImg,
Expand All @@ -11,43 +12,7 @@ import {
UserName,
} from '../MessageStyles/MessageStyles';

const contacts = [
{
id: '1',
userName: 'Brandon',
ProfileImg: require('../../../../assets/users/Brandon.png'),
},
{
id: '2',
userName: 'Kyle',
ProfileImg: require('../../../../assets/users/Kyle.png'),
},
{
id: '3',
userName: 'Nam',
ProfileImg: require('../../../../assets/users/Nam.png'),
},
{
id: 'pbbQjIfF7abqfvKD38DOBAbgoHr2',
userName: 'Mev',
ProfileImg: require('../../../../assets/users/Mev.png'),
},
{
id: '5',
userName: 'Jenessa',
ProfileImg: require('../../../../assets/users/Jenessa.png'),
},
{
id: '6',
userName: 'Majd',
ProfileImg: require('../../../../assets/users/Majd.png'),
},
{
id: '7',
userName: 'Donn',
ProfileImg: require('../../../../assets/users/Donn.png'),
},
];
const contacts = Messages;

function Connections({ navigation }) {
return (
Expand Down
59 changes: 4 additions & 55 deletions app/Screens/message/MessageScreens/MessagesScreen.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { Button, FlatList, StyleSheet, Text, View } from 'react-native';
import { FlatList, StyleSheet } from 'react-native';

import Messages from '../Data';
import {
Container,
MessageText,
Expand All @@ -14,58 +15,6 @@ import {
UserName,
} from '../MessageStyles/MessageStyles';

const Messages = [
{
id: '1',
userName: 'Brandon',
ProfileImg: require('../../../../assets/users/Brandon.png'),
messageTime: '4 mins ago',
messageText: 'Approvals are looking great',
},
{
id: '2',
userName: 'Kyle',
ProfileImg: 'https://i.imgur.com/O9IwNcx.png',
messageTime: '2 hours ago',
messageText: 'I created a new profile recently',
},
{
id: '3',
userName: 'Nam',
ProfileImg: 'https://i.imgur.com/swnqERH.png',
messageTime: '1 hours ago',
messageText: 'The design is finished on Figma',
},
{
id: 'pbbQjIfF7abqfvKD38DOBAbgoHr2',
userName: 'Mev',
ProfileImg: 'https://i.imgur.com/Biw5Jsb.png',
messageTime: '1 day ago',
messageText: 'hi',
},
{
id: '5',
userName: 'Jenessa',
ProfileImg: require('../../../../assets/users/Jenessa.png'),
messageTime: '2 days ago',
messageText: 'I finished setting up the database',
},
{
id: '6',
userName: 'Majd',
ProfileImg: require('../../../../assets/users/Majd.png'),
messageTime: '2 days ago',
messageText: 'my code is polished',
},
{
id: '7',
userName: 'Donn',
ProfileImg: require('../../../../assets/users/Donn.png'),
messageTime: '2 days ago',
messageText: 'Navigation is good to go',
},
];

function MessagesScreen({ navigation }) {
return (
<Container>
Expand All @@ -74,8 +23,8 @@ function MessagesScreen({ navigation }) {
keyExtractor={(item) => item.id}
renderItem={({ item }) => (
<Tile
onPress={
() => navigation.navigate('ChatScreen', { userName: item.userName, id: item.id }) // change item.id to _id to match incoming data object properties
onPress={() =>
navigation.navigate('ChatScreen', { userName: item.userName, id: item.id })
}
>
<UserInfo>
Expand Down