Skip to content

Commit b0d314d

Browse files
committed
Updates
1 parent 562ca82 commit b0d314d

File tree

4 files changed

+52
-15
lines changed

4 files changed

+52
-15
lines changed

android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<uses-sdk
1010
android:minSdkVersion="16"
11-
android:targetSdkVersion="22" />
11+
android:targetSdkVersion="23" />
1212

1313
<application
1414
android:name=".MainApplication"

app/redux/modules/navigation.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ const reset = (state, payload = {}) => {
4444

4545
export const reducer = createReducer({
4646
[REHYDRATE]: (state, {payload}) => {
47-
console.log('REHYDRATE called for navigation', payload);
4847
const {navigation} = payload;
4948
const index = navigation ? navigation.index : 0;
5049
// return NavUtils.reset(state, [routes['welcome']]);

app/views/Database/index.js

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { Children as C } from 'react';
22

33
import {
44
View,
@@ -13,27 +13,55 @@ export class Database extends React.Component {
1313
super(props);
1414

1515
const {firestack} = this.props;
16-
const db = firestack.database;
17-
this.db = db;
18-
db.setPersistence(true);
16+
// firestack.database.setPersistence(false);
17+
18+
this.state = {
19+
children: []
20+
}
1921
}
2022

2123
componentDidMount() {
24+
const {firestack} = this.props;
25+
26+
const pRef = firestack.presence
27+
// .on('/users/connected')
28+
.setOnline('auser')
29+
.onConnect(ref => {
30+
console.log('connected!', ref)
31+
})
32+
2233
const roomId = 'roomId';
23-
const ref = this.db.ref('chat-messages').child(roomId);
24-
ref.keepSynced(true);
25-
ref.orderByKey().limitToLast(3).once('value').then(snapshot => {
26-
console.log('snapshot ->', snapshot);
27-
});
34+
const ref = firestack.database.ref('chat-messages').child(roomId);
35+
ref.on('value', (snapshot) => {
36+
const val = snapshot.val();
37+
const children = Object.keys(val)
38+
.map(key => {
39+
return {...val[key], key};
40+
});
41+
this.setState({children})
42+
})
43+
// ref.keepSynced(true);
44+
// ref.orderByKey().limitToLast(3).on('value', snapshot => {
45+
// const o = Object.keys(snapshot.val());
46+
// ref.child(o[0]).setAt({
47+
// from: 'me',
48+
// msg: 'Hello you guys'
49+
// })
50+
// });
51+
}
52+
53+
componentWillUnmount() {
54+
const {firestack} = this.props;
55+
firestack.presence.setOffline();
56+
firestack.database.cleanup();
2857
}
2958

3059
render() {
3160
return (
3261
<View style={appStyles.scene}>
33-
<Text>Database examples</Text>
34-
<Text>Database examples</Text>
35-
<Text>Database examples</Text>
36-
<Text>Database examples</Text>
62+
{this.state.children.map(c => {
63+
return <Text key={c.key}>{c.msg}</Text>
64+
})}
3765
</View>
3866
)
3967
}

app/views/Presence/Demos/Online.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ export class Online extends React.Component {
1111

1212
componentWillMount() {
1313
const {firestack} = this.props;
14+
const presence = firestack.presence;
15+
16+
console.log('presence', presence)
17+
presence
18+
.on('users/connections')
19+
.setOnlineFor('auser')
20+
.onConnect(ref => {
21+
console.log('connected', ref);
22+
ref.onDisconnect().remove();
23+
});
1424
}
1525

1626
_sendHi() {

0 commit comments

Comments
 (0)