diff --git a/app/(tabs)/_layout.tsx b/app/(app)/(tabs)/_layout.tsx
similarity index 100%
rename from app/(tabs)/_layout.tsx
rename to app/(app)/(tabs)/_layout.tsx
diff --git a/app/(tabs)/index.tsx b/app/(app)/(tabs)/index.tsx
similarity index 100%
rename from app/(tabs)/index.tsx
rename to app/(app)/(tabs)/index.tsx
diff --git a/app/(tabs)/settings.tsx b/app/(app)/(tabs)/settings.tsx
similarity index 100%
rename from app/(tabs)/settings.tsx
rename to app/(app)/(tabs)/settings.tsx
diff --git a/app/(app)/_layout.tsx b/app/(app)/_layout.tsx
new file mode 100644
index 0000000..2c82880
--- /dev/null
+++ b/app/(app)/_layout.tsx
@@ -0,0 +1,113 @@
+import { MaterialCommunityIcons } from '@expo/vector-icons'
+import {
+ useFonts,
+ JetBrainsMono_400Regular,
+} from '@expo-google-fonts/jetbrains-mono'
+import { NotoSans_400Regular } from '@expo-google-fonts/noto-sans'
+import { Redirect, SplashScreen, Stack, useRootNavigationState } from 'expo-router'
+import * as SecureStore from 'expo-secure-store'
+import React from 'react'
+import { useColorScheme } from 'react-native'
+import { PaperProvider } from 'react-native-paper'
+
+import { useAuth } from '@/lib/providers/auth'
+import { Setting } from '@/lib/types'
+import { StackHeader, Themes } from '@/lib/ui'
+
+export {
+ // Catch any errors thrown by the Layout component.
+ ErrorBoundary,
+} from 'expo-router'
+
+export const unstable_settings = {
+ // Ensure that reloading on `/modal` keeps a back button present.
+ initialRouteName: '(root)/login',
+}
+
+// Prevent the splash screen from auto-hiding before asset loading is complete.
+SplashScreen.preventAutoHideAsync()
+
+const RootLayout = () => {
+ const { user } = useAuth()
+ const [loaded, error] = useFonts({
+ NotoSans_400Regular,
+ JetBrainsMono_400Regular,
+ ...MaterialCommunityIcons.font,
+ })
+
+ // Get authentication state
+ const rootNavigationState = useRootNavigationState()
+
+ // Expo Router uses Error Boundaries to catch errors in the navigation tree.
+ React.useEffect(() => {
+ if (error) throw error
+ }, [error])
+
+ React.useEffect(() => {
+ if (loaded) {
+ SplashScreen.hideAsync()
+ }
+ }, [loaded])
+ // Make sure we have the navigation state before showing content
+ if (!loaded || !rootNavigationState) {
+ return null
+ }
+ if (!user) {
+ console.log('redirecting inside the root')
+ return
+ }
+
+ return
+}
+
+const RootLayoutNav = () => {
+ const colorScheme = useColorScheme()
+ const [settings, setSettings] = React.useState({
+ theme: 'auto',
+ color: 'default',
+ })
+
+ // Load settings from the device
+ React.useEffect(() => {
+ SecureStore.getItemAsync('settings').then((result) => {
+ if (result === null) {
+ SecureStore.setItemAsync('settings', JSON.stringify(settings)).then(
+ (res) => console.log(res),
+ )
+ }
+
+ setSettings(JSON.parse(result ?? JSON.stringify(settings)))
+ })
+
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [])
+
+ return (
+
+ (
+
+ ),
+ }}
+ >
+
+
+
+
+
+
+ )
+}
+
+export default RootLayout
diff --git a/app/drawer/_layout.tsx b/app/(app)/drawer/_layout.tsx
similarity index 100%
rename from app/drawer/_layout.tsx
rename to app/(app)/drawer/_layout.tsx
diff --git a/app/drawer/index.tsx b/app/(app)/drawer/index.tsx
similarity index 100%
rename from app/drawer/index.tsx
rename to app/(app)/drawer/index.tsx
diff --git a/app/drawer/settings.tsx b/app/(app)/drawer/settings.tsx
similarity index 100%
rename from app/drawer/settings.tsx
rename to app/(app)/drawer/settings.tsx
diff --git a/app/modal.tsx b/app/(app)/modal.tsx
similarity index 100%
rename from app/modal.tsx
rename to app/(app)/modal.tsx
diff --git a/app/search.tsx b/app/(app)/search.tsx
similarity index 100%
rename from app/search.tsx
rename to app/(app)/search.tsx
diff --git a/app/(auth)/login.tsx b/app/(auth)/login.tsx
deleted file mode 100644
index c0c5b9e..0000000
--- a/app/(auth)/login.tsx
+++ /dev/null
@@ -1,7 +0,0 @@
-import { Text } from "react-native-paper";
-
-export default function Login() {
- return (
- Login please
- )
-}
\ No newline at end of file
diff --git a/app/+html.tsx b/app/+html.tsx
deleted file mode 100644
index 69c20c3..0000000
--- a/app/+html.tsx
+++ /dev/null
@@ -1,42 +0,0 @@
-import { ScrollViewStyleReset } from 'expo-router/html'
-import React from 'react'
-
-// This file is web-only and used to configure the root HTML for every
-// web page during static rendering.
-// The contents of this function only run in Node.js environments and
-// do not have access to the DOM or browser APIs.
-export default function Root({ children }: { children: React.ReactNode }) {
- return (
-
-
-
-
-
-
- {/*
- Disable body scrolling on web. This makes ScrollView components work closer to how they do on native.
- However, body scrolling is often nice to have for mobile web. If you want to enable it, remove this line.
- */}
-
-
- {/* Using raw CSS styles as an escape-hatch to ensure the background color never flickers in dark-mode. */}
-
- {/* Add any additional elements that you want globally available on web... */}
-
- {children}
-
- )
-}
-
-const responsiveBackground = `
-body {
- background-color: #fff;
-}
-@media (prefers-color-scheme: dark) {
- body {
- background-color: #000;
- }
-}`
diff --git a/app/_layout.tsx b/app/_layout.tsx
index ac1ba16..ce33e3b 100644
--- a/app/_layout.tsx
+++ b/app/_layout.tsx
@@ -1,111 +1,11 @@
-import { MaterialCommunityIcons } from '@expo/vector-icons'
-import {
- useFonts,
- JetBrainsMono_400Regular,
-} from '@expo-google-fonts/jetbrains-mono'
-import { NotoSans_400Regular } from '@expo-google-fonts/noto-sans'
-import { Redirect, SplashScreen, Stack, useRootNavigationState, useRouter } from 'expo-router'
-import * as SecureStore from 'expo-secure-store'
-import React from 'react'
-import { Platform, useColorScheme } from 'react-native'
-import { PaperProvider } from 'react-native-paper'
-
import { AuthProvider, useAuth } from '@/lib/providers/auth'
-import { Setting } from '@/lib/types'
-import { StackHeader, Themes } from '@/lib/ui'
-export {
- // Catch any errors thrown by the Layout component.
- ErrorBoundary,
-} from 'expo-router'
-
-export const unstable_settings = {
- // Ensure that reloading on `/modal` keeps a back button present.
- initialRouteName: '(tabs)',
-}
-
-// Prevent the splash screen from auto-hiding before asset loading is complete.
-SplashScreen.preventAutoHideAsync()
-
-const RootLayout = () => {
- const [loaded, error] = useFonts({
- NotoSans_400Regular,
- JetBrainsMono_400Regular,
- ...MaterialCommunityIcons.font,
- })
-
- // Get authentication state
- const rootNavigationState = useRootNavigationState()
-
- // Expo Router uses Error Boundaries to catch errors in the navigation tree.
- React.useEffect(() => {
- if (error) throw error
- }, [error])
-
- React.useEffect(() => {
- if (loaded) {
- SplashScreen.hideAsync()
- }
- }, [loaded])
-
- // Make sure we have the navigation state before showing content
- if (!loaded || !rootNavigationState) {
- return null
- }
-
- return
-}
-
-const RootLayoutNav = () => {
- const colorScheme = useColorScheme()
- const [settings, setSettings] = React.useState({
- theme: 'auto',
- color: 'default',
- })
-
- // Load settings from the device
- React.useEffect(() => {
- SecureStore.getItemAsync('settings').then((result) => {
- if (result === null) {
- SecureStore.setItemAsync('settings', JSON.stringify(settings)).then(
- (res) => console.log(res),
- )
- }
-
- setSettings(JSON.parse(result ?? JSON.stringify(settings)))
- })
-
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [])
+import { Redirect, Slot } from 'expo-router'
+export default function Root() {
return (
-
- (
-
- ),
- }}
- >
-
-
-
-
-
-
+
)
}
-
-export default RootLayout
diff --git a/app/login.tsx b/app/login.tsx
new file mode 100644
index 0000000..80efcd9
--- /dev/null
+++ b/app/login.tsx
@@ -0,0 +1,38 @@
+import { useAuth } from '@/lib/providers/auth'
+import { useRouter } from 'expo-router'
+import { useEffect } from 'react'
+import { View } from 'react-native'
+import { Button, Text } from 'react-native-paper'
+
+function Login() {
+ const { signIn, user } = useAuth()
+ const router = useRouter()
+
+ useEffect(() => {
+ if (user) {
+ console.log('redicrecting')
+ router.push('/')
+ }
+ }, [user])
+ useEffect(() => {
+ console.log('login page')
+ }, [])
+ return (
+
+ Welcome
+
+
+ )
+}
+
+export default Login
diff --git a/lib/providers/auth.tsx b/lib/providers/auth.tsx
index 530916c..1bc3c4c 100644
--- a/lib/providers/auth.tsx
+++ b/lib/providers/auth.tsx
@@ -7,6 +7,8 @@ import {
useContext,
useEffect,
useState,
+ useCallback,
+ useMemo,
type ReactNode,
} from 'react'
@@ -17,21 +19,21 @@ interface AuthProviderProps {
export function AuthProvider({ children }: AuthProviderProps) {
const [user, setUser] = useState(null)
- GoogleSignin.configure({
- scopes: [
- 'https://www.googleapis.com/auth/classroom.courses.readonly',
- 'https://www.googleapis.com/auth/classroom.coursework.me',
- 'https://www.googleapis.com/auth/classroom.coursework.students',
- 'https://www.googleapis.com/auth/classroom.coursework.students.readonly',
- 'https://www.googleapis.com/auth/classroom.coursework.me.readonly',
- ],
- })
-
useEffect(() => {
+ GoogleSignin.configure({
+ scopes: [
+ 'https://www.googleapis.com/auth/classroom.courses.readonly',
+ 'https://www.googleapis.com/auth/classroom.coursework.me',
+ 'https://www.googleapis.com/auth/classroom.coursework.students',
+ 'https://www.googleapis.com/auth/classroom.coursework.students.readonly',
+ 'https://www.googleapis.com/auth/classroom.coursework.me.readonly',
+ ],
+ })
+
setUser(GoogleSignin.getCurrentUser())
}, [])
- const signIn = async () => {
+ const signIn = useCallback(async () => {
try {
await GoogleSignin.hasPlayServices()
const userInfo = await GoogleSignin.signIn()
@@ -40,19 +42,24 @@ export function AuthProvider({ children }: AuthProviderProps) {
} catch (error) {
console.error(error)
}
- }
+ }, [])
- const signOut = async () => {
+ const signOut = useCallback(async () => {
try {
await GoogleSignin.signOut()
setUser(null)
} catch (error) {
console.error(error)
}
- }
+ }, [])
+
+ const authContextValue = useMemo(
+ () => ({ user, signIn, signOut }),
+ [user, signIn, signOut],
+ )
return (
-
+
{children}
)
diff --git a/tsconfig.json b/tsconfig.json
index ce27fee..f40d80f 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -6,5 +6,5 @@
"@/*": ["./*"]
}
},
- "include": ["**/*.ts", "**/*.tsx", ".expo/types/**/*.ts", "expo-env.d.ts"]
+ "include": ["**/*.ts", "**/*.tsx", ".expo/types/**/*.ts", "expo-env.d.ts", "app/(app)/plushtml.old"]
}