Skip to content

Commit

Permalink
Add date route.
Browse files Browse the repository at this point in the history
- Starts getting news from date.
- Updates hash as more news loaded.
  • Loading branch information
Leftium committed May 7, 2022
1 parent 7813887 commit 57c3082
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 121 deletions.
12 changes: 10 additions & 2 deletions assets/js/hw.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,12 @@
$homeScrollSection.innerHTML = tmpl1.render({ load_error: true });
hw.pub('logAPIError', 'news');
};
hnapi.news(null, function (data) {
var date = null;
// Grab date from hash.
if (location.hash) {
date = location.hash.slice(7);
}
hnapi.news(date, function (data) {
loadingNews = false;
if (!data || data.error) {
showError();
Expand All @@ -230,6 +235,7 @@
}
},
reload: function () {
ruto.go('/')
amplify.store('news-latest', null); // force cache flush
hnapi.number = 1;
hw.news.render({
Expand All @@ -243,6 +249,7 @@

var date = target.dataset.date;
hnapi.news(date, function (news) {
history.replaceState(null, null, document.location.pathname + '#/date/' + news.curr);
target.classList.remove('loading');
var targetParent = target.parentNode;
if (!targetParent) return;
Expand Down Expand Up @@ -457,7 +464,7 @@
};

hw.init = function () {
console.log('INIT JKM 2022.05.07 725');
console.log('INIT JKM 2022.05.07 853');
hw.news.render();
ruto.init();

Expand Down Expand Up @@ -532,6 +539,7 @@
}
})
.add('/', 'home')
.add(/^\/date\/(\d+)$/i, 'home')
.add('/about', 'about')
.add(/^\/item\/(\d+)$/i, 'comments', function (path, id) {
hw.comments.render(id);
Expand Down
1 change: 1 addition & 0 deletions assets/js/libs/hnapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@

function onSuccess(data) {
var results = process_entries(data);
results.curr = date;
success(results);
};

Expand Down
111 changes: 56 additions & 55 deletions js/hw-ios-2.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/hw-ios-2.min.js.map

Large diffs are not rendered by default.

66 changes: 33 additions & 33 deletions js/hw-ios.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/hw-ios.min.js.map

Large diffs are not rendered by default.

56 changes: 28 additions & 28 deletions js/hw-web.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/hw-web.min.js.map

Large diffs are not rendered by default.

0 comments on commit 57c3082

Please sign in to comment.