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

Display current cycle, epoch, and period on homepage #610

Merged
merged 2 commits into from
Oct 4, 2022
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
7 changes: 6 additions & 1 deletion src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,12 @@ mod tests {
".*<title>Ordinals</title>.*<h1>Ordinals</h1>
<nav>.*</nav>
.*
<h2>Recent Blocks</h2>
<h2>Latest Blocks</h2>
<dl>
<dt>cycle</dt><dd>0</dd>
<dt>epoch</dt><dd>0</dd>
<dt>period</dt><dd>0</dd>
</dl>
<ol start=1 reversed class='blocks monospace'>
<li><a href=/block/[[:xdigit:]]{64} class=uncommon>[[:xdigit:]]{64}</a></li>
<li><a href=/block/000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f class=mythic>000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f</a></li>
Expand Down
19 changes: 14 additions & 5 deletions src/subcommand/server/templates/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ use super::*;
pub(crate) struct HomeHtml {
last: u64,
blocks: Vec<(Rarity, BlockHash)>,
starting_ordinal: Option<Ordinal>,
}

impl HomeHtml {
pub(crate) fn new(blocks: Vec<(u64, BlockHash)>) -> Self {
Self {
starting_ordinal: blocks
.get(0)
.map(|(height, _)| Height(*height).starting_ordinal()),
last: blocks
.get(0)
.map(|(height, _)| height)
Expand Down Expand Up @@ -37,13 +41,13 @@ mod tests {
assert_regex_match!(
&HomeHtml::new(vec![
(
1,
1260001,
"1111111111111111111111111111111111111111111111111111111111111111"
.parse()
.unwrap()
),
(
0,
1260000,
"0000000000000000000000000000000000000000000000000000000000000000"
.parse()
.unwrap()
Expand All @@ -54,10 +58,15 @@ mod tests {
<nav>.*</nav>
<h2>Search</h2>
<form action=/search method=get>.*</form>
<h2>Recent Blocks</h2>
<ol start=1 reversed class='blocks monospace'>
<h2>Latest Blocks</h2>
<dl>
<dt>cycle</dt><dd>1</dd>
<dt>epoch</dt><dd>6</dd>
<dt>period</dt><dd>625</dd>
</dl>
<ol start=1260001 reversed class='blocks monospace'>
<li><a href=/block/1{64} class=uncommon>1{64}</a></li>
<li><a href=/block/0{64} class=mythic>0{64}</a></li>
<li><a href=/block/0{64} class=legendary>0{64}</a></li>
</ol>
",
);
Expand Down
9 changes: 8 additions & 1 deletion templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ <h2>Search</h2>
<input autocapitalize=off autocomplete=off autocorrect=off autofocus name=query spellcheck=false type=text>
<input type=submit>
</form>
<h2>Recent Blocks</h2>
<h2>Latest Blocks</h2>
%% if let Some(starting_ordinal) = self.starting_ordinal {
<dl>
<dt>cycle</dt><dd>{{starting_ordinal.cycle()}}</dd>
<dt>epoch</dt><dd>{{starting_ordinal.epoch()}}</dd>
<dt>period</dt><dd>{{starting_ordinal.period()}}</dd>
</dl>
%% }
<ol start={{self.last}} reversed class='blocks monospace'>
%% for (rarity, hash) in &self.blocks {
<li><a href=/block/{{hash}} class={{rarity}}>{{hash}}</a></li>
Expand Down