Skip to content

Commit

Permalink
refactor: updated routing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
DOOduneye committed Apr 11, 2024
1 parent 94700a4 commit 8c0a2e9
Show file tree
Hide file tree
Showing 19 changed files with 458 additions and 260 deletions.
18 changes: 18 additions & 0 deletions frontend/sac-mobile/app/(app)/(tabs)/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ const HomeTabBarIcon = ({ color }: { color: string }) => (
<MaterialCommunityIcons name="home" size={24} color={color} />
);

const ProfileTabBarIcon = ({ color }: { color: string }) => (
<MaterialCommunityIcons name="account" size={24} color={color} />
);

const SearchTabBarIcon = ({ color }: { color: string }) => (
<MaterialCommunityIcons name="magnify" size={24} color={color} />
);

const Layout = () => {
const { isLoggedIn, fetchUser } = useAuthStore();

Expand All @@ -28,6 +36,16 @@ const Layout = () => {
}}
redirect={!isLoggedIn}
/>
<Tabs.Screen
name="search"
options={{ title: 'Search', headerShown: false, tabBarIcon: SearchTabBarIcon }}

Check failure on line 41 in frontend/sac-mobile/app/(app)/(tabs)/_layout.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `·title:·'Search',·headerShown:·false,·tabBarIcon:·SearchTabBarIcon` with `⏎····················title:·'Search',⏎····················headerShown:·false,⏎····················tabBarIcon:·SearchTabBarIcon⏎···············`

Check failure on line 41 in frontend/sac-mobile/app/(app)/(tabs)/_layout.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `·title:·'Search',·headerShown:·false,·tabBarIcon:·SearchTabBarIcon` with `⏎····················title:·'Search',⏎····················headerShown:·false,⏎····················tabBarIcon:·SearchTabBarIcon⏎···············`
redirect={!isLoggedIn}
/>
<Tabs.Screen
name="profile"
options={{ title: 'Profile', headerShown: false, tabBarIcon: ProfileTabBarIcon }}

Check failure on line 46 in frontend/sac-mobile/app/(app)/(tabs)/_layout.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `·title:·'Profile',·headerShown:·false,·tabBarIcon:·ProfileTabBarIcon` with `⏎····················title:·'Profile',⏎····················headerShown:·false,⏎····················tabBarIcon:·ProfileTabBarIcon⏎···············`

Check failure on line 46 in frontend/sac-mobile/app/(app)/(tabs)/_layout.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `·title:·'Profile',·headerShown:·false,·tabBarIcon:·ProfileTabBarIcon` with `⏎····················title:·'Profile',⏎····················headerShown:·false,⏎····················tabBarIcon:·ProfileTabBarIcon⏎···············`
redirect={!isLoggedIn}
/>
</Tabs>
);
};
Expand Down
70 changes: 46 additions & 24 deletions frontend/sac-mobile/app/(app)/(tabs)/index.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import React from 'react';
import { Text, View } from 'react-native';
import { Text, View, FlatList } from 'react-native';

Check failure on line 2 in frontend/sac-mobile/app/(app)/(tabs)/index.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `Text,·View,·FlatList·}·from·'react-native` with `FlatList,·Text,·View·}·from·'react-native';⏎import·{·SafeAreaView·}·from·'react-native-safe-area-context`

Check failure on line 2 in frontend/sac-mobile/app/(app)/(tabs)/index.tsx

View workflow job for this annotation

GitHub Actions / Lint

'View' is defined but never used

Check failure on line 2 in frontend/sac-mobile/app/(app)/(tabs)/index.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `Text,·View,·FlatList·}·from·'react-native` with `FlatList,·Text,·View·}·from·'react-native';⏎import·{·SafeAreaView·}·from·'react-native-safe-area-context`

Check failure on line 2 in frontend/sac-mobile/app/(app)/(tabs)/index.tsx

View workflow job for this annotation

GitHub Actions / Lint

'View' is defined but never used

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused import View.

import { Link } from 'expo-router';

import { Button } from '@/components/button';
import { useAuthStore } from '@/hooks/use-auth';

Check failure on line 6 in frontend/sac-mobile/app/(app)/(tabs)/index.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `useAuthStore·}·from·'@/hooks/use-auth` with `clubs·}·from·'@/data/clubs`

Check failure on line 6 in frontend/sac-mobile/app/(app)/(tabs)/index.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `useAuthStore·}·from·'@/hooks/use-auth` with `clubs·}·from·'@/data/clubs`
import { useEvents } from '@/hooks/use-event';

Check failure on line 7 in frontend/sac-mobile/app/(app)/(tabs)/index.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `Events·}·from·'@/hooks/use-event` with `AuthStore·}·from·'@/hooks/use-auth`

