Skip to content

Commit 5db192e

Browse files
committedFeb 3, 2022
Add love sorting
1 parent 4f78a94 commit 5db192e

File tree

7 files changed

+591
-68
lines changed

7 files changed

+591
-68
lines changed
 

‎docs/_data/love.json

+456-62
Large diffs are not rendered by default.

‎docs/_includes/elements/tw.html

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
{% assign tweet = site.data.love.tweets_by_id[include.tweet_id] %}
22
{% assign twUrl = "https://twitter.com/" | append: tweet.username | append: "/status/" | append: tweet.id %}
33

4-
<article class="bd-tw {{ include.modifier }} {% if include.drawing_id %}bd-has-drawing{% endif %}">
4+
<article
5+
data-likes="{{ tweet.hearts }}"
6+
data-id="{{ tweet.id }}"
7+
class="bd-tw {{ include.modifier }} {% if include.drawing_id %}bd-has-drawing{% endif %}">
58
<header class="bd-tw-header">
69
<a class="bd-tw-author" href="{{ twUrl }}" target="_blank">
710
<figure class="bd-tw-avatar">

‎docs/_sass/components/pill.scss

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
.bd-pills {
2+
@extend %block;
3+
align-items: center;
4+
color: $text-light;
5+
display: flex;
6+
justify-content: center;
7+
}
8+
9+
.bd-pill-label {
10+
padding: 0 0.5em;
11+
}
12+
13+
.bd-pills-body {
14+
background: $background;
15+
align-items: center;
16+
background: #fafafa;
17+
border-radius: 0.5em;
18+
display: flex;
19+
padding: 0.25em;
20+
}
21+
22+
.bd-pill-button {
23+
@extend %reset;
24+
border-radius: 0.25em;
25+
color: $text;
26+
cursor: pointer;
27+
font-weight: 500;
28+
padding: 0.5em 0.75em;
29+
position: relative;
30+
transition-duration: 0.5s;
31+
transition-property: color, background-color;
32+
33+
&:hover {
34+
background-color: $white;
35+
color: $text-strong;
36+
}
37+
38+
&.is-active {
39+
background-color: $white;
40+
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.05), 0 0.125em 0.125em rgba(0, 0, 0, 0.05);
41+
color: $text-strong;
42+
z-index: 1;
43+
}
44+
}

‎docs/bulma-docs.scss

+1
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ $navbar-breakpoint: $tablet;
222222
@import "./_sass/components/spacing-table";
223223
@import "./_sass/components/survey";
224224
@import "./_sass/components/color";
225+
@import "./_sass/components/pill";
225226

226227
@import "./_sass/pages/index";
227228
@import "./_sass/pages/docs";

‎docs/css/bulma-docs.css

+46-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/css/bulma-docs.min.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/love.html

+39-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,45 @@
4545
button=call_button
4646
%}
4747

48-
<div class="bd-tws">
48+
<script type="text/javascript">
49+
function compareTweets(key) {
50+
return (a, b) => {
51+
const avalue = parseInt(a.dataset[key]);
52+
const bvalue = parseInt(b.dataset[key]);
53+
54+
if (avalue > bvalue)
55+
return -1;
56+
57+
if (avalue < bvalue)
58+
return 1;
59+
60+
return 0;
61+
}
62+
}
63+
64+
function sortTweets(key) {
65+
const $pills = document.querySelectorAll("#bd-pills .bd-pill-button");
66+
$pills.forEach($pill => $pill.classList.remove('is-active'));
67+
window.event.target.classList.add('is-active');
68+
69+
const $tweets = document.querySelectorAll("#love-tweets .bd-tw");
70+
const tweets = Array.from($tweets);
71+
let sorted = tweets.sort(compareTweets(key));
72+
73+
sorted.forEach(e =>
74+
document.querySelector("#love-tweets .bd-tws-list").appendChild(e));
75+
}
76+
</script>
77+
78+
<nav id="bd-pills" class="bd-pills">
79+
<div class="bd-pills-body">
80+
<span class="bd-pill-label">Sort by</span>
81+
<button class="bd-pill-button is-active" onclick="sortTweets('id')">Date</button>
82+
<button class="bd-pill-button" onclick="sortTweets('likes')">Likes</button>
83+
</div>
84+
</nav>
85+
86+
<div id="love-tweets" class="bd-tws">
4987
<div class="bd-tws-list">
5088
{% for tweet_pair in site.data.love.tweets_by_id reversed %}
5189
{% assign tweet_id = tweet_pair[0] %}

0 commit comments

Comments
 (0)
Please sign in to comment.