const getTrendingWishes = () => { let now = new Date(); now.setDate(now.getDate() - 3); let daysAgo = now.getTime(); return firebase.database().ref('/wishes/').orderByChild('createdAt').startAt(daysAgo); }
const fetchToDos = () => async dispatch => { todosRef.on("value", snapshot => { dispatch({ type: FETCH_TODOS, payload: snapshot.val() }); }); }
componentWillMount() { const messagesRef = database.ref('messages') .orderByKey() .limitToLast(100); messagesRef.on('child_added', snapshot => { const message = { text: snapshot.val(), id: snapshot.key }; this.setState(prevState => ({ messages: [ message, ...prevState.messages ], })); }); }
const getComments = async (parentId, slug, type, limit) => { const db = firebase.firestore(); let commentsQuery = db.collection('comments3') .where('postType', '==', type) .where('postId', '==', slug) .where('parentId', '==', parentId || null) .orderBy("createdAt"); if (limit) { commentsQuery = commentsQuery.limit(limit); } return commentsQuery.get();; }
componentWillUnmount() { this.chatRefData.off() }
deleteFavorite(id: string): Promise<void> { const db = firebase.firestore(); if (this.userId) { return db.collection('favorites').where('user', '==', this.userId).where('dish', '==', id).get() .then(doc => { doc.forEach( docu => { return db.doc('favorites/' + docu.id).delete(); }); }); } else { return Promise.reject(new Error('No User Logged In!')); } }
const getLatestWishes = () => { return firebase.database().ref('/wishes/').orderByChild('createdAt').limitToLast(50); }
componentDidMount() { goalRef.on('value', snap => { let goals = []; snap.forEach(goal => { const { email, title } = goal.val(); const serverKey = goal.key; goals.push({ email, title, serverKey }); }) this.props.setGoals(goals); }) }
const fetchNextPaintings = lastVisible => async dispatch => { try { dispatch({ type: PAINTINGS_FETCH, }); const firebase = require('firebase'); // eslint-disable-line global-require require('firebase/firestore'); // eslint-disable-line global-require const db = firebase.firestore(); const snapshots = await db .collection('paintings') .orderBy('createdAt', 'desc') .startAfter(lastVisible) .limit(FETCH_LIMIT) .get(); dispatch({ type: PAINTINGS_FETCH_NEXT, payload: parseSnapshots(snapshots), lastVisible: snapshots.docs[snapshots.docs.length - 1], }); } catch (err) { console.log('err:', err); dispatch({ type: PAINTINGS_FETCH_ERROR, payload: err, }); } }
componentDidMount() { goalRef.on('value',snap => { let goals = []; snap.forEach(goal => { const {email,title}= goal.val(); goals.push({email,title}); }) this.props.setGoals(goals); }) }
// Begin Session const getUserFromApi = (username) => { return database.ref(apiUris.users) .orderByChild('username') .equalTo(username) .once('value') .then((snapshot) => { const response = snapshot.val(); let user; response && response.every((apiUser) => { if (apiUser && apiUser.username === username) { user = apiUser; } return user; }); return user || {}; }); }
/* postFavorites(dishids: any) { return this.http.post(baseURL + 'favorites/', dishids) .catch(error => { return this.processHTTPMsgService.handleError(error); }); } */ isFavorite(id: string): Promise<boolean> { const db = firebase.firestore(); if (this.userId) { return db.collection('favorites').where('user', '==', this.userId).where('dish', '==', id).get() .then(doc => { return !doc.empty; }); } else { return Promise.resolve(false); } }
componentDidMount() { messageRef.on('value', snap => { let messages = []; snap.forEach(response => { let { message, author } = response.val(); messages.push({ message, author }); }) this.setState({messages: messages}); }) }
componentDidMount(){ completeGoalRef.on('value', snap =>{ let completeGoals = []; snap.forEach(completeGoal => { const { email, title } = completeGoal.val(); completeGoals.push({email, title}) }) this.props.setCompleted(completeGoals); }) }