Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
in-mai-space committed Nov 4, 2024
1 parent 7714664 commit 598a0db
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 37 deletions.
16 changes: 11 additions & 5 deletions frontend/api/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,17 @@ export async function getUserBadges(): Promise<any> {
return data.badges;
}

export async function followUser(id: string, followUserId: string): Promise<void> {
const response = await fetch(`${API_BASE_URL}/user/${id}/follow/${followUserId}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
});
export async function followUser(
id: string,
followUserId: string,
): Promise<void> {
const response = await fetch(
`${API_BASE_URL}/user/${id}/follow/${followUserId}`,
{
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
},
);
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData.error || 'Failed to follow user');
Expand Down
58 changes: 47 additions & 11 deletions frontend/app/(app)/(tabs)/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import React from 'react';
import Home from "../../../assets/house.svg";
import Search from "../../../assets/search.svg";
import Plus from "../../../assets/plus.svg";
import Star from "../../../assets/star.svg";
import Profile from "../../../assets/profile.svg";
import { faHouse, faSearch, faStar, faCircleUser, faPlusSquare } from '@fortawesome/free-solid-svg-icons';
import Home from '../../../assets/house.svg';
import Search from '../../../assets/search.svg';
import Plus from '../../../assets/plus.svg';
import Star from '../../../assets/star.svg';
import Profile from '../../../assets/profile.svg';
import {
faHouse,
faSearch,
faStar,
faCircleUser,
faPlusSquare,
} from '@fortawesome/free-solid-svg-icons';
import { Tabs } from 'expo-router';
import IconButton from '../../../components/icon-button';

Expand All @@ -29,7 +35,13 @@ const Layout = () => {
title: 'Home',
headerShown: false,
headerTransparent: true,
tabBarIcon: ({ focused }) => { return focused ? <IconButton icon={faHouse} /> : <Home width={20} height={20} />;},
tabBarIcon: ({ focused }) => {
return focused ? (
<IconButton icon={faHouse} />
) : (
<Home width={20} height={20} />
);
},
}}
/>
<Tabs.Screen
Expand All @@ -38,7 +50,13 @@ const Layout = () => {
title: 'Explore',
headerShown: false,
headerTransparent: true,
tabBarIcon: ({ focused }) => {return focused ? <IconButton icon={faSearch} /> : <Search width={20} height={20} />},
tabBarIcon: ({ focused }) => {
return focused ? (
<IconButton icon={faSearch} />
) : (
<Search width={20} height={20} />
);
},
}}
/>
<Tabs.Screen
Expand All @@ -47,7 +65,13 @@ const Layout = () => {
title: 'Post',
headerShown: false,
headerTransparent: true,
tabBarIcon: ({ focused }) => {return focused ? <IconButton icon={faPlusSquare} /> : <Plus width={20} height={20} />},
tabBarIcon: ({ focused }) => {
return focused ? (
<IconButton icon={faPlusSquare} />
) : (
<Plus width={20} height={20} />
);
},
}}
/>
<Tabs.Screen
Expand All @@ -56,7 +80,13 @@ const Layout = () => {
title: 'Notification',
headerShown: false,
headerTransparent: true,
tabBarIcon: ({ focused }) => {return focused ? <IconButton icon={faStar} /> : <Star width={20} height={20} />},
tabBarIcon: ({ focused }) => {
return focused ? (
<IconButton icon={faStar} />
) : (
<Star width={20} height={20} />
);
},
}}
/>
<Tabs.Screen
Expand All @@ -65,7 +95,13 @@ const Layout = () => {
title: 'Profile',
headerShown: false,
headerTransparent: true,
tabBarIcon: ({ focused }) => {return focused ? <IconButton icon={faCircleUser} /> : <Profile width={20} height={20} />},
tabBarIcon: ({ focused }) => {
return focused ? (
<IconButton icon={faCircleUser} />
) : (
<Profile width={20} height={20} />
);
},
}}
/>
</Tabs>
Expand Down
5 changes: 4 additions & 1 deletion frontend/app/(app)/post/components/post-creation-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export default function PostCreation() {
const methods = useForm<FormFields>();
return (
<FormProvider {...methods}>
<ScrollView showsVerticalScrollIndicator={false} className="flex flex-col space-y-2 w-[90vw]">
<ScrollView
showsVerticalScrollIndicator={false}
className="flex flex-col space-y-2 w-[90vw]"
>
<View className="flex flex-col justify-items items-center pt-[10vh]">
<Text className="font-bold text-[24px] leading-[29.05px] pb-[1vh]">
{' '}
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/(app)/user/components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const Header = ({ id }: { id: string }) => {
const handleFollowToggle = useCallback(async () => {
try {
if (supabaseId) {
await followMutation.mutateAsync({id: supabaseId, followUserId: id});
await followMutation.mutateAsync({ id: supabaseId, followUserId: id });
} else {
console.error('supabaseId is null');
}
Expand Down
10 changes: 8 additions & 2 deletions frontend/app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ const InitialLayout = () => {
return (
<View className="h-full w-full flex flex-col">
<Stack>
<Stack.Screen name="(auth)" options={{ headerShown: false, gestureEnabled: false }} />
<Stack.Screen name="(app)" options={{ headerShown: false, gestureEnabled: false }} />
<Stack.Screen
name="(auth)"
options={{ headerShown: false, gestureEnabled: false }}
/>
<Stack.Screen
name="(app)"
options={{ headerShown: false, gestureEnabled: false }}
/>
</Stack>
</View>
);
Expand Down
14 changes: 7 additions & 7 deletions frontend/auth/authStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const useAuthStore = create<AuthState>(
'supabase.auth.token',
'supabase.auth.refreshToken',
'@supabase.auth.token',
'@supabase.auth.refreshToken'
'@supabase.auth.refreshToken',
]);
} catch (error) {
console.error('Error clearing storage:', error);
Expand All @@ -55,7 +55,7 @@ export const useAuthStore = create<AuthState>(
set({ loading: true, error: null });
try {
await get().clearStorage();

const response = await login(userData);
const session = await getSession();
const userMe = await getUserById(response.user.id);
Expand All @@ -82,7 +82,7 @@ export const useAuthStore = create<AuthState>(
set({ loading: true, error: null });
try {
await get().clearStorage();

const response = await register(userData);
const session = await getSession();
const userMe = await getUserById(response.user.id);
Expand Down Expand Up @@ -110,7 +110,7 @@ export const useAuthStore = create<AuthState>(
try {
await logout();
await get().clearStorage();

set({
user: null,
token: null,
Expand All @@ -134,6 +134,6 @@ export const useAuthStore = create<AuthState>(
{
name: 'auth-storage',
getStorage: () => AsyncStorage,
}
)
);
},
),
);
5 changes: 3 additions & 2 deletions frontend/hooks/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export const useFollowUser = () => {
const queryClient = useQueryClient();

return useMutation({
mutationFn: ({ id, followUserId }: { id: string, followUserId: string }) => followUser(id, followUserId),
mutationFn: ({ id, followUserId }: { id: string; followUserId: string }) =>
followUser(id, followUserId),
onSuccess: (_, { id }) => {
queryClient.invalidateQueries({ queryKey: ['user', id] });
queryClient.invalidateQueries({ queryKey: ['user'] });
Expand All @@ -54,4 +55,4 @@ export const useFollowUser = () => {
queryClient.invalidateQueries({ queryKey: ['user'] });
},
});
};
};
17 changes: 9 additions & 8 deletions frontend/utils/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ export const formatNumber = (number: number): string => {
};

export const timeAgo = (date: Date = new Date()): string => {
const seconds = Math.floor((new Date().getTime() - new Date(date).getTime()) / 1000);
const seconds = Math.floor(
(new Date().getTime() - new Date(date).getTime()) / 1000,
);
let interval = Math.floor(seconds / 31536000);
if (interval >= 1) return interval === 1 ? "1y ago" : `${interval}y ago`;
if (interval >= 1) return interval === 1 ? '1y ago' : `${interval}y ago`;
interval = Math.floor(seconds / 2592000);
if (interval >= 1) return interval === 1 ? "1m ago" : `${interval}m ago`;
if (interval >= 1) return interval === 1 ? '1m ago' : `${interval}m ago`;
interval = Math.floor(seconds / 86400);
if (interval >= 1) return interval === 1 ? "1d ago" : `${interval}d ago`;
if (interval >= 1) return interval === 1 ? '1d ago' : `${interval}d ago`;
interval = Math.floor(seconds / 3600);
if (interval >= 1) return interval === 1 ? "1h ago" : `${interval}h ago`;
if (interval >= 1) return interval === 1 ? '1h ago' : `${interval}h ago`;
interval = Math.floor(seconds / 60);
if (interval >= 1) return interval === 1 ? "1m ago" : `${interval}m ago`;
return seconds === 1 ? "1s ago" : `${seconds}s ago`;
if (interval >= 1) return interval === 1 ? '1m ago' : `${interval}m ago`;
return seconds === 1 ? '1s ago' : `${seconds}s ago`;
};

0 comments on commit 598a0db

Please sign in to comment.