Skip to content

Commit 1753309

Browse files
authored
Feature/sajmal (#45)
1 parent 314de41 commit 1753309

2 files changed

Lines changed: 39 additions & 26 deletions

File tree

simplq/src/components/page/QueueStatus.jsx

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
1-
import React from "react";
1+
import React, { useState } from "react";
22
import Typography from '@material-ui/core/Typography';
33
import Button from '@material-ui/core/Button';
44
import CentralSection from "../CentralSection";
5-
5+
import QueueService from '../../services/queue';
6+
import { CircularProgress } from "@material-ui/core";
67

78
function QueueStatus(props) {
8-
var aheadCount = 10;
9+
const [aheadCount, setAheadCount] = useState();
10+
QueueService.userIndexQueue(props.match.params.queueId, props.match.params.tokenId).then(
11+
count => setAheadCount(count)
12+
);
913

1014
return <CentralSection heading="Sit Tight!">
11-
<Typography variant="h5" align="center" color="textSecondary" component="p">
12-
There are {aheadCount} people ahead of you. Thanks for waiting!
13-
</Typography>
15+
{aheadCount ?
16+
<Typography variant="h5" align="center" color="textSecondary" component="p">
17+
There are {aheadCount} people ahead of you. Thanks for waiting!
18+
</Typography>
19+
:
20+
<CircularProgress style={{ display: "block", margin: "0px auto" }} />
21+
}
1422
<div style={{ display: "flex", justifyContent: 'flex-end' }}>
15-
<Button variant="contained" color="primary" style={{
16-
marginTop: 30,
17-
marginLeft: 10,
18-
}}>
19-
Refresh
23+
<Button variant="contained" color="primary" style={{
24+
marginTop: 30,
25+
marginLeft: 10,
26+
}}>
27+
Refresh
2028
</Button>
21-
</div>
29+
</div>
2230
</CentralSection>
2331
}
2432

simplq/src/services/queue.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,18 @@ class QueueService {
3434
throw new Error("Queue not found");
3535
}
3636
});
37-
37+
3838
const usersPromise = this.queues.doc(queueId).collection("users").get()
39-
.then(snapshot => {
40-
const users = [];
41-
snapshot.forEach(doc => {
42-
users.push(doc.data())
43-
});
44-
return users;
45-
})
46-
.catch(err => {
47-
throw new Error('Error getting users from queue', err);
39+
.then(snapshot => {
40+
const users = [];
41+
snapshot.forEach(doc => {
42+
users.push(doc.data())
4843
});
44+
return users;
45+
})
46+
.catch(err => {
47+
throw new Error('Error getting users from queue', err);
48+
});
4949

5050
return {
5151
name: await namePromise,
@@ -55,12 +55,17 @@ class QueueService {
5555

5656
addtoQueue(name, contact, queueId) {
5757
return this.queues.doc(queueId)
58-
.collection("users")
59-
.add({ name: name, contact: contact })
60-
.then(docRef => docRef.id)
61-
.catch(() => console.log("Error adding to queue"));
58+
.collection("users").add({
59+
name: name, contact: contact, "timestamp": firebase.firestore.Timestamp.now()
60+
})
61+
.then(docRef => docRef.id).catch(() => console.log("Error adding to queue"));
6262

6363
}
64+
async userIndexQueue(queueId, tokenId) {
65+
const users = this.queues.doc(queueId).collection("users");
66+
const timeStamp = await users.doc(tokenId).get().then(doc => doc.data().timestamp);
67+
return users.where("timestamp", "<", timeStamp).get().then(snapshot => snapshot.size);
68+
}
6469
}
6570

6671

0 commit comments

Comments
 (0)