Skip to content

Commit

Permalink
Merge branch 'main' of github.com:lyve-app/lyve-mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
Louis3797 committed Jun 20, 2024
2 parents 23cedab + 4bfaf64 commit 95af7d1
Show file tree
Hide file tree
Showing 10 changed files with 288 additions and 40 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"expo-status-bar": "~1.11.1",
"expo-system-ui": "~2.9.3",
"expo-web-browser": "~12.8.2",
"formik": "^2.4.6",
"install": "^0.13.0",
"jwt-decode": "^4.0.0",
"mediasoup-client": "^3.7.8",
Expand Down
7 changes: 7 additions & 0 deletions src/api/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ export type Notification = {
updated_at: Date;
};

export type Genre = {
name: string;
percent: number;
days: Days[];
avgViewers: number;
}

export type GetUserResponse = TypedResponse<{
user: User & {
subscribed: boolean;
Expand Down
8 changes: 6 additions & 2 deletions src/app/(auth)/(tabs)/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
import FloatingButton from '@components/FloatingButton';
import { Feather } from '@expo/vector-icons';
import useAuth from '@modules/auth/useAuth';
import { Tabs } from 'expo-router';
import { Tabs, usePathname } from 'expo-router';
import React from 'react';
import { Platform } from 'react-native';

export default function TabLayout() {
const { user } = useAuth();

const pathname = usePathname();

return (
<Tabs
screenOptions={{
tabBarHideOnKeyboard: true,
tabBarTestID: 'tabbar',
tabBarActiveTintColor: 'white',
tabBarInactiveTintColor: '#676D75',
headerShown: false,
tabBarStyle: {
display: pathname.includes('editProfile') ? 'none' : 'flex',
position: 'absolute',
justifyContent: 'center',
alignItems: 'center',
borderWidth: 0,
height: Platform.OS === 'ios' ? '11%' : '8%',
height: Platform.OS === 'ios' ? '11%' : '9%',
borderColor: '#151718',
borderTopWidth: 1,
borderTopColor: '#242526',
Expand Down
2 changes: 2 additions & 0 deletions src/app/(auth)/(tabs)/profile/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ const ProfileRootLayout = () => {
return (
<Stack>
<Stack.Screen name="[userid]" options={{ headerShown: false, animation: 'fade_from_bottom' }} />
<Stack.Screen name="editProfile" options={{ headerShown: false, animation: 'fade_from_bottom' }} />
</Stack>

);
};

Expand Down
30 changes: 30 additions & 0 deletions src/app/(auth)/(tabs)/profile/editProfile.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {
View,
Text,
KeyboardAvoidingView,
Platform,
ScrollView,
TouchableWithoutFeedback,
Keyboard,
} from 'react-native';
import React from 'react';
import EditProfilePage from '@screens/EditProfilePage';
import { SafeAreaView } from 'react-native-safe-area-context';

const EditProfile = () => {
return (
<KeyboardAvoidingView
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
style={{ flex: 1 }}>
<TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false}>
<SafeAreaView style={{ flex: 1 }}>
<ScrollView contentContainerStyle={{ flexGrow: 1 }}>
<EditProfilePage />
</ScrollView>
</SafeAreaView>
</TouchableWithoutFeedback>
</KeyboardAvoidingView>
);
};

export default EditProfile;
36 changes: 14 additions & 22 deletions src/components/profile/GenreStatisticBadge.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
import { formatNumber } from '@utils/formatNumber';
import React from 'react';
import { YStack, SizableText } from 'tamagui';
import { YStack, SizableText, XStack } from 'tamagui';

interface Props {
genre: string;
percent: number;
avgViewer: number;
days: string[];
}

const GenreStatisticBadge: React.FC<Props> = ({ genre, percent = 0 }) => {
const GenreStatisticBadge: React.FC<Props> = ({ genre, percent, avgViewer, days }) => {
return (
<YStack
padding="$2"
gap="$1"
alignItems="center"
backgroundColor="$primaryLight"
height="$10"
width="$8"
borderRadius={15}>
<YStack
justifyContent="center"
alignItems="center"
height="$4"
width="$4"
backgroundColor="#151718"
borderRadius={15}>
<SizableText fontSize={20}>{genre.split(' ')[1] ?? '❓'}</SizableText>
</YStack>
<YStack alignItems="center">
<SizableText fontSize={13}>{genre.split(' ')[0]}</SizableText>
<SizableText fontSize={13}>{percent}%</SizableText>
<YStack padding="$2" backgroundColor="$primaryLight" borderRadius={15}>
<YStack gap="$2" paddingLeft="$2" paddingRight="$2">
<SizableText fontSize={14}>
{percent.toPrecision(3)}% {genre}
</SizableText>
<XStack justifyContent='space-between'>
<SizableText fontSize={13} color="$color.textWashedOut">Avg. Viewers: {formatNumber(avgViewer)}</SizableText>
<SizableText fontSize={13} color="$color.textWashedOut">Mostly {days}</SizableText>
</XStack>
</YStack>
</YStack>
);
Expand Down
3 changes: 1 addition & 2 deletions src/components/profile/ProfileHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ const ProfileHeader: React.FC<ProfileHeaderProps> = ({ user, isSelf, subscribed
{isSelf ? (
<>
<Button
testID="edit-profile-button"
onPress={() => console.log('Edit Profile View')}
onPress={() => router.push('/(auth)/(tabs)/profile/editProfile')}
backgroundColor="$textWashedOut"
size="$4"
borderRadius="$10"
Expand Down
152 changes: 152 additions & 0 deletions src/screens/EditProfilePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import React, { useEffect, useState } from 'react';
import useAuth from '@modules/auth/useAuth';
import { Avatar, Button, H1, Input, SizableText, TextArea, XStack, YStack } from 'tamagui';
import { Feather } from '@expo/vector-icons';
import { router } from 'expo-router';
import { Formik } from 'formik';
import { KeyboardAvoidingView, Platform, Pressable } from 'react-native';
import { useUpdateUser } from '@api/user/mutation/useUpdateUser';
import { useGetUser } from '@api/user/query/useGetUser';
import useCameraActionSheet from '@hooks/useCameraActionSheet';

const EditProfilePage = () => {


const { show, assets } = useCameraActionSheet();


const [imageUri, setImageUri] = useState<{
image: {
uri: string;
name: string;
type: string;
};
} | null>(null);

useEffect(() => {
if (assets && assets[0]) {
const { uri, mimeType, fileName, assetId } = assets[0];
setImageUri({
image: { uri, type: mimeType ?? 'image/jpeg', name: fileName ?? assetId ?? 'image' },
});
}
}, [assets]);

const openActionSheet = async () => {
console.log("fnjkgjrngjrj");
await show();
};


const { user } = useAuth();

const { data } = useGetUser({
variables: { id: user.id },
refetchOnMount: true,
refetchOnWindowFocus: true,
});

const { mutate } = useUpdateUser();

const updateUser = async (displayname: string, bio: string) => {
const formData = new FormData();


if (imageUri) {
// @ts-ignore
formData.append('image', { ...imageUri.image });
}

formData.append('dispname', displayname);
formData.append('bio', bio);
mutate({
id: user.id,
data: formData,
});
};

const handleFinishPress = (displayname: string, bio: string) => {
updateUser(displayname, bio);
router.back();
};

return (

<Formik
initialValues={{ displayname: user.dispname || '', bio: data?.data?.user.bio || '' }}
onSubmit={(values) => updateUser(values.displayname, values.bio)}>
{(props) => (
<YStack padding="$4" backgroundColor="$background" gap="$5" flexGrow={1}>
<XStack alignItems="center" justifyContent="space-between">
<XStack alignItems="center">
<Pressable onPress={() => router.back()}>
<Feather name="chevron-left" size={28} color="white" />
</Pressable>
<H1 fontSize={24}>Edit Profile</H1>
</XStack>
<Pressable onPress={() => handleFinishPress(props.values.displayname, props.values.bio)}>
<SizableText fontSize={18} color="$accentWashedOut">
Finish
</SizableText>
</Pressable>
</XStack>

<YStack alignItems="center">
<Avatar circular size="$10" testID="profile-avatar">
<Avatar.Image
accessibilityLabel="Nate Wienert"
src={
data?.data?.user.avatar_url ??
'https://lyveblobstorage.blob.core.windows.net/images/avatar_placeholder.png'
}
/>
<Avatar.Fallback delayMs={600} backgroundColor="$blue10" />
</Avatar>
<Pressable onPress={openActionSheet}>
<SizableText color="$textWashedOut">Edit Avatar</SizableText>
</Pressable>
</YStack>

<YStack gap="$2">
<YStack gap="$6">
<YStack gap="$2">
<XStack justifyContent="space-between">
<SizableText color="$textWashedOut">Displayname</SizableText>
<SizableText
color={props.values.displayname.length >= 20 ? 'red' : '$textWashedOut'}>
{props.values.displayname.length}/20
</SizableText>
</XStack>
<Input
maxLength={20}
placeholderTextColor="$textWashedOut"
placeholder="displayname"
onChangeText={props.handleChange('displayname')}
value={props.values.displayname}
/>
</YStack>

<YStack gap="$2">
<XStack justifyContent="space-between">
<SizableText color="$textWashedOut">Bio</SizableText>
<SizableText color={props.values.bio.length >= 100 ? 'red' : '$textWashedOut'}>
{props.values.bio.length}/100
</SizableText>
</XStack>
<TextArea
maxLength={100}
placeholderTextColor="$textWashedOut"
placeholder="bio"
onChangeText={props.handleChange('bio')}
value={props.values.bio}
/>
</YStack>
</YStack>
</YStack>
</YStack>
)}
</Formik>
);
};

export default EditProfilePage;
Loading

0 comments on commit 95af7d1

Please sign in to comment.