return SHortnames in events

This commit is contained in:
Luke Berndt
2023-02-03 20:23:55 -05:00
parent 86d8c0b710
commit 51f739395d
2 changed files with 36 additions and 36 deletions

View File

@@ -23,7 +23,7 @@ exports.getEvent = async function (req, res, next) {
exports.getEvents = async function (req, res, next) { exports.getEvents = async function (req, res, next) {
try { try {
let events = await Event.find({},["title", "description", "startTime", "endTime", "expireTime", "numCalls", "createdAt"]).exec(); let events = await Event.find({},["title", "description", "startTime", "endTime", "expireTime", "numCalls", "createdAt", "shortNames"]).exec();
res.contentType('json'); res.contentType('json');
res.send(JSON.stringify(events)); res.send(JSON.stringify(events));
} }

View File

@@ -1,5 +1,5 @@
import React, { Component } from "react"; import React, { Component } from "react";
import { Link, useNavigate } from 'react-router-dom' import { Link, useNavigate } from 'react-router-dom'
import { import {
Container, Container,
@@ -10,55 +10,55 @@ import {
Divider, Divider,
Table Table
} from "semantic-ui-react"; } from "semantic-ui-react";
import NavBar from "../Common/NavBar" import NavBar from "../Common/NavBar"
import { useGetEventsQuery } from "../features/api/apiSlice"; import { useGetEventsQuery } from "../features/api/apiSlice";
// ---------------------------------------------------- // ----------------------------------------------------
const ListEvents = (props) => { const ListEvents = (props) => {
const dateRange = (start, end) => { const dateRange = (start, end) => {
if (start.getYear() != end.getYear()) { if (start.getYear() != end.getYear()) {
return start.toLocaleDateString('en-us', { weekday:"short", year:"numeric", month:"short", day:"numeric"}) + " " + start.toLocaleTimeString() + " - " + end.toLocaleDateString('en-us', { weekday:"short", year:"numeric", month:"short", day:"numeric"}) + " " + end.toLocaleTimeString(); return start.toLocaleDateString('en-us', { weekday: "short", year: "numeric", month: "short", day: "numeric" }) + " " + start.toLocaleTimeString() + " - " + end.toLocaleDateString('en-us', { weekday: "short", year: "numeric", month: "short", day: "numeric" }) + " " + end.toLocaleTimeString();
} else if (start.getMonth() != end.getMonth()) { } else if (start.getMonth() != end.getMonth()) {
return start.toLocaleDateString('en-us', { weekday:"short", month:"short", day:"numeric"}) + " " + start.toLocaleTimeString() + " - " + end.toLocaleDateString('en-us', { weekday:"short", month:"short", day:"numeric"}) + " " + end.toLocaleTimeString(); return start.toLocaleDateString('en-us', { weekday: "short", month: "short", day: "numeric" }) + " " + start.toLocaleTimeString() + " - " + end.toLocaleDateString('en-us', { weekday: "short", month: "short", day: "numeric" }) + " " + end.toLocaleTimeString();
} else if (start.getDay() != end.getDay()) {
return start.toLocaleDateString('en-us', { weekday:"short", month:"short", day:"numeric"}) + " " + start.toLocaleTimeString() + " - " + end.toLocaleDateString('en-us', { weekday:"short", day:"numeric"}) + " " + end.toLocaleTimeString();
} else {
return start.toLocaleDateString('en-us', { weekday:"short", month:"short", day:"numeric"}) + " " + start.toLocaleTimeString() + " - " + end.toLocaleTimeString();
}
} else if (start.getDay() != end.getDay()) {
return start.toLocaleDateString('en-us', { weekday: "short", month: "short", day: "numeric" }) + " " + start.toLocaleTimeString() + " - " + end.toLocaleDateString('en-us', { weekday: "short", day: "numeric" }) + " " + end.toLocaleTimeString();
} else {
return start.toLocaleDateString('en-us', { weekday: "short", month: "short", day: "numeric" }) + " " + start.toLocaleTimeString() + " - " + end.toLocaleTimeString();
} }
const {data:events, isSuccess} = useGetEventsQuery();
}
const { data: events, isSuccess } = useGetEventsQuery();
const navigate = useNavigate(); const navigate = useNavigate();
//<Table.Cell>{event.shortNames.map( shortName => <Link to={"/system/"+shortName}>{shortName}</Link> )}</Table.Cell>}
return ( return (
<div> <div>
<NavBar/> <NavBar />
<Container > <Container >
<Divider horizontal style={{paddingTop:"5em", paddingBottom:"2em"}}><Header as="h1">Events<Icon name='rss' /></Header></Divider> <Divider horizontal style={{ paddingTop: "5em", paddingBottom: "2em" }}><Header as="h1">Events<Icon name='rss' /></Header></Divider>
<Table basic="very"> <Table basic="very">
<Table.Body> <Table.Body>
{isSuccess&&events.map((event, index) => {isSuccess && events.map((event, index) =>
<Table.Row key={index}> <Table.Row key={index}>
<Table.Cell><Link to={"/events/"+event._id}><Header as='h3'>{event.title}</Header></Link></Table.Cell> <Table.Cell><Link to={"/events/" + event._id}><Header as='h3'>{event.title}</Header></Link></Table.Cell>
<Table.Cell>{event.description}</Table.Cell> <Table.Cell>{event.description}</Table.Cell>
<Table.Cell>{event.numCalls} Calls</Table.Cell> <Table.Cell>{event.numCalls} Calls</Table.Cell>
<Table.Cell>{dateRange(new Date(event.startTime),new Date(event.endTime))}</Table.Cell> <Table.Cell>{dateRange(new Date(event.startTime), new Date(event.endTime))}</Table.Cell>
</Table.Row> </Table.Row>
)} )}
</Table.Body> </Table.Body>
</Table> </Table>
</Container> </Container>
</div> </div>
); );
} }
export default ListEvents; export default ListEvents;