Skip to content

Commit

Permalink
Merge pull request #96 from bambu-group-03/fixes
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
LuisParedes1 committed Nov 24, 2023
2 parents 91b7206 + c33cc57 commit 140e7f3
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 31 deletions.
12 changes: 6 additions & 6 deletions src/api/snaps/use-snaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const useSnaps = createQuery<Response, Variables, AxiosError>({
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);
Expand All @@ -42,7 +42,7 @@ export const getSnap = createQuery<Response, SnapVariables, AxiosError>({
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);
Expand All @@ -61,7 +61,7 @@ export const getSnapsFrom = createQuery<Response, Variables, AxiosError>({
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);
Expand All @@ -76,7 +76,7 @@ export const userReplySnaps = createQuery<Response, ReplyVariable, AxiosError>({
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);
Expand All @@ -91,7 +91,7 @@ export const useMentions = createQuery<Response, Variables, Error>({
// 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);
Expand All @@ -108,7 +108,7 @@ export const useNotifications = createQuery<Response, Variables, AxiosError>({
'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);
Expand Down
2 changes: 1 addition & 1 deletion src/screens/feed/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const Card = ({ snap, client, onPress = () => {} }: Props) => {
setCommentCount(snap.num_replies);
}, [snap]);

console.log(snap);
// console.log(snap);

return (
<Pressable className="flex shrink-0 p-4 pb-0" onPress={onPress}>
Expand Down
12 changes: 7 additions & 5 deletions src/screens/profile/profile-navigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -12,10 +14,10 @@ export type ProfileStackParamList = {
Followers: { users: UserType[] | undefined };
Following: { users: UserType[] | undefined };
EditProfileScreen: { user: UserType | undefined };
// ChatMessagesScreen: {
// chat: Chat | undefined;
// user: UserType;
// };
ChatMessagesScreen: {
chat: Chat | undefined;
user: UserType;
};
};

const Stack = createNativeStackNavigator<ProfileStackParamList>();
Expand All @@ -27,7 +29,7 @@ export const ProfileNavigator = () => {
<Stack.Screen name="Followers" component={InteractionsScreen} />
<Stack.Screen name="Following" component={InteractionsScreen} />
<Stack.Screen name="EditProfileScreen" component={SignInComplete} />
{/* <Stack.Screen name="ChatMessagesScreen" component={ChatScreen} /> */}
<Stack.Screen name="ChatMessagesScreen" component={ChatScreen} />
</Stack.Navigator>
);
};
43 changes: 27 additions & 16 deletions src/screens/profile/profile-screen.tsx
Original file line number Diff line number Diff line change
@@ -1,59 +1,70 @@
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';
import ProfileSnapsView from './profile-snaps-view';
import ProfileScreenView from './profile-view';

const BASE_URL =
'https://api-identity-socializer-luiscusihuaman.cloud.okteto.net/api';

const BASE_INTERACTION_URL =
'https://api-identity-socializer-luiscusihuaman.cloud.okteto.net/api/interactions/';

// const BASE_SNAP_URL =
// 'https://api-content-discovery-luiscusihuaman.cloud.okteto.net/api/feed/';

const ProfileScreen = () => {
// Obtengo los datos guardados en la memoria interna del telefono

// First, get the route params unconditionally
const route = useRoute<RouteProp<ProfileStackParamList, 'UserProfile'>>();
const routeUser = route.params?.user;

const userData = routeUser ? routeUser : getUserState();
const user = routeUser ? routeUser : getUserState();

const [userFollowerCount, setUserFollowerCount] = React.useState<number>(0);
const [userFollowingCount, setUserFollowingCount] = React.useState<number>(0);
const [userUpdatedInfo, setUserUpdatedInfo] = React.useState<UserType>();

useEffect(() => {
axios
.get(BASE_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_URL + '/interactions/' + user?.id + '/count_followers')
.then((response) => {
console.log(response.data);
setUserFollowerCount(response.data);
})
.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_URL + '/interactions/' + user?.id + '/count_following')
.then((response) => {
console.log(response.data);
setUserFollowingCount(response.data);
})
.catch((error) => {
console.error(error);
});
}, [userData]);
}, [user]);

const client = axios.create({
baseURL: BASE_INTERACTION_URL,
Expand All @@ -65,14 +76,14 @@ const ProfileScreen = () => {
<View>
<ScrollView>
<ProfileScreenView
user={userData}
user={userUpdatedInfo}
follower_count={userFollowerCount}
following_count={userFollowingCount}
client={client}
/>
</ScrollView>
</View>
<ProfileSnapsView user={userData} />
<ProfileSnapsView user={userUpdatedInfo} />
</>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/screens/profile/profile-snaps-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Card
Expand Down
6 changes: 5 additions & 1 deletion src/screens/profile/profile-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ const ProfileScreenView = ({
setFollowingCount(following_count);
}, [following_count]);

useEffect(() => {
setIsFollowing(user?.is_followed || false);
}, [user]);

const navigate = useNavigation();

return (
Expand Down Expand Up @@ -129,7 +133,7 @@ const ProfileScreenView = ({
</View>
) : null}

{user && userData && user.id !== userData.id ? (
{user && userData && user.id !== userData.id && isFollowing ? (
<TouchableOpacity
className="mt-4 rounded-full bg-blue-500 px-4 py-3 text-center font-bold text-white"
onPress={() =>
Expand Down
10 changes: 10 additions & 0 deletions src/screens/search/search-navigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import * as React from 'react';

import type { Snap } from '@/api';
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';
import SearchView from './search-view';
Expand All @@ -17,6 +20,11 @@ export type SearchStackParamList = {
Followers: { users: UserType[] | undefined };
Following: { users: UserType[] | undefined };
SnapList: { snaps: Snap[] };
EditProfileScreen: { user: UserType | undefined };
ChatMessagesScreen: {
chat: Chat | undefined;
user: UserType;
};
};

const Stack = createNativeStackNavigator<SearchStackParamList>();
Expand All @@ -30,6 +38,8 @@ export const SearchNavigator = () => {
<Stack.Screen name="Followers" component={InteractionsScreen} />
<Stack.Screen name="Following" component={InteractionsScreen} />
<Stack.Screen name="SnapList" component={SnapList} />
<Stack.Screen name="EditProfileScreen" component={SignInComplete} />
<Stack.Screen name="ChatMessagesScreen" component={ChatScreen} />
</Stack.Navigator>
);
};
2 changes: 1 addition & 1 deletion src/screens/search/snap-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Card
snap={item}
Expand Down
10 changes: 10 additions & 0 deletions src/screens/users/user-navigate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@ 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';

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<UserStackParamList>();
Expand All @@ -20,6 +28,8 @@ export const UserNavigator = () => {
<Stack.Screen name="UserProfile" component={ProfileScreen} />
<Stack.Screen name="Followers" component={InteractionsScreen} />
<Stack.Screen name="Following" component={InteractionsScreen} />
<Stack.Screen name="EditProfileScreen" component={SignInComplete} />
<Stack.Screen name="ChatMessagesScreen" component={ChatScreen} />
</Stack.Navigator>
);
};

0 comments on commit 140e7f3

Please sign in to comment.