Check failure on line 7 in frontend/sac-mobile/app/(app)/(tabs)/index.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `Events·}·from·'@/hooks/use-event` with `AuthStore·}·from·'@/hooks/use-auth`
import { Event } from '@/types/event';

Check failure on line 8 in frontend/sac-mobile/app/(app)/(tabs)/index.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `Event·}·from·'@/types/event';⏎import·{·SafeAreaView·}·from·'react-native-safe-area-contex` with `useEvents·}·from·'@/hooks/use-even`

Check failure on line 8 in frontend/sac-mobile/app/(app)/(tabs)/index.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `Event·}·from·'@/types/event';⏎import·{·SafeAreaView·}·from·'react-native-safe-area-contex` with `useEvents·}·from·'@/hooks/use-even`
import { SafeAreaView } from 'react-native-safe-area-context';
import { Club } from '@/types/club';
import { clubs } from '@/data/clubs';

Check failure on line 11 in frontend/sac-mobile/app/(app)/(tabs)/index.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `clubs·}·from·'@/data/clubs` with `Event·}·from·'@/types/event`

Check failure on line 11 in frontend/sac-mobile/app/(app)/(tabs)/index.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `clubs·}·from·'@/data/clubs` with `Event·}·from·'@/types/event`

const Home = () => {
const { signOut, user } = useAuthStore();
const { user } = useAuthStore();
const { data: events, isLoading, error } = useEvents();

const handleSignOut = async () => {
signOut();
};

if (isLoading) {
return <Text>Loading...</Text>;
}
Expand All @@ -23,25 +22,48 @@ const Home = () => {
return <Text>Error: {error.message}</Text>;
}

const renderEvent = ({ item: event }: { item: Event }) => (
<Link
className='mt-10 mr-3'

Check failure on line 27 in frontend/sac-mobile/app/(app)/(tabs)/index.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `'mt-10·mr-3'` with `"mt-10·mr-3"`

Check failure on line 27 in frontend/sac-mobile/app/(app)/(tabs)/index.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `'mt-10·mr-3'` with `"mt-10·mr-3"`
key={event.id}
href={{
pathname: '/(app)/event/[id]',
params: { id: event.id }
}}
>
<Text>{event.name}</Text>
</Link>
);

const renderClub = ({ item: club }: { item: Club }) => (
<Link
className='mt-10 mr-3'

Check failure on line 40 in frontend/sac-mobile/app/(app)/(tabs)/index.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `'mt-10·mr-3'` with `"mt-10·mr-3"`

Check failure on line 40 in frontend/sac-mobile/app/(app)/(tabs)/index.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `'mt-10·mr-3'` with `"mt-10·mr-3"`
key={club.id}
href={{
pathname: '/(app)/club/[id]',
params: { id: club.id }
}}
>
<Text>{club.name}</Text>
</Link>
);

return (
<View className="items-center justify-center flex-1 gap-5">
<SafeAreaView className='flex items-center justify-center flex-1'>
<Text>Welcome {user?.first_name}</Text>
<Button onPress={handleSignOut}>Sign Out</Button>
{/* <Link href={"/(app)/(tabs)/event"}>
<Text>Event</Text>
</Link> */}
{events?.map((event) => (
<Link
key={event.id}
href={{
pathname: '/(app)/event/[id]',
params: { id: event.id }
}}
>
<Text>{event.name}</Text>
</Link>
))}
</View>
<FlatList
numColumns={5}
data={events}
renderItem={renderEvent}
keyExtractor={(item) => item.id.toString()}
/>
<FlatList
numColumns={5}
data={clubs}
renderItem={renderClub}
keyExtractor={(item) => item.id.toString()}
/>
</SafeAreaView>
);
};

Expand Down
20 changes: 20 additions & 0 deletions frontend/sac-mobile/app/(app)/(tabs)/profile.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { View, Text } from 'react-native';

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused import Text.
import React from 'react';
import { Button } from '@/components/button';
import { useAuthStore } from '@/hooks/use-auth';

const Profile = () => {
const { signOut } = useAuthStore();

const handleSignOut = async () => {
signOut();
};

return (
<View className='items-center justify-center flex-1 gap-5'>
<Button onPress={handleSignOut}>Sign Out</Button>
</View>
);
}

export default Profile;
12 changes: 12 additions & 0 deletions frontend/sac-mobile/app/(app)/(tabs)/search.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { View, Text } from 'react-native'
import React from 'react'

const Search = () => {
return (
<View>
<Text>Search</Text>
</View>
)
}

export default Search
106 changes: 105 additions & 1 deletion frontend/sac-mobile/app/(app)/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,113 @@
import React from 'react';

