Skip to content

Commit

Permalink
DBCC22-1858 Camera panel details
Browse files Browse the repository at this point in the history
  • Loading branch information
fatbird committed Mar 27, 2024
1 parent c1067c9 commit f2a9339
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 42 deletions.
61 changes: 34 additions & 27 deletions src/frontend/src/Components/FriendlyTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,48 @@ const datetimeFormat = {
timeZoneName: 'short',
};
const formatter = new Intl.DateTimeFormat('en-US', datetimeFormat);
const ONE_DAY = 1000 * 60 * 60 * 24; // 24 hours in milliseconds

export default function FriendlyTime( {date} ) {
export default function FriendlyTime({ date, asDate=false, includeFullIfHumanized=false }) {
const [showTooltip, setShowTooltip] = useState(false);

// get time difference in seconds
// get time difference in milliseconds
const timeDiff = (new Date() - new Date(date));
const dateFormatted = formatter.format(new Date(date));

// if difference is less than 24hrs
if (timeDiff < 86400000 ) {
return <div
className="friendly-time"
title={dateFormatted}
onClick={(event) => {
const humanize = timeDiff < ONE_DAY;

if (humanize && !asDate) {
return (
<React.Fragment>
{ includeFullIfHumanized &&
<p className="friendly-time-text formatted-date">{dateFormatted}</p>
}

<div
className="friendly-time"
title={dateFormatted}
onClick={(event) => {
event.stopPropagation();
setShowTooltip(!showTooltip);
}}
onKeyDown={(keyEvent) => {
if (keyEvent.keyCode == 13) {
event.stopPropagation();
setShowTooltip(!showTooltip);
}}
onKeyDown={(keyEvent) => {
if (keyEvent.keyCode == 13) {
event.stopPropagation();
setShowTooltip(!showTooltip)
}
}}>

<p className="friendly-time-text">
<ReactTimeAgo date={date} locale="en-US"/>
</p>
<span className={"friendly-time__tooltip" + (showTooltip ? " showTooltip" : "")}>{dateFormatted}</span>
</div>
}
setShowTooltip(!showTooltip)
}
}}>

// else return formatted date without tooltip
else {
return <p className="friendly-time-text formatted-date">
{dateFormatted}
<p className="friendly-time-text">
<ReactTimeAgo date={date} locale="en-US"/>
</p>
<span className={"friendly-time__tooltip" + (showTooltip ? " showTooltip" : "")}>
{dateFormatted}
</span>
</div>
</React.Fragment>
)
}

return <p className="friendly-time-text formatted-date">{dateFormatted}</p>;
}
17 changes: 6 additions & 11 deletions src/frontend/src/Components/map/camPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default function CamPopup(props) {
</div>
<p className="name">Camera</p>
</div>
{camera &&
{ camera &&
<div className="popup__content">
<div className="popup__content__title">
<p className="name"
Expand All @@ -88,34 +88,29 @@ export default function CamPopup(props) {
if (keyEvent.keyCode == 13) {
handlePopupClick();
}
}}>

{camera.name}
</p>
}}>{camera.name}</p>
</div>
{camera.is_on ?
{ camera.is_on ?
<div className="popup__content__image">
<div className="clip">
<img src={camera.links.imageDisplay} width='300' />
</div>
<div className="timestamp">
<p className="driveBC">Drive<span>BC</span></p>
<FriendlyTime date={camera.last_update_modified} />
<FriendlyTime date={camera.last_update_modified} includeFullIfHumanized />
</div>
</div> :
<div className="popup__content__image">
<div className="camera-unavailable">
<div className="card-pill">
<p>Unavailable</p>
</div>
<div className="card-pill"><p>Unavailable</p></div>
<div className="card-img-box unavailable">
<FontAwesomeIcon icon={faVideoSlash} />
</div>
<p>This camera image is temporarily unavailable. Please check again later.</p>
</div>
<div className="timestamp">
<p className="driveBC">Drive<span>BC</span></p>
<FriendlyTime date={camera.last_update_modified} />
<FriendlyTime date={camera.last_update_modified} asDate={true}/>
</div>
</div>
}
Expand Down
5 changes: 2 additions & 3 deletions src/frontend/src/pages/CameraDetailsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ export default function CameraDetailsPage() {
{!replay && (
<div className="timestamp">
<p className="driveBC">Drive<span>BC</span></p>
<FriendlyTime date={lastUpdate} />
<FriendlyTime date={lastUpdate} includeFullIfHumanized />
</div>
)}
</div>
Expand All @@ -418,8 +418,7 @@ export default function CameraDetailsPage() {
<FontAwesomeIcon icon={faFlag} />Nearby
</span>
}>
<div className="actions-bar actions-bar--nearby">
</div>
<div className="actions-bar actions-bar--nearby"></div>
<div className="map-wrap map-context-wrap">
<DndProvider options={HTML5toTouch}>
<Map camera={camera} isPreview={true} cameraHandler={initCamera} mapViewRoute={mapViewRoute}/>
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/src/pages/CameraDetailsPage.scss
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@
}

.credit {
margin-top: 0.25rem;
font-size: 0.75rem;
font-style: italic;
}
Expand Down Expand Up @@ -522,7 +523,7 @@
top: 0rem;
bottom: 0;
width: 100%;
height: 388px;
height: 370px;

.map {
width: 100%;
Expand Down

0 comments on commit f2a9339

Please sign in to comment.