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

Upgrade firebase and complete AuthScreen. #43

Merged
merged 9 commits into from
Feb 7, 2023
Merged
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
13 changes: 10 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module.exports = {
env: {
browser: true,
es2021: true,
node: true,
},
Expand All @@ -12,17 +11,25 @@ module.exports = {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 12,
ecmaVersion: 'latest',
sourceType: 'module',
},
plugins: [
'react',
'react-native',
'unused-imports',
],
rules: {
'react/jsx-props-no-spreading': 'off',
'react/prop-types': 'off',
'react-native/no-unused-styles': 2,
'no-unused-vars': 'off',
'unused-imports/no-unused-imports': 'error',
'unused-imports/no-unused-vars': [
'warn',
{
vars: 'all', varsIgnorePattern: '^_', args: 'after-used', argsIgnorePattern: '^_',
},
],
},
root: true,
};
36 changes: 0 additions & 36 deletions .github/ISSUE_TEMPLATE/bug_report.md

This file was deleted.

20 changes: 0 additions & 20 deletions .github/ISSUE_TEMPLATE/feature_request.md

This file was deleted.

213 changes: 42 additions & 171 deletions App.jsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,27 @@
import React, { useState } from 'react';
import { View, Dimensions } from 'react-native';
import { initializeApp, getApp } from 'firebase/app';
import { getAuth, onAuthStateChanged } from 'firebase/auth';

import firebase from 'firebase';
import { NavigationContainer } from '@react-navigation/native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import {
NativeBaseProvider,
Box,
Text,
Heading,
VStack,
FormControl,
Input,
Link,
Button,
Icon,
HStack,
Center,
Pressable,
Container,
TouchableOpacity,
} from 'native-base';
import {
MaterialCommunityIcons,
MaterialIcons,
Ionicons,
} from '@expo/vector-icons';
import AwesomeIcon from '@expo/vector-icons/FontAwesome5';

import AuthScreen from './screens/Auth';
import DashboardScreen from './screens/Dashboard';
import { AuthScreen } from './screens/Auth';
import CalendarScreen from './screens/Calendar';
import MapScreen from './screens/Map';
import SaleScreen from './screens/Sale';
import EventScreen from './screens/Event';




