-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
145 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,57 @@ | ||
import { View, Text } from "react-native" | ||
import { SafeAreaView } from "react-native-safe-area-context" | ||
import { useUser } from "@clerk/clerk-expo"; | ||
import { ActivityIndicator, FlatList, Image, Text, View } from "react-native"; | ||
import { SafeAreaView } from "react-native-safe-area-context"; | ||
|
||
import RideCard from "@/components/RideCard"; | ||
import { images } from "@/constants"; | ||
import { useFetch } from "@/lib/fetch"; | ||
import { Ride } from "@/types/type"; | ||
|
||
const Rides = () => { | ||
return( | ||
<SafeAreaView> | ||
<Text> | ||
Rides | ||
</Text> | ||
</SafeAreaView> | ||
) | ||
} | ||
const { user } = useUser(); | ||
|
||
const { | ||
data: recentRides, | ||
loading, | ||
error, | ||
} = useFetch<Ride[]>(`/(api)/ride/${user?.id}`); | ||
|
||
return ( | ||
<SafeAreaView className="flex-1 bg-white"> | ||
<FlatList | ||
data={recentRides} | ||
renderItem={({ item }) => <RideCard ride={item} />} | ||
keyExtractor={(item, index) => index.toString()} | ||
className="px-5" | ||
keyboardShouldPersistTaps="handled" | ||
contentContainerStyle={{ | ||
paddingBottom: 100, | ||
}} | ||
ListEmptyComponent={() => ( | ||
<View className="flex flex-col items-center justify-center"> | ||
{!loading ? ( | ||
<> | ||
<Image | ||
source={images.noResult} | ||
className="w-40 h-40" | ||
alt="No recent rides found" | ||
resizeMode="contain" | ||
/> | ||
<Text className="text-sm">No recent rides found</Text> | ||
</> | ||
) : ( | ||
<ActivityIndicator size="small" color="#000" /> | ||
)} | ||
</View> | ||
)} | ||
ListHeaderComponent={ | ||
<> | ||
<Text className="text-2xl font-JakartaBold my-5">All Rides</Text> | ||
</> | ||
} | ||
/> | ||
</SafeAreaView> | ||
); | ||
}; | ||
|
||
export default Rides; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,77 @@ | ||
|
||
import * as SecureStore from 'expo-secure-store' | ||
import * as Linking from "expo-linking" | ||
import { fetchAPI } from './fetch' | ||
|
||
|
||
export interface TokenCache { | ||
getToken: (key: string) => Promise<string | undefined | null> | ||
saveToken: (key: string, token: string) => Promise<void> | ||
clearToken?: (key: string) => void | ||
} | ||
getToken: (key: string) => Promise<string | undefined | null> | ||
saveToken: (key: string, token: string) => Promise<void> | ||
clearToken?: (key: string) => void | ||
} | ||
|
||
export const tokenCache = { | ||
async getToken(key: string) { | ||
try { | ||
const item = await SecureStore.getItemAsync(key) | ||
if (item) { | ||
console.log(`${key} was used 🔐 \n`) | ||
} else { | ||
console.log('No values stored under key: ' + key) | ||
} | ||
return item | ||
} catch (error) { | ||
console.error('SecureStore get item error: ', error) | ||
await SecureStore.deleteItemAsync(key) | ||
return null | ||
export const tokenCache = { | ||
async getToken(key: string) { | ||
try { | ||
const item = await SecureStore.getItemAsync(key) | ||
if (item) { | ||
console.log(`${key} was used 🔐 \n`) | ||
} else { | ||
console.log('No values stored under key: ' + key) | ||
} | ||
}, | ||
async saveToken(key: string, value: string) { | ||
try { | ||
return SecureStore.setItemAsync(key, value) | ||
} catch (err) { | ||
return | ||
return item | ||
} catch (error) { | ||
console.error('SecureStore get item error: ', error) | ||
await SecureStore.deleteItemAsync(key) | ||
return null | ||
} | ||
}, | ||
async saveToken(key: string, value: string) { | ||
try { | ||
return SecureStore.setItemAsync(key, value) | ||
} catch (err) { | ||
return | ||
} | ||
}, | ||
} | ||
export const googleOAuth = async (startOAuthFlow: any) => { | ||
try { | ||
const { createdSessionId, signIn, signUp, setActive } = await startOAuthFlow({ | ||
redirectUrl: Linking.createURL("/(root)/(tabs)/home") | ||
}) | ||
if (createdSessionId) { | ||
if (setActive) { | ||
await setActive!({ | ||
session: createdSessionId | ||
}) | ||
if (signUp.createdSessionId) { | ||
await fetchAPI("/(api)/user", | ||
{ | ||
method: "POST", | ||
body: JSON.stringify({ | ||
name: `${signUp.firstName} ${signUp.lastName}`, | ||
email: signUp.email, | ||
clerkId: signUp.createdUserId | ||
}) | ||
}) | ||
} | ||
return { | ||
success: true, | ||
code: "success", | ||
message: "You have successfully authenticated" | ||
} | ||
} | ||
}, | ||
} | ||
|
||
} | ||
return { | ||
success: false, | ||
message: "An error occurred" | ||
} | ||
|
||
} catch (error: any) { | ||
return { | ||
success: false, | ||
message: error?.errors[0]?.longMessage | ||
} | ||
} | ||
} |