Skip to content

Commit

Permalink
feat: following count in profile
Browse files Browse the repository at this point in the history
  • Loading branch information
LuisParedes1 committed Nov 11, 2023
1 parent fe3f090 commit d584423
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 20 deletions.
54 changes: 37 additions & 17 deletions src/screens/profile/profile-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,54 @@ import { useEffect, useState } from 'react';
import { Snap } from '@/api';
import { getUserState } from '@/core';

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

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
const userData = getUserState();

const [userSnaps, setUserSnaps] = useState<Snap[]>([]);
const [userFollowerCount, setUserFollowerCount] = useState<number>(0);
const [userFollowingCount, setUserFollowingCount] = useState<number>(0);

//const [userData, setUserData] = useState<UserType | null>(null);
// useEffect(() => {
// axios
// .get(BASE_USER_URL + 'users/' + userID)
// .then((response) => {
// console.log(response.data);
// setUserData(response.data);
// })
// .catch((error) => {
// console.error(error);
// });
// }, [userID]);
// Pido la cantidad de followers
useEffect(() => {
axios
.get(BASE_INTERACTION_URL + userData?.id + '/count_followers')
.then((response) => {
console.log(response.data);
setUserFollowerCount(response.data);
})
.catch((error) => {
console.error(error);
});
}, [userData]);

// Pido la cantidad de following
useEffect(() => {
axios
.get(BASE_INTERACTION_URL + userData?.id + '/count_following')
.then((response) => {
console.log(response.data);
setUserFollowingCount(response.data);
})
.catch((error) => {
console.error(error);
});
}, [userData]);

// Pido los snaps del usuario
useEffect(() => {
const limit = 100;
const offset = 0;

axios
.get(
BASE_INTERACTION_URL +
BASE_SNAP_URL +
userData?.id +
'/snaps?limit=' +
limit +
Expand All @@ -61,7 +77,11 @@ const ProfileScreen = () => {
<FocusAwareStatusBar />
<View>
<ScrollView>
<ProfileScreenView user={userData} />
<ProfileScreenView
user={userData}
follower_count={userFollowerCount}
following_count={userFollowingCount}
/>
</ScrollView>
</View>
<MySnapsView data={userSnaps} />
Expand Down
14 changes: 11 additions & 3 deletions src/screens/profile/profile-view.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { UserType } from '@/core/auth/utils';
import { FocusAwareStatusBar, View, Image, Text, TouchableOpacity } from '@/ui';

const ProfileScreenView = ({ user }: { user: UserType | undefined }) => {
const ProfileScreenView = ({
user,
follower_count,
following_count,
}: {
user: UserType | undefined;
follower_count: number;
following_count: number;
}) => {
return (
<View>
<View className="relative max-w-md mx-auto md:max-w-2xl min-w-0 break-words bg-white w-full mb-6 shadow-lg rounded-xl mt-3">
Expand All @@ -23,7 +31,7 @@ const ProfileScreenView = ({ user }: { user: UserType | undefined }) => {
<View className="p-3 text-center">
<TouchableOpacity onPress={() => console.log('Followers')}>
<Text className="text-xl font-bold block uppercase tracking-wide text-slate-700 text-center">
2,454
{follower_count}
</Text>

<Text
Expand All @@ -41,7 +49,7 @@ const ProfileScreenView = ({ user }: { user: UserType | undefined }) => {
<View className="p-3 text-center">
<TouchableOpacity onPress={() => console.log('Following')}>
<Text className="text-xl font-bold block uppercase tracking-wide text-slate-700 text-center">
564
{following_count}
</Text>

<Text
Expand Down

0 comments on commit d584423

Please sign in to comment.