Skip to content

Commit 3655517

Browse files
committed
Firebase updated to v3.9.0. More material example updates.
* Material example updates * /projects is now protected route * pushWithMeta is used in projects * comments updated
1 parent e89e381 commit 3655517

File tree

10 files changed

+5591
-57
lines changed

10 files changed

+5591
-57
lines changed

docs/api/compose.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ Middleware that handles configuration (placed in redux's
2525
changes. Argument Pattern: `(authData, firebase, dispatch)`
2626
- `config.onRedirectResult` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Function run when redirect
2727
result is returned. Argument Pattern: `(authData, firebase, dispatch)`
28+
- `config.customAuthParameters` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Object for setting which
29+
30+
customAuthParameters are passed to external auth providers.
2831
- `config.profileFactory` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Factory for modifying how user profile is saved.
2932
- `config.uploadFileDataFactory` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Factory for modifying
3033
how file meta data is written during file uploads
@@ -63,4 +66,18 @@ const createStoreWithFirebase = compose(
6366
const store = createStoreWithFirebase(rootReducer, initialState)
6467
```
6568

69+
_Custom Auth Parameters_
70+
71+
```javascript
72+
// Follow Setup example with the following config:
73+
const config = {
74+
customAuthParameters: {
75+
google: {
76+
// prompts user to select account on every google login
77+
prompt: 'select_account'
78+
}
79+
}
80+
}
81+
```
82+
6683
Returns **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** That accepts a component a returns a wrapped version of component

docs/api/helpers.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ Detect whether items are loaded yet or not
99
**Examples**
1010

1111
```javascript
12-
import React, { Component, PropTypes } from 'react'
12+
import React, { Component } from 'react'
13+
import PropTypes from 'prop-types'
1314
import { connect } from 'react-redux'
1415
import { firebaseConnect, isLoaded, dataToJS } from 'react-redux-firebase'
1516
```
@@ -28,7 +29,8 @@ Detect whether items are empty or not
2829
**Examples**
2930

3031
```javascript
31-
import React, { Component, PropTypes } from 'react'
32+
import React, { Component } from 'react'
33+
import PropTypes from 'prop-types'
3234
import { connect } from 'react-redux'
3335
import { firebaseConnect, isEmpty, dataToJS } from 'react-redux-firebase'
3436
```

docs/queries.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ Limit query results to include a range starting at a specific number
128128

129129
**Internal Method**: [ `limitToLast`](https://firebase.google.com/docs/reference/js/firebase.database.Query#limitToLast)
130130

131-
#### Example
131+
#### Examples
132132

133133
1. Starting at the fifth item
134134
```js
@@ -146,6 +146,9 @@ Limit query results to include a range starting at a specific number
146146
```
147147

148148
## endAt
149+
150+
#### Examples
151+
1. Usage with startAt
149152
```js
150153
@firebaseConnect([
151154
'todos#orderByChild=added&startAt=1&endAt=5'
@@ -156,6 +159,14 @@ Limit query results to include a range starting at a specific number
156159
## equalTo
157160
Limit query results with parameter equal to previous query method (i.e when used with orderByChild, it limits results with child equal to provided value). Internally runs [Firebase's `equalTo`](https://firebase.google.com/docs/reference/js/firebase.database.Query#equalTo).
158161

162+
### Parsing
163+
The following are internally parsed:
164+
* `null`
165+
* `boolean`
166+
* `number`
167+
168+
This means the actual value will be parsed instead of the string containing the value. If you do not want this to happen, look at the `notParsed` query parameter below.
169+
159170
#### Examples
160171
1. Order by child parameter
161172
```js
@@ -171,7 +182,6 @@ Can be used to keep internal parsing from happening. Useful when attempting to s
171182

172183
#### Examples
173184
1. Order by child parameter equal to a number string. Equivalent of searching for `'123'` (where as not using `notParsed` would search for children equal to `123`)
174-
175185
```js
176186
@firebaseConnect([
177187
{

examples/complete/material/src/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const firebase = {
1313
export const reduxFirebase = {
1414
userProfile: 'users', // root that user profiles are written to
1515
enableLogging: false, // enable/disable Firebase Database Logging
16-
updateProfileOnLogin: false // enable/disable updating of profile on login
16+
updateProfileOnLogin: false, // enable/disable updating of profile on login
1717
// profileDecorator: (userData) => ({ email: userData.email }) // customize format of user profile
1818
}
1919

examples/complete/material/src/routes/Home/components/TodoItem/TodoItem.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default class TodoItem extends Component {
3838
{todo.text}
3939
</span><br />
4040
<span className='TodoItem-Owner'>
41-
{
41+
Owner: {
4242
isObject(todo.owner)
4343
? todo.owner.displayName || todo.owner.username
4444
: todo.owner || 'No Owner'

examples/complete/material/src/routes/Home/containers/HomeContainer.js

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import {
77
firebaseConnect,
88
isLoaded,
99
pathToJS,
10-
dataToJS,
11-
// orderedToJS, // needed for ordered list
12-
populatedDataToJS // needed for populated list
10+
// dataToJS, // needed for full list and once
11+
orderedToJS, // needed for ordered list
12+
// populatedDataToJS // needed for populated list
1313
} from 'react-redux-firebase'
1414
import CircularProgress from 'material-ui/CircularProgress'
1515
import Snackbar from 'material-ui/Snackbar'
@@ -20,23 +20,22 @@ import TodoItem from '../components/TodoItem'
2020
import NewTodoPanel from '../components/NewTodoPanel'
2121
import classes from './HomeContainer.scss'
2222

23-
const populates = [
24-
{ child: 'owner', root: 'users', keyProp: 'key' }
25-
]
23+
// const populates = [{ child: 'owner', root: 'users', keyProp: 'uid' }]
2624

2725
@firebaseConnect([
2826
// 'todos' // sync full list of todos
29-
// { path: '/projects', type: 'once' } // for loading once instead of binding
30-
// { path: 'todos', queryParams: ['limitToFirst=20'] } // limit to first 20
31-
{ path: 'todos', populates } // populate
32-
// { path: 'todos', queryParams: ['orderByChild=text'] }, // list todos alphabetically
27+
// { path: 'todos', type: 'once' } // for loading once instead of binding
28+
{ path: 'todos', queryParams: ['orderByKey', 'limitToLast=8'] } // limit to first 20
29+
// { path: 'todos', populates } // populate
30+
// { path: 'todos', queryParams: ['orderByKey', 'limitToLast=5'] }, // get five most recent (array will need to be inverted)
3331
])
3432
@connect(
3533
({firebase}) => ({
3634
auth: pathToJS(firebase, 'auth'),
35+
account: pathToJS(firebase, 'profile'),
3736
// todos: dataToJS(firebase, 'todos')
38-
todos: populatedDataToJS(firebase, '/todos', populates), // if populating
39-
// todos: orderedToJS(firebase, 'todos'), // if using ordering such as orderByChild
37+
// todos: populatedDataToJS(firebase, '/todos', populates), // if populating
38+
todos: orderedToJS(firebase, 'todos'), // if using ordering such as orderByChild
4039
})
4140
)
4241
export default class Home extends Component {
@@ -72,10 +71,12 @@ export default class Home extends Component {
7271
if (!auth || !auth.uid) {
7372
return this.setState({ error: 'You must be Logged into Delete' })
7473
}
75-
if (todos[id].owner !== auth.uid) {
76-
return this.setState({ error: 'You must own todo to delete' })
77-
}
78-
firebase.remove(`/todos/${id}`)
74+
return this.setState({ error: 'Delete example requires using populate' })
75+
// only works if populated
76+
// if (todos[id].owner.uid !== auth.uid) {
77+
// return this.setState({ error: 'You must own todo to delete' })
78+
// }
79+
// firebase.remove(`/todos/${id}`)
7980
}
8081

8182
handleAdd = (newTodo) => {
@@ -85,15 +86,16 @@ export default class Home extends Component {
8586
} else {
8687
newTodo.owner = 'Anonymous'
8788
}
88-
// using this.props.firebase.pushWithMeta would attach createdBy and createdAt
89+
// attach a timestamp
90+
newTodo.createdAt = this.props.firebase.database.ServerValue.TIMESTAMP
91+
// using this.props.firebase.pushWithMeta here instead would automatically attach createdBy and createdAt
8992
return this.props.firebase.push('/todos', newTodo)
9093
}
9194

9295
render () {
9396
const { todos } = this.props
9497
const { error } = this.state
95-
console.log('todos:', todos)
96-
98+
console.log('this.props.account', this.props.account)
9799
return (
98100
<div className={classes.container} style={{ color: Theme.palette.primary2Color }}>
99101
{
@@ -115,6 +117,10 @@ export default class Home extends Component {
115117
redux-firebasev3.firebaseio.com
116118
</a>
117119
</span>
120+
<span style={{ marginTop: '2rem' }}>
121+
<strong>Note: </strong>
122+
old data is removed
123+
</span>
118124
</div>
119125
<div className={classes.todos}>
120126
<NewTodoPanel
@@ -129,7 +135,8 @@ export default class Home extends Component {
129135
<List className={classes.list}>
130136
{
131137
todos &&
132-
map(todos, (todo, id) => (
138+
// todos list is reversed so the most recent is first
139+
map(todos.reverse(), (todo, id) => (
133140
<TodoItem
134141
key={id}
135142
id={id}

examples/complete/material/src/routes/Projects/containers/ProjectsContainer.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@ import {
1010
isEmpty
1111
} from 'react-redux-firebase'
1212
import { LIST_PATH } from 'constants'
13+
import { UserIsAuthenticated } from 'utils/router'
14+
import LoadingSpinner from 'components/LoadingSpinner'
1315
import ProjectTile from '../components/ProjectTile/ProjectTile'
1416
import NewProjectTile from '../components/NewProjectTile/NewProjectTile'
1517
import NewProjectDialog from '../components/NewProjectDialog/NewProjectDialog'
16-
import LoadingSpinner from 'components/LoadingSpinner'
1718
import classes from './ProjectsContainer.scss'
1819

1920
const populates = [
2021
{ child: 'createdBy', root: 'users', keyProp: 'uid' }
2122
]
2223

24+
@UserIsAuthenticated
2325
@firebaseConnect([
2426
{ path: 'projects', populates }
2527
// 'projects#populate=owner:users' // string equivalent
@@ -50,10 +52,7 @@ export default class Projects extends Component {
5052

5153
newSubmit = (newProject) => {
5254
const { auth, firebase: { push } } = this.props
53-
if (auth.uid) {
54-
newProject.owner = auth.uid
55-
}
56-
push('projects', newProject)
55+
return pushWithMeta('projects', newProject)
5756
.then(() => this.setState({ newProjectModal: false }))
5857
.catch(err => {
5958
// TODO: Show Snackbar
@@ -62,7 +61,7 @@ export default class Projects extends Component {
6261
}
6362

6463
deleteProject = (key) => {
65-
this.props.firebase.remove(`projects/${key}`)
64+
return this.props.firebase.remove(`projects/${key}`)
6665
.then(() => {
6766
// TODO: Show snackbar
6867
})
@@ -86,7 +85,6 @@ export default class Projects extends Component {
8685
const { projects, auth } = this.props
8786
const { newProjectModal } = this.state
8887

89-
9088
return (
9189
<div className={classes.container}>
9290
{

0 commit comments

Comments
 (0)