Skip to content

Commit f8327a2

Browse files
committed
setup router and login/signup
1 parent f14f017 commit f8327a2

23 files changed

+2187
-2532
lines changed
Lines changed: 25 additions & 0 deletions
Loading

client/src/components/App/App.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ import * as React from 'react'
22
import { ApolloProvider } from 'react-apollo'
33
import { ApolloProvider as ApolloHooksProvider } from 'react-apollo-hooks'
44
import Router from '../Router'
5+
import { UserProvider } from '../../screens/Login/UserContext'
56
import { client } from '../../utils/apollo'
67

78
const App = () => {
89
return (
910
<ApolloProvider client={client}>
1011
<ApolloHooksProvider client={client}>
11-
<Router />
12+
<UserProvider>
13+
<Router />
14+
</UserProvider>
1215
</ApolloHooksProvider>
1316
</ApolloProvider>
1417
)

client/src/components/Box/Box.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { View } from 'react-native'
2+
import styled from 'styled-components'
3+
4+
interface BoxProps {
5+
width?: string
6+
height?: number
7+
maxWidth?: number
8+
}
9+
10+
const Box = styled(View)<BoxProps>`
11+
width: ${props => props.width || '100%'};
12+
max-width: ${props => props.maxWidth || 600}px;
13+
height: ${props => props.height || 500}px;
14+
background: #edeef3;
15+
box-shadow: 0 100px 100px 0 rgba(0, 0, 0, 0.2);
16+
border-radius: 10px;
17+
`
18+
19+
export default Box

client/src/components/Box/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './Box'
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import * as React from 'react'
2+
import { Text, TouchableOpacity } from 'react-native'
3+
import styled from 'styled-components'
4+
5+
const Wrapper = styled(TouchableOpacity)`
6+
background: #575b7e;
7+
border-radius: 30px;
8+
text-align: center;
9+
box-shadow: 0 20px 30px 0 rgba(87, 91, 126, 0.3);
10+
padding: 17px 45px;
11+
`
12+
13+
const Label = styled(Text)`
14+
font-size: 18px;
15+
font-weight: 900;
16+
color: #ffffff;
17+
letter-spacing: -0.5px;
18+
`
19+
20+
interface ButtonProps {
21+
children: string
22+
onPress: () => void
23+
}
24+
25+
const Button = ({ children, onPress }: ButtonProps) => (
26+
<Wrapper onPress={onPress} activeOpacity={0.6}>
27+
<Label>{children}</Label>
28+
</Wrapper>
29+
)
30+
31+
export default Button
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './Button'

client/src/components/Input/Input.tsx

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import * as React from 'react'
2+
import { View, Text, TextInput, TextInputIOSProps } from 'react-native'
3+
import styled from 'styled-components'
4+
5+
const Base = styled(TextInput)`
6+
background: #ffffff;
7+
padding: 12px 20px;
8+
box-shadow: 0 13px 27px 0 rgba(0, 0, 0, 0.04);
9+
border-radius: 2.67px;
10+
font-size: 20px;
11+
font-weight: 900;
12+
color: #575b7e;
13+
letter-spacing: -0.91px;
14+
`
15+
16+
const Label = styled(Text)`
17+
margin-bottom: 8px;
18+
font-size: 13.33px;
19+
font-weight: 900;
20+
color: #575b7e;
21+
letter-spacing: -0.61px;
22+
`
23+
24+
interface InputProps {
25+
style?: any
26+
label?: string
27+
placeholder?: string
28+
value?: string
29+
onChangeText: (text: string) => void
30+
secure?: boolean
31+
textContentType?: TextInputIOSProps['textContentType']
32+
}
33+
34+
const Input = ({
35+
style,
36+
label,
37+
placeholder,
38+
value,
39+
onChangeText,
40+
secure,
41+
textContentType,
42+
}: InputProps) => (
43+
<View style={style}>
44+
{label && <Label>{label}</Label>}
45+
<Base
46+
value={value}
47+
onChangeText={onChangeText}
48+
placeholder={placeholder}
49+
placeholderTextColor="rgba(67, 91, 126, 0.3)"
50+
textContentType={textContentType}
51+
secureTextEntry={secure}
52+
/>
53+
</View>
54+
)
55+
56+
export default Input

client/src/components/Input/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './Input'
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
import { NativeRouter, Route as NativeRoute, Link as NativeLink } from 'react-router-native'
1+
import {
2+
NativeRouter,
3+
Route as NativeRoute,
4+
Link as NativeLink,
5+
Switch as NativeSwitch,
6+
Redirect as NativeRedirect,
7+
} from 'react-router-native'
28

39
export let Router = NativeRouter
410
export let Route = NativeRoute
511
export let Link = NativeLink
12+
export let Switch = NativeSwitch
13+
export let Redirect = NativeRedirect
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
import { BrowserRouter, Route as WebRoute, Link as WebLink } from 'react-router-dom'
1+
import {
2+
BrowserRouter,
3+
Route as WebRoute,
4+
Link as WebLink,
5+
Switch as WebSwitch,
6+
Redirect as WebRedirect,
7+
} from 'react-router-dom'
28

39
export let Router = BrowserRouter
410
export let Route = WebRoute
511
export let Link = WebLink
12+
export let Switch = WebSwitch
13+
export let Redirect = WebRedirect
Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,38 @@
11
import * as React from 'react'
2-
import { View, Text, StyleSheet } from 'react-native'
3-
import { Router, Route, Link } from './Router'
2+
import { Text } from 'react-native'
3+
import { Router, Route, Switch, Redirect, Link } from './Router'
4+
import Login from '../../screens/Login'
5+
import { useUserContext } from '../../screens/Login/UserContext'
46

57
const Home = () => <Text>Home</Text>
6-
const About = () => <Text>About</Text>
78

89
export default () => {
10+
const { userState, getUser } = useUserContext()
11+
React.useEffect(() => {
12+
getUser()
13+
}, [userState.user && userState.user.id])
914
return (
1015
<Router>
11-
<View style={styles.container}>
12-
<View style={styles.nav}>
13-
<Link to="/">
14-
<Text>Home</Text>
15-
</Link>
16-
<Link to="/about">
17-
<Text>About</Text>
18-
</Link>
19-
</View>
20-
21-
<Route exact path="/" component={Home} />
22-
<Route path="/about" component={About} />
23-
</View>
16+
{userState.loggingIn ? null : userState.user ? (
17+
<Route
18+
path="/"
19+
render={() => (
20+
<Switch>
21+
<Route path="/" exact component={Home} />
22+
{/* <Route path="/policies" component={Policies} /> */}
23+
<Route path="*" render={() => <Redirect to="/" />} />
24+
</Switch>
25+
)}
26+
/>
27+
) : (
28+
<Switch>
29+
<Route path="/login" component={Login} />
30+
<Route path="/signup" component={Login} />
31+
<Route path="*" render={() => <Redirect to="/login" />} />
32+
</Switch>
33+
)}
2434
</Router>
2535
)
2636
}
2737

28-
const styles = StyleSheet.create({
29-
container: {
30-
alignItems: 'center',
31-
backgroundColor: '#F5FCFF',
32-
flex: 1,
33-
justifyContent: 'center',
34-
},
35-
nav: {
36-
flexDirection: 'row',
37-
justifyContent: 'space-around',
38-
},
39-
})
38+
export { Router, Route, Switch, Redirect, Link }

0 commit comments

Comments
 (0)