Skip to content

Commit e7d6e76

Browse files
Merge pull request #7 from DanielMSchmidt/redesign-ui
chore: redesign UI to be more appealing
2 parents 201eb28 + a687157 commit e7d6e76

File tree

6 files changed

+101
-62
lines changed

6 files changed

+101
-62
lines changed

src/fetcher/base.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
use serde::{Deserialize, Serialize};
22

3-
#[derive(Deserialize, Debug, Clone, Serialize)]
3+
#[derive(Deserialize, Debug, Clone, Serialize, Eq, PartialEq,)]
44
pub struct Shareable {
55
pub id: String,
66
pub title: String,
77
pub date: String,
88
pub url: String,
99
pub source: String,
1010
}
11+
12+
impl PartialOrd for Shareable {
13+
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
14+
Some(self.date.cmp(&other.date))
15+
}
16+
}
17+
18+
impl Ord for Shareable {
19+
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
20+
self.date.cmp(&other.date)
21+
}
22+
}

src/main.rs

+29-41
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use axum::{
88
routing::get,
99
Router,
1010
};
11+
1112
use fetcher::base::Shareable;
1213
use mysql::prelude::*;
1314
use mysql::*;
@@ -102,14 +103,13 @@ async fn main() {
102103
#[derive(Template)]
103104
#[template(path = "base.html", escape = "none")]
104105
struct BaseTemplate {
105-
content: String,
106+
title: String,
106107
}
107108

108109
#[derive(Template)]
109110
#[template(path = "index.html", escape = "none")]
110111
struct IndexTemplate {
111-
twitter_items: String,
112-
stackoverflow_items: String,
112+
items: Vec<Shareable>,
113113
}
114114

115115
#[derive(Template)]
@@ -158,49 +158,37 @@ async fn root(
158158
info!("Fetched {} items", shareables.len());
159159
debug!("Items: {:?}", shareables);
160160

161-
let twitter_items = shareables
162-
.iter()
163-
.filter(|shareable| shareable.source == "twitter")
164-
.map(|shareable| {
165-
format!(
166-
"<li><a href=\"{}\">{}</a></li>",
167-
shareable.url, shareable.title
168-
)
169-
})
170-
.collect::<Vec<String>>()
171-
.join("");
172-
173-
let stackoverflow_items = shareables
174-
.iter()
175-
.filter(|shareable| shareable.source == "stackoverflow")
176-
.map(|shareable| {
177-
format!(
178-
"<li><a href=\"{}\">{}</a></li>",
179-
shareable.url,
180-
shareable
181-
.title
182-
.replace(":question:", "❓")
183-
.replace(":white_check_mark:", "✅")
184-
.replace(":waiting-spin:", "🔄")
185-
)
161+
let mut sanitized_shareable = shareables
162+
.into_iter()
163+
.map(|item| Shareable {
164+
id: item.id,
165+
title: item
166+
.title
167+
.replace(":question:", "❓")
168+
.replace(":white_check_mark:", "✅")
169+
.replace(":waiting-spin:", "🔄"),
170+
date: item.date,
171+
url: item.url,
172+
source: item.source,
186173
})
187-
.collect::<Vec<String>>()
188-
.join("");
189-
190-
let content = IndexTemplate {
191-
twitter_items,
192-
stackoverflow_items,
193-
};
194-
let str = content.render().expect("Could not render template");
195-
HtmlTemplate(BaseTemplate { content: str })
174+
.filter(|item| !item.title.contains("[Dependency Updated]"))
175+
.collect::<Vec<Shareable>>();
176+
177+
sanitized_shareable.sort_by(|a, b| b.cmp(a));
178+
179+
180+
181+
HtmlTemplate(IndexTemplate {
182+
items: sanitized_shareable,
183+
})
184+
.into_response()
196185
}
197186
Err(e) => {
198187
error!("Error loading data: {}", e);
199-
let content = ErrorTemplate {
188+
HtmlTemplate(ErrorTemplate {
200189
message: format!("{}", e),
201-
};
202-
let str = content.render().expect("Could not render template");
203-
HtmlTemplate(BaseTemplate { content: str })
190+
})
191+
.into_response()
204192
}
205193
}
206194
}

templates/base.html

+42-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,42 @@
1-
<body>
2-
{{ content }}
3-
</body>
1+
<html>
2+
<head>
3+
<title>{% block title %}{{ title }}{% endblock %} - CDKTF News</title>
4+
{% block head %}{% endblock %}
5+
<style>
6+
#content {
7+
background-color: #f5f5f5;
8+
padding: 0.5em;
9+
}
10+
11+
.items {
12+
display: flex;
13+
flex-wrap: wrap;
14+
justify-content: center;
15+
}
16+
17+
.item {
18+
border-radius: 0.5em;
19+
color: black;
20+
display: block;
21+
font-size: 1.5em;
22+
margin: 1em;
23+
padding: 0.5em;
24+
text-decoration: none;
25+
width: 9em;
26+
word-break: break-word;
27+
}
28+
29+
.item-src-stackoverflow {
30+
background-color: rgb(230, 134, 58);
31+
}
32+
33+
.item-src-twitter {
34+
background-color: rgb(72, 155, 233);
35+
color: white;
36+
}
37+
</style>
38+
</head>
39+
<body>
40+
<div id="content">{% block content %}{% endblock %}</div>
41+
</body>
42+
</html>

templates/error.html

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
<body>
2-
<h1>An Error occured</h1>
1+
{% extends "base.html" %} {% block title %}Error{% endblock %} {% block head %}
2+
<style></style>
3+
{% endblock %} {% block content %}
4+
<h1>An Error occured</h1>
35

4-
<p>{{ message }}</p>
5-
</body>
6+
<p>{{ message }}</p>
7+
{% endblock %}

templates/index.html

+8-13
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
<body>
2-
<h1>All Items</h1>
3-
4-
<h2>Twitter</h2>
5-
<ul>
6-
{{ twitter_items }}
7-
</ul>
8-
9-
<h2>StackOverflow</h2>
10-
<ul>
11-
{{ stackoverflow_items }}
12-
</ul>
13-
</body>
1+
{% extends "base.html" %} {% block title %}All Items{% endblock %} {% block head
2+
%}
3+
<style></style>
4+
{% endblock %} {% block content %}
5+
<h1>All Items</h1>
6+
<div class="items">
7+
{% for item in items %} {% include "item.html" %} {% endfor %} {% endblock %}
8+
</div>

templates/item.html

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<a href="{{ item.url }}" class="item item-src-{{ item.source }}">
2+
{{ item.title }}
3+
</a>

0 commit comments

Comments
 (0)