Skip to content

Commit

Permalink
imp: Followings Screen
Browse files Browse the repository at this point in the history
  • Loading branch information
gulsensabak committed Dec 13, 2024
1 parent 5a3c207 commit ad903c7
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 3 deletions.
6 changes: 6 additions & 0 deletions mobile/tradeverse/app/(tabs)/account/followings.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react'
import FollowingScreen from '../../../screens/following'

export default function Followings() {
return <FollowingScreen />
}
3 changes: 2 additions & 1 deletion mobile/tradeverse/config/screen-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const paths = {
FOLLOWED_TOPICS: `${roots.ACCOUNT}/followed-topics`,
FOLLOWED_USERS: `${roots.ACCOUNT}/followed-users`,
MY_POSTS: `${roots.ACCOUNT}/my-posts`,
FOLLOWERS: `${roots.ACCOUNT}/followers`
FOLLOWERS: `${roots.ACCOUNT}/followers`,
FOLLOWINGS: `${roots.ACCOUNT}/followings`
},
}
export default paths
2 changes: 1 addition & 1 deletion mobile/tradeverse/screens/account-root/profile-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const ProfileConfig = {
value: 'my_following',
title: 'Followings',
icon: <IconUserUp {...defaultIconProps} />,
href: paths.ACCOUNT.FOLLOWED_USERS,
href: paths.ACCOUNT.FOLLOWINGS,
},
],
},
Expand Down
141 changes: 141 additions & 0 deletions mobile/tradeverse/screens/following/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import React, { useEffect, useState } from 'react';
import { View, Text, Image, StyleSheet } from 'react-native';
import GlobalScreen from '../../components/ui/global-screen';
import FullScrollView from '../../components/ui/full-scroll-view';
import { Stack } from 'expo-router';
import api from '../../services/_axios';
import AsyncStorage from '@react-native-async-storage/async-storage';

const FollowingScreen = () => {
const [followings, setFollowings] = useState([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(false);

const mockData = [
{
username: 'gulsen',
name: 'Gulsen',
userPhoto: null,
},
];

useEffect(() => {
const fetchFollowings = async () => {
try {
const token = await AsyncStorage.getItem('authToken');
const response = await api.get('/api/follow/get-followings', {
headers: { Authorization: `Bearer ${token}` },
});
setFollowings(response.data.followings || mockData);
} catch (error) {
console.error('Error fetching followings:', error);
setFollowings(mockData);
setError(true);
} finally {
setLoading(false);
}
};

fetchFollowings();
}, []);

if (loading) {
return (
<GlobalScreen>
<Text style={styles.loadingText}>Loading following...</Text>
</GlobalScreen>
);
}

if (error && followings.length === 0) {
return (
<GlobalScreen>
<Text style={styles.errorText}>Failed to load followings.</Text>
</GlobalScreen>
);
}

return (
<GlobalScreen>
<FullScrollView>
<Stack.Screen
options={{
headerBackTitleVisible: false,
headerTitle: 'Following',
}}
/>
<View style={styles.container}>
<Text style={styles.countText}>
Following Count: {followings.length}
</Text>
{followings.map((following, index) => (
<View key={index} style={styles.followingItem}>
<Image
source={{
uri: following.userPhoto || 'https://via.placeholder.com/50',
}}
style={styles.userPhoto}
/>
<View style={styles.textContainer}>
<Text style={styles.username}>
{following.username}
</Text>
<Text style={styles.name}>
{following.name}
</Text>
</View>
</View>
))}
</View>
</FullScrollView>
</GlobalScreen>
);
};

const styles = StyleSheet.create({
container: {
padding: 16,
},
countText: {
fontSize: 18,
fontWeight: 'bold',
marginBottom: 16,
textAlign: 'center',
},
loadingText: {
fontSize: 16,
textAlign: 'center',
marginTop: 20,
},
errorText: {
fontSize: 16,
textAlign: 'center',
marginTop: 20,
color: 'red',
},
followingItem: {
flexDirection: 'row',
alignItems: 'center',
marginBottom: 12,
},
userPhoto: {
width: 50,
height: 50,
borderRadius: 25,
marginRight: 12,
backgroundColor: '#ddd', // Placeholder color for fallback
},
textContainer: {
flex: 1,
},
username: {
fontSize: 16,
fontWeight: '600',
},
name: {
fontSize: 14,
color: '#555',
},
});

export default FollowingScreen;
2 changes: 1 addition & 1 deletion mobile/tradeverse/services/_axios.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ api.interceptors.request.use(
api.interceptors.response.use(
(response) => {
console.log('<-- RESPONSE')
if (response) console.log('Data: ', response.data)
if (response) console.log('Data: lıne 40 ', response.data)
console.log('---------------------------------')
return response
},
Expand Down

0 comments on commit ad903c7

Please sign in to comment.