Skip to content

Commit 0c5c97c

Browse files
authored
feat: login (#21)
feat: login
2 parents c4d80c2 + f6ad2fd commit 0c5c97c

File tree

21 files changed

+450
-241
lines changed

21 files changed

+450
-241
lines changed

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,19 @@
2525
"lint": "tslint -p ."
2626
},
2727
"dependencies": {
28+
"apollo-boost": "0.3.1",
2829
"bara": "2.4.0",
29-
"bara-react": "3.0.0",
30+
"bara-react": "3.1.0",
3031
"bara-react-icons": "1.1.0",
32+
"bara-react-yofi": "1.1.0",
3133
"electron-store": "3.2.0",
3234
"electron-updater": "4.0.6",
35+
"graphql": "14.3.0",
36+
"graphql-tag": "2.10.1",
3337
"jsonfile": "5.0.0",
3438
"mkdirp": "0.5.1",
3539
"react": "16.8.6",
40+
"react-apollo": "2.5.5",
3641
"react-app-polyfill": "0.2.2",
3742
"react-dom": "16.8.6",
3843
"react-native": "0.59.4",

src/App.tsx

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,70 @@
1-
import { BaraProvider, TouchableOpacity } from 'bara-react'
1+
import { BaraProvider, TouchableOpacity, useBarnState } from 'bara-react'
22
import React, { Component } from 'react'
33
import { Platform, StyleSheet, Text, View } from 'react-native'
44

5+
import { ApolloProvider } from 'react-apollo'
6+
import { client } from './graphql'
7+
58
import { Octicons as Icon } from 'bara-react-icons/es'
69

7-
import { SideBar, SideBarItem } from './components/SideBar'
10+
import { LoginScreen } from './features/login'
11+
12+
import {
13+
SideBar,
14+
SideBarContent,
15+
SideBarItem,
16+
SideBarLayout,
17+
SideBarSeparator,
18+
SideBarSpace,
19+
} from 'bara-react-yofi'
820
import { GlobalStyles } from './GlobalStyles'
921

1022
interface Props {}
11-
export default class App extends Component<Props> {
12-
render() {
13-
return (
14-
<BaraProvider>
23+
export const App = () => {
24+
const [horizontal] = useBarnState('horizontal', false)
25+
return (
26+
<BaraProvider>
27+
<ApolloProvider client={client}>
1528
<>
1629
<GlobalStyles />
17-
<View style={styles.container}>
18-
<SideBar
19-
horizontal={false}
20-
horizontalSide="bottom"
21-
verticalSide="left"
22-
>
23-
<SideBarItem name="home" iconMaterial="home" />
30+
<SideBarLayout
31+
horizontal={horizontal}
32+
horizontalSide="bottom"
33+
verticalSide="left"
34+
>
35+
<SideBar name="sidebar-demo" horizontal={horizontal}>
36+
<SideBarItem name="home" iconMaterial="home" label="Home" />
37+
<SideBarSeparator horizontal={horizontal} />
38+
<SideBarItem
39+
name="light-bulb"
40+
iconOcticon="light-bulb"
41+
label="Light"
42+
/>
43+
<SideBarSpace />
44+
<SideBarSeparator horizontal={horizontal} />
45+
<SideBarItem
46+
name="rotate"
47+
iconOcticon="screen-normal"
48+
label="Rotate"
49+
/>
2450
<SideBarItem
2551
name="settings"
2652
iconMaterial="settings"
2753
label="Settings"
2854
/>
2955
</SideBar>
30-
</View>
56+
<SideBarContent style={{ backgroundColor: '#ccc' }}>
57+
<LoginScreen />
58+
</SideBarContent>
59+
</SideBarLayout>
3160
</>
32-
</BaraProvider>
33-
)
34-
}
61+
</ApolloProvider>
62+
</BaraProvider>
63+
)
3564
}
3665

66+
export default App
67+
3768
const styles = StyleSheet.create({
3869
container: {
3970
alignItems: 'stretch',

src/bara.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
1-
import { useInitStream } from 'bara'
1+
import {
2+
addDebugListener,
3+
setBarnState,
4+
useBarn,
5+
useBarnStream,
6+
useInitStream,
7+
} from 'bara'
28
import { useComponentsStream } from 'bara-react'
39

4-
import { whenSideBarItemPress } from './components/SideBar'
10+
import { whenSideBarItemPress } from 'bara-react-yofi'
511
import { useWelcome } from './features/welcome'
612

713
export const useStreams = () => {
14+
useBarnStream({ horizontal: false })
815
useInitStream()
916
useComponentsStream()
1017
}
1118

1219
export const useTriggers = () => {
20+
let horizontal = false
1321
useWelcome()
14-
whenSideBarItemPress('settings')(() => {
15-
alert('Setting Pressed!')
22+
useBarn('horizontal', (h: boolean) => {
23+
horizontal = h
24+
})
25+
whenSideBarItemPress('rotate')(() => {
26+
if (horizontal) {
27+
setBarnState('horizontal', false)
28+
} else {
29+
setBarnState('horizontal', true)
30+
}
1631
})
1732
}
1833

src/components/Layout/api.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { setBarnState } from 'bara'
2+
import { useBarnState } from 'bara-react'
3+
import { useEffect } from 'react'
4+
import { Dimensions } from 'react-native'
5+
6+
export const BARN_REACT_DIMENSIONS_KEY = 'dev.barajs.react.dimensions'
7+
export const BARN_REACT_ORIENTATION_KEY = 'dev.barajs.react.orientation'
8+
9+
export function useDimensions() {
10+
const [dimensions, setDimensions] = useBarnState(BARN_REACT_DIMENSIONS_KEY, {
11+
screen: Dimensions.get('screen'),
12+
window: Dimensions.get('window'),
13+
})
14+
15+
useEffect(() => {
16+
Dimensions.addEventListener('change', setDimensions)
17+
return () => Dimensions.removeEventListener('change', setDimensions)
18+
}, [])
19+
20+
return dimensions
21+
}
22+
23+
export function useOrientation() {
24+
const dimensions = useDimensions()
25+
const [orientation] = useBarnState(BARN_REACT_ORIENTATION_KEY, {
26+
portrait: true,
27+
landscape: false,
28+
})
29+
}

src/components/Layout/context.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React, { useContext } from 'react'
2+
3+
export type OrientationType = 'landscape' | 'portrait'
4+
5+
export interface LayoutProviderState {
6+
appOrientation: OrientationType
7+
deviceOrientation: OrientationType
8+
}
9+
10+
// export const LayoutContext = React.createContext<LayoutProviderState>(
11+
// getLayoutState(),
12+
// )
13+
14+
// export const getLayoutState = () => {
15+
// const appOrientation = 'landscape'
16+
// const deviceOrientation = 'landscape'
17+
// return { appOrientation, deviceOrientation }
18+
// }

src/components/Layout/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './api'

src/components/SideBar/SideBarItem.tsx

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/components/SideBar/Sidebar.tsx

Lines changed: 0 additions & 90 deletions
This file was deleted.

src/components/SideBar/api.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/components/SideBar/index.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)