Skip to content

Commit

Permalink
update as of container when the data is out of date
Browse files Browse the repository at this point in the history
  • Loading branch information
Austionian committed Oct 19, 2024
1 parent 3d93ed2 commit d6d4b6c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 deletions.
15 changes: 6 additions & 9 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion assets/static/index.min.js

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions client/parsers/realtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
removeElement,
removeStyle,
removeHidden,
setAttribute,
} from "../utilities";

/**
Expand Down Expand Up @@ -88,6 +89,18 @@ export function parseRealtime(data) {
if (data.loaded_from_fallback) {
removeHidden("wave-fallback-icon");
}

let oneDayMs = 60 * 60 * 24 * 1_000;
if (new Date(data.as_of) < new Date() - oneDayMs) {
setStyleAttribute(
"as-of-container",
"background-color: #facc15; color: #000; display: flex; align-items: center; flex-direction: row-reverse; gap: 8px",
);
document.getElementById("as-of-container").innerHTML +=
`<svg class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true" data-slot="icon">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126ZM12 15.75h.007v.008H12v-.008Z" />
</svg>`;
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/realtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ impl Realtime {

let (as_of, measurements) = line.split_at(16);
let as_of = Self::parse_as_of(as_of)?;
println!("{as_of}");
return Self::parse_data(
measurements,
&latest,
Expand Down
8 changes: 4 additions & 4 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@
rel="stylesheet"
/>

<link rel="preload" href="/assets/styles.css?version=126" as="style" />
<link rel="preload" href="/assets/styles.css?version=128" as="style" />
<link
rel="preload"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.umd.min.js"
as="script"
/>
<link
rel="preload"
href="/assets/static/index.min.js?version=129"
href="/assets/static/index.min.js?version=131"
as="script"
/>

<link
href="/assets/styles.css?version=126"
href="/assets/styles.css?version=128"
rel="stylesheet"
type="text/css"
/>
Expand All @@ -66,7 +66,7 @@
@keyup.escape="showLiveFeed = false; showNav = false;"
:class="{ 'overflow-hidden': showNav || showLiveFeed }"
>
<script src="/assets/static/index.min.js?version=129"></script>
<script src="/assets/static/index.min.js?version=131"></script>
{% block body %} {% endblock %} {% include "includes/footer.html" %} {% if
live_reload %}
<script>
Expand Down

0 comments on commit d6d4b6c

Please sign in to comment.