Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce Firebase reads #203

Merged
merged 6 commits into from
Dec 6, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
re-use announcements from app.js
  • Loading branch information
ianmah committed Dec 6, 2020
commit 4fb8549e989607151d526fb0937772a472d7ac5e
7 changes: 5 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from 'react'
import React, { useEffect, useState } from 'react'
import { Redirect, Route, Switch } from 'wouter'
import GlobalStyle from './theme/GlobalStyle'
import ThemeProvider from './theme/ThemeProvider'
Expand Down Expand Up @@ -110,6 +110,8 @@ const JudgingViewContainer = ({ params }) => {
}

function App() {
const [announcements, setAnnouncements] = useState([])

// TODO create reusable Announcements firebase ref in firebase.js to avoid redundant fb calls in Announcements.js
useEffect(() => {
// don't notify users on IOS devices because Notification API incompatible
Expand All @@ -121,6 +123,7 @@ function App() {
.orderBy('timestamp', 'desc')
.limit(6)
.onSnapshot(querySnapshot => {
setAnnouncements(Object.values(querySnapshot.docs.map(doc => doc.data())))
// firebase doc that triggered db change event
const changedDoc = querySnapshot.docChanges()[0]

Expand All @@ -140,7 +143,7 @@ function App() {
<GlobalStyle />
<Switch>
<PageRoute path="/">
<Home />
<Home announcements={announcements} />
</PageRoute>
<PageRoute path="/charcuterie">
<Charcuterie />
Expand Down
23 changes: 0 additions & 23 deletions src/containers/Announcements.js

This file was deleted.

6 changes: 3 additions & 3 deletions src/pages/Home.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import React from 'react'
import Announcements from '../containers/Announcements'
import Announcements from '../components/Announcements'
import HackerCountdown from '../containers/HackerCountdown'
import { CommonLinks } from '../containers/Quicklinks'
import Livestream from '../components/Livestream'

export default () => {
export default ({ announcements }) => {
return (
<>
<HackerCountdown />
<CommonLinks />
<Livestream />
<Announcements />
<Announcements announcements={announcements} />
</>
)
}