Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into dev-onting
  • Loading branch information
onting committed Aug 6, 2020
2 parents 36dbe29 + 8fa1bb6 commit 5022a17
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 38 deletions.
16 changes: 13 additions & 3 deletions App.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import AsyncStorage from '@react-native-community/async-storage';
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, View, TouchableHighlight } from 'react-native';
import { StyleSheet, View, Text, TouchableHighlight } from 'react-native';
import { Entypo, Octicons, AntDesign } from '@expo/vector-icons';
import { NavigationContainer } from '@react-navigation/native';
import LoginView from './compo/loginview';
Expand All @@ -13,6 +13,7 @@ import ProfileView from './compo/profileview';
const MainView = () => {
const [state, setState] = React.useState('feed');
const target = {feed: <FeedView />, org: <OrgView />, notice: <NoticeView />, profile: <ProfileView />}[state];
const title = {feed: '피드', org: '단체', notice: '알림', profile: '내정보'}[state];

return(
<View style={{
Expand All @@ -22,10 +23,19 @@ const MainView = () => {
<View style={{
flex: 1,
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'cornsilk',
}}>
<View style={{
paddingHorizontal: 30,
paddingVertical: 20,
backgroundColor: 'white'
}}>
<Text style={{
fontSize: 30,
}}>
{title}
</Text>
</View>
{target}
</View>
<View style={{
Expand Down
12 changes: 11 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@
"**/*"
],
"ios": {
"supportsTablet": true
"supportsTablet": true,
"infoPlist": {
"NSAppTransportSecurity": {
"NSAllowsArbitraryLoads": true
}
}
},
"android": {
"permissions": [
"ACCESS_NETWORK_STATE"
]
},
"web": {
"favicon": "./assets/favicon.png"
Expand Down
67 changes: 36 additions & 31 deletions compo/loginview.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,46 @@
import AsyncStorage from '@react-native-community/async-storage';
import React from 'react';
import { StyleSheet, Text, View, TextInput, Button, TouchableHighlight, Alert } from 'react-native';
import hostaddr from '../config'
import {hostaddr} from '../config'
import * as SecureStore from 'expo-secure-store';


export default function LoginView(props) {
const [username, setUsername] = React.useState('');
const [password, setPassword] = React.useState('');

const login = () => {
props.onLogin();
fetch(hostaddr + '/login', {
method: 'POST',
credentials: 'same-origin',
body: JSON.stringify({
username: username,
password: password
}),
}).then(res => {
if(!res.ok){
Alert.alert(
'로그인 실패',
'아이디와 비밀번호를 확인해주세요',
[
{
text: '닫기',
style: 'cancle',
},
],
{cancelable: false},
);
}
else{
AsyncStorage.setItem('username', username);
}
return res.text();
}).then(text => console.log(text))
.catch((err) => {
const login = async() => {
// props.onLogin();/

try{
let loginHeaders = new Headers();
loginHeaders.append('Content-Type', 'application/json');
let res = await fetch(hostaddr + '/user/login', {
method: 'POST',
headers: loginHeaders,
body: JSON.stringify({
"username": username,
"password": password,
})
});
if(!res.ok){
Alert.alert(
'로그인 실패',
'아이디와 비밀번호를 확인해주세요',
[
{
text: '닫기',
style: 'cancle',
},
],
{cancelable: false},
);
}
else{
await AsyncStorage.setItem('username', username);
await SecureStore.setItemAsync("session", res.headers.get("Set-Cookie"))
}
}catch(err){
Alert.alert(
'로그인 실패',
String(err),
Expand All @@ -48,7 +53,7 @@ export default function LoginView(props) {
{cancelable: false},
);
console.log(err);
});
}
}

return (
Expand Down
54 changes: 51 additions & 3 deletions compo/orgview.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,61 @@
import React from 'react';
import { View } from 'react-native';
import { ScrollView, Text, View, Image, TouchableHighlight, useWindowDimensions } from 'react-native';
import hostaddr from '../config'

const OrgView = () => {
const OrgIcon = (props) => {
return (
<View>

<TouchableHighlight>
<Image source={require('../assets/favicon.png')} />
</TouchableHighlight>
<Text>
이름
</Text>
<Text>
테그, 테그
</Text>
</View>
);
}

const OrgView = () => {
const width = useWindowDimensions().width;
const count = 10;
const fit = parseInt(width / 120);
let contents = [];

for(let i = 0; i < count / fit; i++)
{
let row = [];
for(let j = 0; (j < fit) && (i * fit + j < count); j++)
{
row.push(<OrgIcon />);
}

contents.push(
<View style={{
flex: 1,
flexDirection: 'row',
justifyContent: 'space-around',
alignItems: 'center',
marginHorizontal: 10,
marginVertical: 20,
}}>
{row}
</View>
);
}

return (
<ScrollView style={{
flex: 1,
flexDirection: 'column',
marginHorizontal: 20,
marginVertical: 10,
}}>
{contents}
</ScrollView>
);
};

export default OrgView;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@react-navigation/bottom-tabs": "^5.7.3",
"@react-navigation/native": "^5.7.2",
"expo": "~38.0.8",
"expo-secure-store": "~9.0.1",
"expo-status-bar": "^1.0.2",
"react": "~16.11.0",
"react-dom": "~16.11.0",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2731,6 +2731,11 @@ expo-permissions@~9.0.1:
resolved "https://registry.yarnpkg.com/expo-permissions/-/expo-permissions-9.0.1.tgz#dc10b58654bbe39bbbed5827369942b01b08055e"
integrity sha512-CosJgy8XQRN/OFG2JTQDcFxz3XTGi27coCMym/hVXWtQfk0z6PwdRG5IXHfLGuSckwIcgmirrwm2+Zc0X3MmNg==

expo-secure-store@~9.0.1:
version "9.0.1"
resolved "https://registry.yarnpkg.com/expo-secure-store/-/expo-secure-store-9.0.1.tgz#e564a2d5392cd1ab883b9b6a7e261c1815d15788"
integrity sha512-+XgSZTelr57AyIJIGPcB/+QMrrm7wd8KFaF+TD8eJFwEN3B7s+tZyNoPH2JaJkAY0yh9FqcGG4kE3/YgK7GY3Q==

expo-splash-screen@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/expo-splash-screen/-/expo-splash-screen-0.3.1.tgz#4dd79d9d1ab8135281f7cc5889a68e3003223f37"
Expand Down

0 comments on commit 5022a17

Please sign in to comment.