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

Moar Odyssey stuff! #326

Merged
merged 4 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 15 additions & 10 deletions src/components/DispatchTable/DispatchTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function DispatchTable (props) {
} = props

const rescueIds = useSelector(selectDispatchBoard)
const queueLength = useRescueQueueCount()
const [queueLength, maxClients] = useRescueQueueCount()

return (
<section className={[styles.dispatchTable, className]}>
Expand Down Expand Up @@ -45,15 +45,20 @@ function DispatchTable (props) {
}
</tbody>
</table>
{
queueLength > 0 && (
<div className={styles.queueLength}>
{'+'}
<b>{queueLength}</b>
<small>{' IN QUEUE'}</small>
</div>
)
}
<div className={styles.queueLength}>
<small>{'MAX '}</small>
{maxClients}
<small>{' CLIENTS'}</small>
{
queueLength > 0 && (
<>
<small>{' ( '}</small>
{queueLength}
<small>{' IN QUEUE )'}</small>
</>
)
}
</div>
</section>
)
}
Expand Down
5 changes: 5 additions & 0 deletions src/components/DispatchTable/DispatchTable.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@
opacity: 0.25;
}

.odysseyIcon {
float: right;

padding-left: 0.5rem;
}

.queueLength {
float: right;
Expand Down
8 changes: 8 additions & 0 deletions src/components/DispatchTable/RescueRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ function RescueRow (props) {
clientNick,
client,
commandIdentifier,
odyssey,
system,
} = rescue.attributes

Expand Down Expand Up @@ -110,6 +111,13 @@ function RescueRow (props) {
text={clientNick ?? client}
title={clientNick ?? ''}>
{client ?? '?'}
{
odyssey && (
<span className={styles.odysseyIcon}>
<FontAwesomeIcon fixedWidth icon="shoe-prints" title="Odyssey Rescue" transform={{ rotate: -40 }} />
</span>
)
}
</CopyToClipboard>
<td
className="rescue-row-language"
Expand Down
10 changes: 10 additions & 0 deletions src/components/RescueDetails/RescueDetailsContent.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import Link from 'next/link'
// import { useRouter } from 'next/router'
import PropTypes from 'prop-types'
Expand Down Expand Up @@ -62,6 +63,7 @@ function RescueDetailsContent (props) {
platform,
clientLanguage,
createdAt,
odyssey,
title,
quotes,
} = rescue.attributes
Expand All @@ -80,6 +82,14 @@ function RescueDetailsContent (props) {
<div className={styles.header}>
<div className={styles.title}>
{`${typeof commandIdentifier === 'number' ? `#${commandIdentifier} - ` : ''}${title ?? client}`}
{
odyssey && (
<>
{' '}
<FontAwesomeIcon fixedWidth icon="shoe-prints" size="sm" title="Odyssey Rescue" transform={{ rotate: -40 }} />
</>
)
}
{codeRed && <span className="badge">{'CODE RED'}</span>}
{status === 'inactive' && <span className="badge warn">{'Inactive'}</span>}
</div>
Expand Down
1 change: 1 addition & 0 deletions src/helpers/faIconLibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export {
faPlus,
faRocket,
faShieldAlt,
faShoePrints,
faShoppingCart,
faSignature,
faSpaceShuttle,
Expand Down
6 changes: 4 additions & 2 deletions src/hooks/rescueHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export const usePlatformData = (rescue) => {


export const useRescueQueueCount = () => {
const [rescueCount, setCount] = useState(0)
const [queueLength, setCount] = useState(0)
const [maxClients, setMax] = useState(0)

useEffect(
() => {
Expand All @@ -46,6 +47,7 @@ export const useRescueQueueCount = () => {

if (status === HttpStatus.OK) {
setCount(data.data.queueLength)
setMax(data.data.maxClients)
}


Expand All @@ -64,5 +66,5 @@ export const useRescueQueueCount = () => {
)


return rescueCount
return [queueLength, maxClients]
}
57 changes: 44 additions & 13 deletions src/pages/api/qms/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,34 @@ import axios from 'axios'
import { methodRouter } from '~/helpers/apiMiddlewares'


// 10 second maxAge
const cacheMaxAge = 10000



const cache = {
lastCheck: 0,
count: 0,
count: {
maxAge: 10000,
lastCheck: 0,
value: 0,
},
max: {
maxAge: 60000,
lastCheck: 0,
value: 0,
},
}





async function Queue (req, res) {
const nowTime = Date.now()

if (nowTime - cache.lastCheck >= cacheMaxAge) {
cache.lastCheck = nowTime
if (nowTime - cache.count.lastCheck >= cache.count.maxAge) {
cache.count.lastCheck = nowTime

const { data, status, statusText } = await axios.get(
`${process.env.QMS_API_URL}/api/v1/queue`,
`${process.env.QMS_API_URL}/api/v1/queue/`,
{
headers: {
Authorization: `Bearer ${process.env.QMS_API_TOKEN}`,
Expand All @@ -33,21 +44,41 @@ async function Queue (req, res) {
return !rescue.pending && !rescue.in_progress
})

cache.count = rescueQueue.length
cache.count.value = rescueQueue.length
} else {
console.error('GET /api/v1/queue/', status, statusText, data)
res.status(status).end(statusText)
console.error(status, statusText, data)
return
}
}

if (nowTime - cache.max.lastCheck >= cache.max.maxAge) {
cache.max.lastCheck = nowTime
const { data, status, statusText } = await axios.get(
`${process.env.QMS_API_URL}/api/v1/config/`,
{
headers: {
Authorization: `Bearer ${process.env.QMS_API_TOKEN}`,
},
},
)

if (status === HttpStatus.OK) {
cache.max.value = data.max_active_clients
} else {
console.error('GET /api/v1/config/', status, statusText, data)
}
}


return res.status(HttpStatus.OK).json({
res.status(HttpStatus.OK).json({
data: {
queueLength: cache.count,
queueLength: cache.count.value,
maxClients: cache.max.value,
},
meta: {
age: nowTime - cache.lastCheck,
maxAge: cacheMaxAge,
queueAge: nowTime - cache.count.lastCheck,
maxClientAge: nowTime - cache.max.lastCheck,
},
})
}
Expand Down