Skip to content

Commit

Permalink
feat: performance optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
LuisParedes1 committed Nov 12, 2023
1 parent 6cb62cd commit 1483e7d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 46 deletions.
1 change: 1 addition & 0 deletions src/api/snaps/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export type Snap = {
has_shared: boolean;
favs: number;
num_replies: number;
profile_photo_url: string;
};
28 changes: 7 additions & 21 deletions src/screens/feed/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,6 @@ export const Card = ({ snap, client, onPress = () => {} }: Props) => {
day: '2-digit',
});

const [user, setUser] = useState<UserType>();

// Pido la cantidad de followers
useEffect(() => {
axios
.get(
'https://api-identity-socializer-luiscusihuaman.cloud.okteto.net/api/auth/users/' +
snap.author
)
.then((response) => {
console.log(response.data);
setUser(response.data);
})
.catch((error) => {
console.error(error);
});
}, [snap]);

console.log(snap);

return (
Expand All @@ -56,7 +38,7 @@ export const Card = ({ snap, client, onPress = () => {} }: Props) => {
<Image
className="inline-block h-10 w-10 rounded-full"
source={{
uri: user?.profile_photo_id ? user?.profile_photo_id : '',
uri: snap.profile_photo_url,
}}
/>
</View>
Expand Down Expand Up @@ -89,7 +71,9 @@ export const Card = ({ snap, client, onPress = () => {} }: Props) => {
if (isRetweeted) {
interaction = '/unshare/';
method = 'DELETE';
snap.shares--;
if (snap.shares > 0) {
snap.shares--;
}
} else {
interaction = '/share/';
method = 'POST';
Expand Down Expand Up @@ -118,7 +102,9 @@ export const Card = ({ snap, client, onPress = () => {} }: Props) => {
if (isLiked) {
interaction = '/unlike/';
method = 'DELETE';
snap.likes--;
if (snap.likes > 0) {
snap.likes--;
}
} else {
interaction = '/like/';
method = 'POST';
Expand Down
2 changes: 1 addition & 1 deletion src/screens/profile/my-snaps-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const MySnapsView = () => {
data={data}
renderItem={renderItem}
keyExtractor={(_, index) => `item-${index}`}
// ListEmptyComponent={<EmptyList isLoading={isLoading} />}
ListEmptyComponent={<EmptyList isLoading={isLoading} />}
onEndReached={handleEndReached}
onEndReachedThreshold={0.1}
refreshControl={
Expand Down
24 changes: 0 additions & 24 deletions src/screens/profile/profile-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,6 @@ const ProfileScreen = () => {
});
}, [userData]);

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

// axios
// .get(
// BASE_SNAP_URL +
// userData?.id +
// '/snaps?limit=' +
// limit +
// '&offset=' +
// offset
// )
// .then((response) => {
// console.log('Recibi de Snaps');
// console.log(response.data);
// setUserSnaps(response.data.snaps);
// })
// .catch((error) => {
// console.error(error);
// });
// }, [userData]);

return (
<>
<FocusAwareStatusBar />
Expand Down

0 comments on commit 1483e7d

Please sign in to comment.