Skip to content

Commit

Permalink
styling
Browse files Browse the repository at this point in the history
  • Loading branch information
capture120 committed Apr 18, 2024
1 parent acd82e8 commit 2640852
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 69 deletions.
1 change: 0 additions & 1 deletion frontend/components/PopularUser.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
import React from 'react';
import {Image, StyleSheet, Text, View, TouchableOpacity} from 'react-native';
import { Leader } from '../types/types';
Expand Down
25 changes: 13 additions & 12 deletions frontend/components/ProfilePerformance.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { View, Text, Pressable } from 'react-native'
import React from 'react'
import { View, Text, Pressable } from 'react-native';
import React from 'react';
import { useNavigation } from '@react-navigation/native';
import { ProfileNavigationProp } from '../types/navigationTypes';
import { useSession } from '@clerk/clerk-expo';
Expand All @@ -10,15 +10,16 @@ interface ProfilePerformanceProps {
user: User;
}

const ProfilePerformance = (
{ portfolioValue }: ProfilePerformanceProps,
{ user }: ProfilePerformanceProps,
) => {
const ProfilePerformance = ({
portfolioValue,
user,
}: ProfilePerformanceProps) => {
const { session } = useSession();
const navigator = useNavigation<ProfileNavigationProp>();
const handleCopyTrades = () => {
navigator.navigate('CopyTrades', { user: user });
};
console.log(user);

return (
<View className="flex flex-col justify-between space-y-1 py-3 px-6 border-b-[1px] border-b-gray-200">
Expand All @@ -28,15 +29,15 @@ const ProfilePerformance = (
className={`text-2xl ${portfolioValue >= 0 ? 'text-[#02AD98]' : 'text-[#FF2B51]'}`}>
{portfolioValue} %
</Text>
{session?.user.username === user?.username ? null : (
<Pressable onPress={handleCopyTrades}>
<Text>Copy Trades</Text>
</Pressable>
)}
{session?.user.username !== user?.username ? (
<Pressable onPress={handleCopyTrades}>
<Text>Copy Trades</Text>
</Pressable>
) : null}
</View>
<Text>YTD Performance</Text>
</View>
);
};

export default ProfilePerformance
export default ProfilePerformance;
36 changes: 11 additions & 25 deletions frontend/pages/Copy/CopyTradesPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useState } from 'react';
import {
View,
Text,
Expand All @@ -9,15 +9,15 @@ import {
Alert,
Image,
} from 'react-native';
import { useNavigation } from '@react-navigation/native';
import { useNavigation, useRoute } from '@react-navigation/native';
import { useSession } from '@clerk/clerk-expo';
import {
ProfileNavigationProp,
AuthNavigationProp,
} from '../../types/navigationTypes';
import { User } from '../../types/types';
import { getUserById } from '../../services/users';
import { copyTrades } from '../../services/copy';
import { CopyRouteParams } from '../../types/types';
// import { User } from '../../types/types';
// import { copyTrades } from '../../services/copy';

function CopyTradesPage() {
const { session } = useSession();
Expand All @@ -28,20 +28,17 @@ function CopyTradesPage() {
const [stopLossAmount, setStopLossAmount] = useState('500');
const [tradeAuthorizationRequired, setTradeAuthorizationRequired] =
useState(false);
const [user, setUser] = useState<User | null>(null);
const route = useRoute();
const user = (route.params as CopyRouteParams)?.user;

const handleSubmit = async () => {
if (!user) {
Alert.alert('Error', "User doesn't exist");
return;
}
if (!session?.user.id) {
authNavigation.navigate('Login');
return;
}

try {
await copyTrades(session?.user.id as string, user.username);
// await copyTrades(session?.user.id as string, user.username);
} catch (error) {
Alert.alert('Error', 'Failed to copy trades');
return;
Expand All @@ -51,24 +48,13 @@ function CopyTradesPage() {
navigation.navigate('Profile');
};

useEffect(() => {
const fetchUser = async () => {
try {
const user = await getUserById('');
setUser(user);
} catch (error) {
console.error('Error fetching user:', error);
}
};

fetchUser();
}, []);

return (
<View style={styles.container}>
<View style={styles.formWrapper}>
<View style={styles.header}>
<Text style={styles.username}>@kevinkevindaliri</Text>
<Text style={styles.username}>
@{user?.username || 'kevinkevindaliri'}
</Text>
<TouchableOpacity onPress={() => navigation.navigate('Profile')}>
<Text style={styles.closeButton}>×</Text>
</TouchableOpacity>
Expand Down
58 changes: 36 additions & 22 deletions frontend/pages/Profile.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useNavigation, useRoute } from '@react-navigation/native';
import React, { useEffect, useState } from 'react';
import { FlatList, Pressable, ScrollView, View } from 'react-native';
import { FlatList, Pressable, ScrollView, Text, View } from 'react-native';
import { useSession } from '@clerk/clerk-expo';
import ProfileBanner from '../components/ProfileBanner';
import SubTabButton from '../components/SubTabButton';
Expand Down Expand Up @@ -64,49 +64,63 @@ const Profile = () => {
}, []);

return (
<ScrollView className='bg-white'>
<View className='flex flex-col space-y-2'>
<ProfileBanner user={user}/>
<ScrollView className="bg-white">
<View className="flex flex-col space-y-2">
<ProfileBanner user={user} />

<View className='flex flex-row'>
<SubTabButton title='Portfolio' selected={pageNumber == 0} onPress={OnPortfolioSelected} />
<View className="flex flex-row">
<SubTabButton
title="Portfolio"
selected={pageNumber == 0}
onPress={OnPortfolioSelected}
/>
{!isFollowerProfile && (
<SubTabButton title='Activity' selected={pageNumber == 1} onPress={OnActivitySelected} />
<SubTabButton
title="Activity"
selected={pageNumber == 1}
onPress={OnActivitySelected}
/>
)}
</View>

<ScrollView
horizontal={true} className='flex flex-row h-screen' pagingEnabled={true}
horizontal={true}
className="flex flex-row h-screen"
pagingEnabled={true}
showsHorizontalScrollIndicator={true}
onMomentumScrollEnd={(event) => {
onMomentumScrollEnd={event => {
const offset = event.nativeEvent.contentOffset.x;
const page = Math.round(offset / 375);
console.log(`Page number: ${page}`);
setPageNumber(page);
}}
>
{pageNumber === 0 && (
<View className='flex flex-col w-screen'>
<ProfilePerformance portfolioValue={portfolio?.total_gain_pct || 0} user={user} />
<ProfilePositions positions={portfolio?.positions}/>
</View>
)}
<View className='flex flex-col w-screen'>
}}>
{pageNumber === 0 && (
<View className="flex flex-col w-screen">
<ProfilePerformance
portfolioValue={portfolio?.total_gain_pct || 0}
user={user}
/>
<ProfilePositions positions={portfolio?.positions} />
</View>
)}
<View className="flex flex-col w-screen">
{pageNumber == 1 && (
<FlatList
data={ProfileActivityData}
keyExtractor={(item) => item.id.toString()}
keyExtractor={item => item.id.toString()}
renderItem={({ item }) => (
<ActivityItem
title={item.title}
description={item.description}
icon={item.icon} />
)} />
icon={item.icon}
/>
)}
/>
)}
</View>
</ScrollView>

</View>
<Text>{user.username}</Text>
<SignOut />
</ScrollView>
);
Expand Down
9 changes: 0 additions & 9 deletions frontend/router/BottomNavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,4 @@ const BottomNavBar = () => {
);
};


// const ProfileStack = createStackNavigator();
// const ProfileStackNavigator = () => (
// <ProfileStack.Navigator initialRouteName="Profile">
// <ProfileStack.Screen name="Profile" component={Profile} />
// <ProfileStack.Screen name="CopyTrades" component={CopyTradesPage} />
// </ProfileStack.Navigator>
// );

export default BottomNavBar;
4 changes: 4 additions & 0 deletions frontend/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ export interface ProfileRouteParams {
user: User;
}

export interface CopyRouteParams {
user: User;
}

export interface FollowerRouteParams {
users: User[],
label: string
Expand Down

0 comments on commit 2640852

Please sign in to comment.