Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/setup project #1

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
.eslintrc.js
32 changes: 32 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint-disable no-undef */
module.exports = {
env: {
browser: true,
es2021: true,
node: true,
},
extends: [
'airbnb',
'plugin:react/recommended',
'plugin:react-native/all',
],
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 12,
sourceType: 'module',
},
plugins: [
'react',
'react-native',
'import',
'jsx-a11y',
],
rules: {
'@typescript-eslint/no-var-requires': 'off',
'no-undef': 'off',
'react/jsx-filename-extension': [1, { extensions: ['.js', '.jsx'] }],
'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
},
};
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ web-build/

# macOS
.DS_Store

.idea/

# @generated expo-cli sync-2b81b286409207a5da26e14c78851eb30d8ccbdb
# The following patterns were generated by expo-cli

expo-env.d.ts
# @end expo-cli
37 changes: 0 additions & 37 deletions app/(tabs)/_layout.tsx

This file was deleted.

102 changes: 0 additions & 102 deletions app/(tabs)/explore.tsx

This file was deleted.

70 changes: 0 additions & 70 deletions app/(tabs)/index.tsx

This file was deleted.

1 change: 1 addition & 0 deletions app/+html.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from 'react';
import { ScrollViewStyleReset } from 'expo-router/html';
import { type PropsWithChildren } from 'react';

Expand Down
4 changes: 2 additions & 2 deletions app/+not-found.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { Link, Stack } from 'expo-router';
import { StyleSheet } from 'react-native';

import { ThemedText } from '@/components/ThemedText';
import { ThemedView } from '@/components/ThemedView';

Expand All @@ -9,7 +9,7 @@ export default function NotFoundScreen() {
<>
<Stack.Screen options={{ title: 'Oops!' }} />
<ThemedView style={styles.container}>
<ThemedText type="title">This screen doesn't exist.</ThemedText>
<ThemedText type="title">This screen does not exist.</ThemedText>
<Link href="/" style={styles.link}>
<ThemedText type="link">Go to home screen!</ThemedText>
</Link>
Expand Down
38 changes: 30 additions & 8 deletions app/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,59 @@
import React from 'react';
import { DarkTheme, DefaultTheme, ThemeProvider } from '@react-navigation/native';
import { useFonts } from 'expo-font';
import { Stack } from 'expo-router';
import * as SplashScreen from 'expo-splash-screen';
import { useEffect } from 'react';
import { useEffect, useState } from 'react';
import 'react-native-reanimated';

import Login from './login/index';
import Home from './home/index';
import { useColorScheme } from '@/hooks/useColorScheme';
import AsyncStorage from '@react-native-async-storage/async-storage';

// Prevent the splash screen from auto-hiding before asset loading is complete.
SplashScreen.preventAutoHideAsync();

export default function RootLayout() {
const colorScheme = useColorScheme();
const [loggedIn, setLoggedIn] = useState<boolean | null>(null);
const [loaded] = useFonts({
SpaceMono: require('../assets/fonts/SpaceMono-Regular.ttf'),
});

useEffect(() => {
const checkLoginStatus = async () => {
const token = await AsyncStorage.getItem('userToken');
setLoggedIn(token !== null);
};

checkLoginStatus();
}, []);

useEffect(() => {
if (loaded) {
SplashScreen.hideAsync();
}
}, [loaded]);

if (!loaded) {
const handleLogout = async () => {
try {
await AsyncStorage.clear();
setLoggedIn(false);
} catch (e) {
console.error('Failed to clear the async storage', e);
}
};

if (!loaded || loggedIn === null) {
return null;
}

return (
<ThemeProvider value={colorScheme === 'dark' ? DarkTheme : DefaultTheme}>
<Stack>
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
<Stack.Screen name="+not-found" />
</Stack>
{!loggedIn ? (
<Login setLoggedIn={setLoggedIn} />
) : (
<Home onLogout={handleLogout} />
)}
</ThemeProvider>
);
}
24 changes: 24 additions & 0 deletions app/home/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// home/Home.tsx
import React from 'react';
import { View, Text, Button } from 'react-native';
import { styles } from './styles';

interface HomeProps {
onLogout: () => void;
}

const Home: React.FC<HomeProps> = ({ onLogout }) => {
return (
<View style={styles.container}>
<View style={styles.navbar}>
<Text style={styles.title}>Home</Text>
<Button title="Logout" onPress={onLogout} />
</View>
<View style={styles.content}>
<Text>Welcome to the home page!</Text>
</View>
</View>
);
};

export default Home;
Loading