handleSendMessage() { this.messagesRef.push({ userName: this.props.user.displayName, userId: this.props.user.uid, userAvatar: this.props.user.photoURL, message: this.state.message, creationDate: Date.now(), }).then(data => { this.setState({ message: '' }) }); }
const createEmployee = ({name, phone, shift}) => { const {currentUser} = firebase.auth(); return (dispatch) => { firebase.database().ref(`/users/${currentUser.uid}/employees`) .push({name, phone, shift}) .then(() => { dispatch({type: CREATE_EMPLOYEE}); Actions.employeeList({type: 'reset'}) }); //TODO catch error } }
const addReview = (review) => { review.userId = user.id; review.placeId = parseInt(review.placeId); const reviewRef = database.ref(getPlaceDetailUri(review.placeId)) .child('reviews') .push(review); return reviewRef.then(() => { review.id = reviewRef.key; return review.id; }); }
const addToFavoriteQuotes = (quote) => { quote.timestamp = getTimeStamp(); return new Promise((resolve, reject) => { firebase .addToFavoriteQuotes(quote) .then(() => resolve(quote)) .catch(error => reject(error)); }); }
const addDestination = (destination) => { destination.order = ++user.nextDestinationPosition; const destinationsRef = database.ref(getActualUserUri()) .child('destinations') .push(destination); const destinationKey = destinationsRef.key; return destinationsRef .then((snapshot) => { destination.id = destinationKey; }); }
const postMessageToServer = (message) => (dispatch) => { dispatch({ type: POST_MESSAGE, payload: { message, incoming: false } }) postMessage(message) .then(() => { dispatch({ type: POST_MESSAGE_SUCCESS }) }) .catch((error) => { dispatch({ type: POST_MESSAGE_ERROR, error }) }); }
takePicture() { const options = {}; //options.location = ... this.camera.capture({metadata: options}) .then((data) => { console.log(data.data) this.messagesRef.push({ userName: this.props.user.displayName, userId: this.props.user.uid, userAvatar: this.props.user.photoURL, type: 'IMAGE', data: data.data, creationDate: Date.now(), }).then(data => { console.log(data) this.props.navigator.pop() }); }) .catch(err => console.error(err)); }
const startAddExpense = (expenseData = {}) => { return (dispatch, getState) => { const uid = getState().auth.uid; const { description = '', note = '', amount = 0, createdAt = 0 } = expenseData; const expense = { description, note, amount, createdAt }; return database.ref(`users/${uid}/expenses`).push(expense) .then((ref) => { dispatch(addExpense({ id: ref.key, ...expense })); }); }; }
}).then(r => resolve(r), e => reject(e))
handleAddRoom(newRoom) { this.roomRef.push({ name: newRoom, owner: this.props.user.displayName, ownerId: this.props.user.uid, creationDate: Date.now(), }).then(data => { this.showAlert() }) }
const startAddExpense = (expenseData = {}) => { return (dispatch, getState) => { const uid = getState().auth.uid; const { description = '', note = '', amount = 0, createdAt = 0 } = expenseData; const expense = { description, note, amount, createdAt }; return database.ref(`users/${uid}/expenses`).push(expense).then((ref) => { dispatch(addExpense({ id: ref.key, ...expense })); }); }; }