From 8540817173490123f854783a268b696e21233328 Mon Sep 17 00:00:00 2001 From: Luis Paredes Date: Fri, 24 Nov 2023 08:37:37 -0300 Subject: [PATCH 1/3] fix: navigation errors --- src/screens/profile/profile-navigator.tsx | 5 --- src/screens/profile/profile-screen.tsx | 46 +++++++++++++++++------ src/screens/profile/profile-view.tsx | 4 ++ src/screens/users/user-navigate.tsx | 10 +++++ 4 files changed, 49 insertions(+), 16 deletions(-) diff --git a/src/screens/profile/profile-navigator.tsx b/src/screens/profile/profile-navigator.tsx index 20ea769..1d5b580 100644 --- a/src/screens/profile/profile-navigator.tsx +++ b/src/screens/profile/profile-navigator.tsx @@ -12,10 +12,6 @@ export type ProfileStackParamList = { Followers: { users: UserType[] | undefined }; Following: { users: UserType[] | undefined }; EditProfileScreen: { user: UserType | undefined }; - // ChatMessagesScreen: { - // chat: Chat | undefined; - // user: UserType; - // }; }; const Stack = createNativeStackNavigator(); @@ -27,7 +23,6 @@ export const ProfileNavigator = () => { - {/* */} ); }; diff --git a/src/screens/profile/profile-screen.tsx b/src/screens/profile/profile-screen.tsx index 313af86..51a29b2 100644 --- a/src/screens/profile/profile-screen.tsx +++ b/src/screens/profile/profile-screen.tsx @@ -1,10 +1,11 @@ import type { RouteProp } from '@react-navigation/native'; import { useRoute } from '@react-navigation/native'; import axios from 'axios'; -import React from 'react'; +import React, { useEffect } from 'react'; import { ScrollView } from 'react-native-gesture-handler'; import { getUserState } from '@/core'; +import type { UserType } from '@/core/auth/utils'; import { FocusAwareStatusBar, View } from '@/ui'; import type { ProfileStackParamList } from './profile-navigator'; @@ -12,7 +13,7 @@ import ProfileSnapsView from './profile-snaps-view'; import ProfileScreenView from './profile-view'; const BASE_INTERACTION_URL = - 'https://api-identity-socializer-luiscusihuaman.cloud.okteto.net/api/interactions/'; + 'https://api-identity-socializer-luiscusihuaman.cloud.okteto.net/api'; // const BASE_SNAP_URL = // 'https://api-content-discovery-luiscusihuaman.cloud.okteto.net/api/feed/'; @@ -24,15 +25,36 @@ const ProfileScreen = () => { const route = useRoute>(); const routeUser = route.params?.user; - const userData = routeUser ? routeUser : getUserState(); + const user = routeUser ? routeUser : getUserState(); const [userFollowerCount, setUserFollowerCount] = React.useState(0); const [userFollowingCount, setUserFollowingCount] = React.useState(0); + const [userUpdatedInfo, setUserUpdatedInfo] = React.useState(); + + useEffect(() => { + axios + .get( + BASE_INTERACTION_URL + + '/auth/' + + getUserState()?.id + + '/users/' + + user?.id + ) + .then((response) => { + console.log(response.data); + setUserUpdatedInfo(response.data); + }) + .catch((error) => { + console.error(error); + }); + }, [user]); // Pido la cantidad de followers - React.useEffect(() => { + useEffect(() => { axios - .get(BASE_INTERACTION_URL + userData?.id + '/count_followers') + .get( + BASE_INTERACTION_URL + '/interactions/' + user?.id + '/count_followers' + ) .then((response) => { console.log(response.data); setUserFollowerCount(response.data); @@ -40,12 +62,14 @@ const ProfileScreen = () => { .catch((error) => { console.error(error); }); - }, [userData]); + }, [user]); // Pido la cantidad de following - React.useEffect(() => { + useEffect(() => { axios - .get(BASE_INTERACTION_URL + userData?.id + '/count_following') + .get( + BASE_INTERACTION_URL + '/interactions/' + user?.id + '/count_following' + ) .then((response) => { console.log(response.data); setUserFollowingCount(response.data); @@ -53,7 +77,7 @@ const ProfileScreen = () => { .catch((error) => { console.error(error); }); - }, [userData]); + }, [user]); const client = axios.create({ baseURL: BASE_INTERACTION_URL, @@ -65,14 +89,14 @@ const ProfileScreen = () => { - + ); }; diff --git a/src/screens/profile/profile-view.tsx b/src/screens/profile/profile-view.tsx index 39ab8c9..41b9005 100644 --- a/src/screens/profile/profile-view.tsx +++ b/src/screens/profile/profile-view.tsx @@ -45,6 +45,10 @@ const ProfileScreenView = ({ setFollowingCount(following_count); }, [following_count]); + useEffect(() => { + setIsFollowing(user?.is_followed || false); + }, [user]); + const navigate = useNavigation(); return ( diff --git a/src/screens/users/user-navigate.tsx b/src/screens/users/user-navigate.tsx index 81bc8a1..c532386 100644 --- a/src/screens/users/user-navigate.tsx +++ b/src/screens/users/user-navigate.tsx @@ -2,7 +2,10 @@ import { createNativeStackNavigator } from '@react-navigation/native-stack'; import * as React from 'react'; import type { UserType } from '@/core/auth/utils'; +import { SignInComplete } from '@/navigation/signin-complete'; +import type { Chat } from '../chat/chat-list-screen'; +import ChatScreen from '../chat/chat-screen'; import InteractionsScreen from '../profile/interaction-view'; import ProfileScreen from '../profile/profile-screen'; @@ -10,6 +13,11 @@ export type UserStackParamList = { UserProfile: { user: UserType }; Followers: { users: UserType[] | undefined }; Following: { users: UserType[] | undefined }; + EditProfileScreen: { user: UserType | undefined }; + ChatMessagesScreen: { + chat: Chat | undefined; + user: UserType; + }; }; const Stack = createNativeStackNavigator(); @@ -20,6 +28,8 @@ export const UserNavigator = () => { + + ); }; From 96d40442de3b173e8b34d716540caef415ee5506 Mon Sep 17 00:00:00 2001 From: Luis Paredes Date: Fri, 24 Nov 2023 08:46:12 -0300 Subject: [PATCH 2/3] fix: user navigation --- src/api/snaps/use-snaps.ts | 12 ++++++------ src/screens/feed/card.tsx | 2 +- src/screens/profile/profile-navigator.tsx | 7 +++++++ src/screens/profile/profile-snaps-view.tsx | 2 +- src/screens/search/search-navigator.tsx | 10 ++++++++++ src/screens/search/snap-list.tsx | 2 +- 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/api/snaps/use-snaps.ts b/src/api/snaps/use-snaps.ts index a584e20..f0fb58d 100644 --- a/src/api/snaps/use-snaps.ts +++ b/src/api/snaps/use-snaps.ts @@ -27,7 +27,7 @@ export const useSnaps = createQuery({ const response = await client.get( `${primaryKey}/?user_id=${variables.user_id}&limit=${limit}&offset=${offset}` ); - console.log('response.data.snaps', response.data.snaps); // response.data is an array of posts + // console.log('response.data.snaps', response.data.snaps); // response.data is an array of posts return response.data.snaps; } catch (e) { console.log('error', e); @@ -42,7 +42,7 @@ export const getSnap = createQuery({ const response = await client.get( `${primaryKey}/${variables.snap_id}?user_id=${variables.user_id}` ); - console.log('response.data.snaps', response.data); // response.data is an array of posts + // console.log('response.data.snaps', response.data); // response.data is an array of posts return response.data; } catch (e) { console.log('error', e); @@ -61,7 +61,7 @@ export const getSnapsFrom = createQuery({ const response = await client.get( `${primaryKey}/${variables.user_id}/snaps?limit=${limit}&offset=${offset}` ); - console.log('response.data.snaps', response.data.snaps); // response.data is an array of posts + // console.log('response.data.snaps', response.data.snaps); // response.data is an array of posts return response.data.snaps; } catch (e) { console.log('error', e); @@ -76,7 +76,7 @@ export const userReplySnaps = createQuery({ const response = await client.get( `${primaryKey}/get_replies?snap_id=${replyVariables.snap_id}&user_id=${replyVariables.user_id}` ); - console.log('response.data.snaps', response.data.snaps); // response.data is an array of posts + // console.log('response.data.snaps', response.data.snaps); // response.data is an array of posts return response.data.snaps; } catch (e) { console.log('error', e); @@ -91,7 +91,7 @@ export const useMentions = createQuery({ // const limit = 100; // const offset = 0; const response = await client.get(`${primaryKey}/${variables.user_id}`); - console.log('response.data.snaps', response.data.snaps); // response.data is an array of posts + // console.log('response.data.snaps', response.data.snaps); // response.data is an array of posts return response.data.snaps; } catch (e) { console.log('error', e); @@ -108,7 +108,7 @@ export const useNotifications = createQuery({ 'https://api-identity-socializer-luiscusihuaman.cloud.okteto.net', }); const response = await client.get(`${primaryKey}/${variables.user_id}`); - console.log('response.data.notifications', response.data); // response.data is an array of posts + // console.log('response.data.notifications', response.data); // response.data is an array of posts return response.data; } catch (e) { console.log('error', e); diff --git a/src/screens/feed/card.tsx b/src/screens/feed/card.tsx index 4952d35..0279e12 100644 --- a/src/screens/feed/card.tsx +++ b/src/screens/feed/card.tsx @@ -48,7 +48,7 @@ export const Card = ({ snap, client, onPress = () => {} }: Props) => { setCommentCount(snap.num_replies); }, [snap]); - console.log(snap); + // console.log(snap); return ( diff --git a/src/screens/profile/profile-navigator.tsx b/src/screens/profile/profile-navigator.tsx index 1d5b580..a4c7ce4 100644 --- a/src/screens/profile/profile-navigator.tsx +++ b/src/screens/profile/profile-navigator.tsx @@ -4,6 +4,8 @@ import * as React from 'react'; import type { UserType } from '@/core/auth/utils'; import { SignInComplete } from '@/navigation/signin-complete'; +import type { Chat } from '../chat/chat-list-screen'; +import ChatScreen from '../chat/chat-screen'; import InteractionsScreen from './interaction-view'; import ProfileScreen from './profile-screen'; @@ -12,6 +14,10 @@ export type ProfileStackParamList = { Followers: { users: UserType[] | undefined }; Following: { users: UserType[] | undefined }; EditProfileScreen: { user: UserType | undefined }; + ChatMessagesScreen: { + chat: Chat | undefined; + user: UserType; + }; }; const Stack = createNativeStackNavigator(); @@ -23,6 +29,7 @@ export const ProfileNavigator = () => { + ); }; diff --git a/src/screens/profile/profile-snaps-view.tsx b/src/screens/profile/profile-snaps-view.tsx index 6bf7e7e..7ed1365 100644 --- a/src/screens/profile/profile-snaps-view.tsx +++ b/src/screens/profile/profile-snaps-view.tsx @@ -53,7 +53,7 @@ const ProfileSnapsView = ({ user }: { user: UserType | undefined }) => { // Corrected renderItem function const renderItem = ({ item, index }: { item: Snap; index: number }) => { // Render the item only if its index is within the current renderCount - console.log(`renderItem: ${index}: ${renderCount}`); + // console.log(`renderItem: ${index}: ${renderCount}`); if (index < renderCount) { return ( (); @@ -30,6 +38,8 @@ export const SearchNavigator = () => { + + ); }; diff --git a/src/screens/search/snap-list.tsx b/src/screens/search/snap-list.tsx index b2a02ac..c302344 100644 --- a/src/screens/search/snap-list.tsx +++ b/src/screens/search/snap-list.tsx @@ -23,7 +23,7 @@ const SnapList = () => { }); const renderSnap = ({ item }: { item: Snap }) => { - console.log(`Entre en renderItem: ${JSON.stringify(item)}`); + // console.log(`Entre en renderItem: ${JSON.stringify(item)}`); return ( Date: Fri, 24 Nov 2023 08:52:28 -0300 Subject: [PATCH 3/3] fix: folow and unfollow endpoints --- src/screens/profile/profile-screen.tsx | 25 ++++++------------------- src/screens/profile/profile-view.tsx | 2 +- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/screens/profile/profile-screen.tsx b/src/screens/profile/profile-screen.tsx index 51a29b2..ea86348 100644 --- a/src/screens/profile/profile-screen.tsx +++ b/src/screens/profile/profile-screen.tsx @@ -12,16 +12,13 @@ import type { ProfileStackParamList } from './profile-navigator'; import ProfileSnapsView from './profile-snaps-view'; import ProfileScreenView from './profile-view'; -const BASE_INTERACTION_URL = +const BASE_URL = 'https://api-identity-socializer-luiscusihuaman.cloud.okteto.net/api'; -// const BASE_SNAP_URL = -// 'https://api-content-discovery-luiscusihuaman.cloud.okteto.net/api/feed/'; +const BASE_INTERACTION_URL = + 'https://api-identity-socializer-luiscusihuaman.cloud.okteto.net/api/interactions/'; const ProfileScreen = () => { - // Obtengo los datos guardados en la memoria interna del telefono - - // First, get the route params unconditionally const route = useRoute>(); const routeUser = route.params?.user; @@ -33,13 +30,7 @@ const ProfileScreen = () => { useEffect(() => { axios - .get( - BASE_INTERACTION_URL + - '/auth/' + - getUserState()?.id + - '/users/' + - user?.id - ) + .get(BASE_URL + '/auth/' + getUserState()?.id + '/users/' + user?.id) .then((response) => { console.log(response.data); setUserUpdatedInfo(response.data); @@ -52,9 +43,7 @@ const ProfileScreen = () => { // Pido la cantidad de followers useEffect(() => { axios - .get( - BASE_INTERACTION_URL + '/interactions/' + user?.id + '/count_followers' - ) + .get(BASE_URL + '/interactions/' + user?.id + '/count_followers') .then((response) => { console.log(response.data); setUserFollowerCount(response.data); @@ -67,9 +56,7 @@ const ProfileScreen = () => { // Pido la cantidad de following useEffect(() => { axios - .get( - BASE_INTERACTION_URL + '/interactions/' + user?.id + '/count_following' - ) + .get(BASE_URL + '/interactions/' + user?.id + '/count_following') .then((response) => { console.log(response.data); setUserFollowingCount(response.data); diff --git a/src/screens/profile/profile-view.tsx b/src/screens/profile/profile-view.tsx index 41b9005..79a8145 100644 --- a/src/screens/profile/profile-view.tsx +++ b/src/screens/profile/profile-view.tsx @@ -133,7 +133,7 @@ const ProfileScreenView = ({ ) : null} - {user && userData && user.id !== userData.id ? ( + {user && userData && user.id !== userData.id && isFollowing ? (