const firebaseConfig = {
apiKey: 'AIzaSyA8GH6yj1i4gJM0H_ZTsurYG3Dqn4-nIS8',
authDomain: 'ncu-app-test.firebaseapp.com',
Expand All @@ -47,124 +31,15 @@ const firebaseConfig = {
appId: '1:739839700130:web:37591d0118a440488cfbfb',
};
const Tab = createBottomTabNavigator();
function MainApp() {
const [selected, setSelected] = React.useState(1);

const renderSelectedTab = () => {
switch (selected) {
case 0:
return <DashboardScreen />;
break;
case 1:
return <CalendarScreen />;
break;
case 2:
return <EventScreen />;
break;
case 3:
return <MapScreen />;
break;
case 4:
return <SaleScreen />;
break;
default:
}
};


// activeTintColor: '#E5EBF1',
// inactiveTintColor: '#28527A',
// activeBackgroundColor: '#28527A',
// inactiveBackgroundColor: '#E5EBF1',
return (
<NativeBaseProvider>

<Box flex={1} bg="white" safeAreaTop width="100%" alignSelf="center">
<Center flex={1}>{renderSelectedTab()}</Center>
<HStack bg="#E5EBF1" alignItems="center" safeAreaBottom shadow={6}>
<Pressable py="2" flex={1} onPress={() => setSelected(0)} bg={selected === 0 ? '#28527A' : '#E5EBF1'}>
<Center>
<Icon
as={MaterialCommunityIcons}
name="home-outline"
color={selected === 0 ? '#E5EBF1' : '#28527A'}
size="sm"
/>
<Text color={selected === 0 ? '#E5EBF1' : '#28527A'} fontSize="12">
首頁
</Text>
</Center>
</Pressable>

<Pressable py="2" flex={1} onPress={() => setSelected(1)} bg={selected === 1 ? '#28527A' : '#E5EBF1'}>
<Center>
<Icon
as={MaterialCommunityIcons}
name="calendar-month"
color={selected === 1 ? '#E5EBF1' : '#28527A'}

size="sm"
/>
<Text color={selected === 1 ? '#E5EBF1' : '#28527A'} fontSize="12">
行事曆
</Text>
</Center>
</Pressable>
<Pressable py="2" flex={1} onPress={() => setSelected(2)} bg={selected === 2 ? '#28527A' : '#E5EBF1'}>
<Center>
<Icon
as={Ionicons}
name="game-controller-outline"
color={selected === 2 ? '#E5EBF1' : '#28527A'}
size="sm"
/>
<Text color={selected === 2 ? '#E5EBF1' : '#28527A'} fontSize="12">
活動
</Text>
</Center>
</Pressable>
<Pressable py="2" flex={1} onPress={() => setSelected(3)} bg={selected === 3 ? '#28527A' : '#E5EBF1'}>
<Center>
<Icon
as={MaterialCommunityIcons}
name="map-outline"
color={selected === 3 ? '#E5EBF1' : '#28527A'}
size="sm"
/>
<Text color={selected === 3 ? '#E5EBF1' : '#28527A'} fontSize="12">
地圖
</Text>
</Center>
</Pressable>
<Pressable py="2" flex={1} onPress={() => setSelected(4)} bg={selected === 4 ? '#28527A' : '#E5EBF1'}>
<Center>
<Icon
as={MaterialCommunityIcons}
name="cart-outline"
color={selected === 4 ? '#E5EBF1' : '#28527A'}
size="sm"
/>
<Text color={selected === 4 ? '#E5EBF1' : '#28527A'} fontSize="12">
拍賣
</Text>
</Center>
</Pressable>
</HStack>
</Box>
</NativeBaseProvider>
);
}

const CustomTabBar = ({ state, descriptors, navigation }) => {
const [selected, setSelected] = React.useState(1);
function CustomTabBar({ state, descriptors, navigation }) {
return (
<HStack bg="#E5EBF1" alignItems="center" safeAreaBottom shadow={6}>
{state.routes.map((route, index) => {
{state.routes.map((route, index) => {
const { options } = descriptors[route.key];
const label =
options.tabBarLabel !== undefined
? options.tabBarLabel
: options.title !== undefined
const label = options.tabBarLabel !== undefined
? options.tabBarLabel
: options.title !== undefined
? options.title
: route.name;

Expand All @@ -182,19 +57,17 @@ const CustomTabBar = ({ state, descriptors, navigation }) => {
};

const icon_name = {
'首頁': 'home-outline',
'行事曆':'calendar-month',
'活動':'game-controller-outline',
'地圖':'map-outline',
'拍賣':'cart-outline'
行事曆: 'calendar-month',
活動: 'game-controller-outline',
地圖: 'map-outline',
};

return (
<Pressable py="2" flex={1} onPress={onPress} bg={isFocused? '#28527A' : '#E5EBF1'}>

<Pressable py="2" flex={1} onPress={onPress} bg={isFocused ? '#28527A' : '#E5EBF1'}>
<Center>
<Icon
as={label === '活動' ? Ionicons : MaterialCommunityIcons }
as={label === '活動' ? Ionicons : MaterialCommunityIcons}
name={icon_name[label]}
color={isFocused ? '#E5EBF1' : '#28527A'}
size="sm"
Expand All @@ -204,48 +77,46 @@ const CustomTabBar = ({ state, descriptors, navigation }) => {
</Text>
</Center>
</Pressable>

);
})}
</HStack>
)
</HStack>
);
}

export default function App() {
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig);
} else {
firebase.app();
}
initializeApp(firebaseConfig);

const [auth, setAuth] = useState();
firebase.auth().onAuthStateChanged((user) => {
setAuth(user);
const [authState, setAuthState] = useState();
const auth = getAuth(getApp());
onAuthStateChanged(auth, (user) => {
setAuthState(user);
});

if (auth === undefined) {
return <View />;
if (authState === null) {
return (
<NativeBaseProvider>
<AuthScreen />
</NativeBaseProvider>
);
}

return (
/* { auth ? <MainApp /> : <AuthScreen />} */
<NativeBaseProvider>
<NavigationContainer>
<Tab.Navigator
screenOptions={{
headerShown: false,
}}
tabBar={(props) => (
<CustomTabBar {...props} />
)}
>
<Tab.Screen name="首頁" component={DashboardScreen}/>
<Tab.Screen name="行事曆" component={CalendarScreen} />
<Tab.Screen name="活動" component={EventScreen} />
<Tab.Screen name="地圖" component={MapScreen} />
<Tab.Screen name="拍賣" component={SaleScreen} />
</Tab.Navigator>
</NavigationContainer>
<NavigationContainer>
<Tab.Navigator
screenOptions={{
headerShown: false,
}}
tabBar={(props) => (
<CustomTabBar {...props} />
)}
>
<Tab.Screen name="行事曆" component={CalendarScreen} />
<Tab.Screen name="活動" component={EventScreen} />
<Tab.Screen name="地圖" component={MapScreen} />
</Tab.Navigator>
</NavigationContainer>
</NativeBaseProvider>
);
}
7 changes: 3 additions & 4 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"userInterfaceStyle": "light",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
Expand All @@ -17,6 +18,7 @@
"**/*"
],
"ios": {
"supportsTablet": true,
"bundleIdentifier": "tw.edu.ncu.app",
"buildNumber": "1.0.0"
},
Expand All @@ -35,9 +37,6 @@
},
"web": {
"favicon": "./assets/favicon.png"
},
"facebookScheme": "fb717771508969062",
"facebookAppId": "717771508969062",
"facebookDisplayName": "NCU App"
}
}
}
Loading