Skip to content

Commit

Permalink
request time ago and sorted
Browse files Browse the repository at this point in the history
  • Loading branch information
SMNAFI committed Nov 24, 2022
1 parent a233f7c commit 756f41e
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 22 deletions.
55 changes: 41 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"firebase": "^9.14.0",
"moment": "^2.29.4",
"react": "^18.2.0",
"react-bootstrap": "^2.6.0",
"react-dom": "^18.2.0",
Expand Down
9 changes: 8 additions & 1 deletion src/components/Request.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react'
import { Button, Card } from 'react-bootstrap'
import { useSelector } from 'react-redux'
import { Link } from 'react-router-dom'
import moment from 'moment'

const Donar = ({ request }) => {
// console.log(request)
Expand All @@ -20,6 +21,7 @@ const Donar = ({ request }) => {
location,
district,
numManaged,
timestamp,
// response,
} = request
return (
Expand All @@ -42,7 +44,12 @@ const Donar = ({ request }) => {
Location: {location}, {district}
</Card.Text>
<Card.Text>Bag managed: {numManaged}</Card.Text>
{/* <Card.Text>Total response: {response.length}</Card.Text> */}
<Card.Text>
<small>{new Date(timestamp?.toDate()).toLocaleString()}</small>
</Card.Text>
<Card.Text>
<small>{moment(timestamp?.toDate()).fromNow()}</small>
</Card.Text>
</Card.Body>
<Link to={`/feed/${id}`}>
<Button>Details</Button>
Expand Down
2 changes: 1 addition & 1 deletion src/screens/LoginScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const LoginScreen = () => {
district: '',
lastDonation: '',
response: 0,
timeStamp: serverTimestamp(),
createdAt: serverTimestamp(),
})

// now userInfo is in the database
Expand Down
2 changes: 1 addition & 1 deletion src/screens/RegisterScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const RegisterScreen = () => {
district: '',
lastDonation: '',
response: 0,
timeStamp: serverTimestamp(),
createdAt: serverTimestamp(),
})

// now userInfo is in the database
Expand Down
10 changes: 6 additions & 4 deletions src/screens/RequestFeedScreen.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react'
import { collection, onSnapshot } from 'firebase/firestore'
import { collection, onSnapshot, orderBy, query } from 'firebase/firestore'
import { db } from '../firebase'
import { Col, Form, Row } from 'react-bootstrap'
import Loader from '../components/Loader'
Expand All @@ -12,8 +12,12 @@ const RequestFeedScreen = () => {
const [error, setError] = useState(null)

useEffect(() => {
const colRef = collection(db, 'requests')
// const q = query(colRef, orderBy('createdAt', 'desc'))
const q = query(colRef, orderBy('timestamp', 'desc'))

const unsub = onSnapshot(
collection(db, 'requests'),
q,
(snapShot) => {
let list = []

Expand All @@ -22,11 +26,9 @@ const RequestFeedScreen = () => {
})
setRequests(list)
setLoading(false)
// console.log(list)
},
(error) => {
setError(error)
// console.log(error)
}
)

Expand Down
2 changes: 1 addition & 1 deletion src/screens/RequestScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const RequestPage = () => {
date,
numManaged: 0,
isManaged: false,
timestamp: serverTimestamp(),
createdAt: serverTimestamp(),
})
setProblem('')
setBloodGroup('A+')
Expand Down

0 comments on commit 756f41e

Please sign in to comment.