import { Stack } from 'expo-router';
import { MenuView } from '@react-native-menu/menu';
import { LeftArrow } from '@/components/left-arrow';
import { MaterialCommunityIcons } from '@expo/vector-icons';
import { View, Platform, StatusBar } from 'react-native';

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused import StatusBar.

const Layout = () => {
return <Stack />;
return (
<Stack>
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
<Stack.Screen
name="event/[id]"
options={{
animationTypeForReplace: 'push',
animation: 'slide_from_right',
headerShown: true,
headerTitleStyle: {
color: 'white'
},
headerBackground: () => (

Check warning on line 22 in frontend/sac-mobile/app/(app)/_layout.tsx

View workflow job for this annotation

GitHub Actions / Lint

Do not define components during render. React will see a new component type on every render and destroy the entire subtree’s DOM nodes and state (https://reactjs.org/docs/reconciliation.html#elements-of-different-types). Instead, move this component definition out of the parent component “Layout” and pass data as props. If you want to allow component creation in props, set allowAsProps option to true

Check warning on line 22 in frontend/sac-mobile/app/(app)/_layout.tsx

View workflow job for this annotation

GitHub Actions / Lint

Do not define components during render. React will see a new component type on every render and destroy the entire subtree’s DOM nodes and state (https://reactjs.org/docs/reconciliation.html#elements-of-different-types). Instead, move this component definition out of the parent component “Layout” and pass data as props. If you want to allow component creation in props, set allowAsProps option to true
<View className="h-full bg-gray-600" />
),
headerLeft: () => <LeftArrow />,

Check warning on line 25 in frontend/sac-mobile/app/(app)/_layout.tsx

View workflow job for this annotation

GitHub Actions / Lint

Do not define components during render. React will see a new component type on every render and destroy the entire subtree’s DOM nodes and state (https://reactjs.org/docs/reconciliation.html#elements-of-different-types). Instead, move this component definition out of the parent component “Layout” and pass data as props. If you want to allow component creation in props, set allowAsProps option to true

Check warning on line 25 in frontend/sac-mobile/app/(app)/_layout.tsx

View workflow job for this annotation

GitHub Actions / Lint

Do not define components during render. React will see a new component type on every render and destroy the entire subtree’s DOM nodes and state (https://reactjs.org/docs/reconciliation.html#elements-of-different-types). Instead, move this component definition out of the parent component “Layout” and pass data as props. If you want to allow component creation in props, set allowAsProps option to true
headerRight: () => {

Check warning on line 26 in frontend/sac-mobile/app/(app)/_layout.tsx

View workflow job for this annotation

GitHub Actions / Lint

Do not define components during render. React will see a new component type on every render and destroy the entire subtree’s DOM nodes and state (https://reactjs.org/docs/reconciliation.html#elements-of-different-types). Instead, move this component definition out of the parent component “Layout” and pass data as props. If you want to allow component creation in props, set allowAsProps option to true

Check warning on line 26 in frontend/sac-mobile/app/(app)/_layout.tsx

View workflow job for this annotation

GitHub Actions / Lint

Do not define components during render. React will see a new component type on every render and destroy the entire subtree’s DOM nodes and state (https://reactjs.org/docs/reconciliation.html#elements-of-different-types). Instead, move this component definition out of the parent component “Layout” and pass data as props. If you want to allow component creation in props, set allowAsProps option to true
return (
<MenuView
onPressAction={({ nativeEvent }) => {
console.warn(JSON.stringify(nativeEvent));
}}
actions={[
{
id: 'share',
title: 'Share Event',
image: Platform.select({
ios: 'square.and.arrow.up',
android: 'share-variant'
})
},
{
id: 'report',
title: 'Report Event',
image: Platform.select({
ios: 'person.crop.circle.badge.exclamationmark.fill',
android: 'person-circle-outline'
})
}
]}
>
<MaterialCommunityIcons
name="dots-vertical"
size={24}
color="white"
/>
</MenuView>
);
}
}}
/>
<Stack.Screen
name="club"
options={{
animationTypeForReplace: 'push',
animation: 'slide_from_right',
headerShown: true,
headerTitleStyle: {
color: 'white'
},
headerBackground: () => (

Check warning on line 70 in frontend/sac-mobile/app/(app)/_layout.tsx

View workflow job for this annotation

GitHub Actions / Lint

Do not define components during render. React will see a new component type on every render and destroy the entire subtree’s DOM nodes and state (https://reactjs.org/docs/reconciliation.html#elements-of-different-types). Instead, move this component definition out of the parent component “Layout” and pass data as props. If you want to allow component creation in props, set allowAsProps option to true

Check warning on line 70 in frontend/sac-mobile/app/(app)/_layout.tsx

View workflow job for this annotation

GitHub Actions / Lint

Do not define components during render. React will see a new component type on every render and destroy the entire subtree’s DOM nodes and state (https://reactjs.org/docs/reconciliation.html#elements-of-different-types). Instead, move this component definition out of the parent component “Layout” and pass data as props. If you want to allow component creation in props, set allowAsProps option to true
<View className="h-full bg-gray-600" />
),
headerLeft: () => <LeftArrow />,

Check warning on line 73 in frontend/sac-mobile/app/(app)/_layout.tsx

View workflow job for this annotation

GitHub Actions / Lint

Do not define components during render. React will see a new component type on every render and destroy the entire subtree’s DOM nodes and state (https://reactjs.org/docs/reconciliation.html#elements-of-different-types). Instead, move this component definition out of the parent component “Layout” and pass data as props. If you want to allow component creation in props, set allowAsProps option to true

Check warning on line 73 in frontend/sac-mobile/app/(app)/_layout.tsx

View workflow job for this annotation

GitHub Actions / Lint

Do not define components during render. React will see a new component type on every render and destroy the entire subtree’s DOM nodes and state (https://reactjs.org/docs/reconciliation.html#elements-of-different-types). Instead, move this component definition out of the parent component “Layout” and pass data as props. If you want to allow component creation in props, set allowAsProps option to true
headerRight: () => {

Check warning on line 74 in frontend/sac-mobile/app/(app)/_layout.tsx

View workflow job for this annotation

GitHub Actions / Lint

Do not define components during render. React will see a new component type on every render and destroy the entire subtree’s DOM nodes and state (https://reactjs.org/docs/reconciliation.html#elements-of-different-types). Instead, move this component definition out of the parent component “Layout” and pass data as props. If you want to allow component creation in props, set allowAsProps option to true

Check warning on line 74 in frontend/sac-mobile/app/(app)/_layout.tsx

View workflow job for this annotation

GitHub Actions / Lint

Do not define components during render. React will see a new component type on every render and destroy the entire subtree’s DOM nodes and state (https://reactjs.org/docs/reconciliation.html#elements-of-different-types). Instead, move this component definition out of the parent component “Layout” and pass data as props. If you want to allow component creation in props, set allowAsProps option to true
return (
<MenuView
onPressAction={({ nativeEvent }) => {
console.warn(JSON.stringify(nativeEvent));
}}
actions={[
{
id: 'share',
title: 'Share Club',
image: Platform.select({
ios: 'square.and.arrow.up',
android: 'share-variant'
})
},
{
id: 'report',
title: 'Report Club',
image: Platform.select({
ios: 'person.crop.circle.badge.exclamationmark.fill',
android: 'person-circle-outline'
})
}
]}
>
<MaterialCommunityIcons
name="dots-vertical"
size={24}
color="white"
/>
</MenuView>
);
}
}}
/>
</Stack>
);
};

export default Layout;
21 changes: 21 additions & 0 deletions frontend/sac-mobile/app/(app)/club/[id].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { View, Text, SafeAreaView } from 'react-native'

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused import View.
import React from 'react'
import { Link, Stack, useLocalSearchParams } from 'expo-router';

const ClubPage = () => {
const { id } = useLocalSearchParams<{ id: string }>();

return (
<SafeAreaView>
<Stack.Screen
options={{ title: `${id}` }}
/>
<Text>ClubPage</Text>
<Link href={{ pathname: `/club/faq/${id}` }}>
<Text>FAQ</Text>
</Link>
</SafeAreaView>
)
}

export default ClubPage
15 changes: 15 additions & 0 deletions frontend/sac-mobile/app/(app)/club/_layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { View, Text } from 'react-native'

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused imports Text, View.
import React from 'react'
import { Stack } from 'expo-router'

const Layout = () => {
return (
<Stack>
<Stack.Screen name="[id]" options={{ headerShown: false }} />
<Stack.Screen name="faq/[id]" options={{ headerShown: false, presentation: 'modal' }} />

</Stack>
)
}

export default Layout
15 changes: 15 additions & 0 deletions frontend/sac-mobile/app/(app)/club/faq/[id].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { View, Text, SafeAreaView } from 'react-native'

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused import View.
import React from 'react'
import { useLocalSearchParams } from 'expo-router';

const Faq = () => {
const { id } = useLocalSearchParams<{ id: string }>();

return (
<SafeAreaView className='items-center justify-center flex-1 bg-white'>
<Text>{id}</ Text>
</SafeAreaView>
)
}

export default Faq
Loading

0 comments on commit 8c0a2e9

Please sign in to comment.