Commit a2905002 authored by yPhil's avatar yPhil
Browse files

Streamlined populate()

- On lastItems() in both cases
parent de3f00c3
...@@ -281,10 +281,8 @@ PTL.dialog = { ...@@ -281,10 +281,8 @@ PTL.dialog = {
newName = DOMPurify.sanitize($(this).find('input#feedNameInput').val()), newName = DOMPurify.sanitize($(this).find('input#feedNameInput').val()),
newType = $('#feedTypeDiv :radio:checked').attr('id'); newType = $('#feedTypeDiv :radio:checked').attr('id');
$dataStore $dataStore
.data('url', newUrl) .data('url', newUrl)
.attr('data-dummyurl', newUrl)
.data('name', newName) .data('name', newName)
.data('type', newType); .data('type', newType);
......
...@@ -95,28 +95,29 @@ PTL.feed = { ...@@ -95,28 +95,29 @@ PTL.feed = {
await PTL.feed.populate($(this), progress); await PTL.feed.populate($(this), progress);
}); });
// const $feedControls = $('<div>').attr('class', 'feedControls dataStore')
// .data('index', feedIndex)
// .data('url', url)
// .data('name', name)
// .data('type', type)
// .data('limit', limit)
// .data('status', status)
// .data('iconhash', iconhash)
// .data('nbitems', nbitems)
// .data('lastitem', lastitem);
const $feedControls = $('<div>') const $feedControls = $('<div>')
.attr('class', 'feedControls dataStore') .attr('class', 'feedControls dataStore')
.attr('data-index', feedIndex) .data('index', feedIndex)
.attr('data-url', url) .data('url', url)
.attr('data-name', name) .data('name', name)
.attr('data-type', type) .data('type', type)
.attr('data-limit', limit) .data('limit', limit)
.attr('data-status', status) .data('status', status)
.attr('data-iconhash', iconhash) .data('iconhash', iconhash)
.attr('data-nbitems', nbitems) .data('nbitems', nbitems)
.attr('data-lastitem', lastitem); .data('lastitem', lastitem);
// const $feedControls = $('<div>')
// .attr('class', 'feedControls dataStore')
// .attr('data-index', feedIndex)
// .attr('data-url', url)
// .attr('data-name', name)
// .attr('data-type', type)
// .attr('data-limit', limit)
// .attr('data-status', status)
// .attr('data-iconhash', iconhash)
// .attr('data-nbitems', nbitems)
// .attr('data-lastitem', lastitem);
if ($feedControls.data('status') == 'on') { if ($feedControls.data('status') == 'on') {
$refreshIcon.removeClass('icon-pin') $refreshIcon.removeClass('icon-pin')
...@@ -572,7 +573,7 @@ PTL.feed = { ...@@ -572,7 +573,7 @@ PTL.feed = {
await PTL.feed.fetchIcon(feedHost).then((iconhash) => { await PTL.feed.fetchIcon(feedHost).then((iconhash) => {
if (iconhash) { if (iconhash) {
$favIcon.attr('src', '/favicons/' + iconhash + '.favicon'); $favIcon.attr('src', '/favicons/' + iconhash + '.favicon');
$dataStore.attr('data-iconhash', iconhash); $dataStore.data('iconhash', iconhash);
PTL.tab.saveTabs(); PTL.tab.saveTabs();
} }
}).catch((error) => { }).catch((error) => {
...@@ -586,124 +587,52 @@ PTL.feed = { ...@@ -586,124 +587,52 @@ PTL.feed = {
console.log('Catched favicon error: %s (%s)', error); console.log('Catched favicon error: %s (%s)', error);
} }
feedTitle = (feedName) ? feedName : feedUrl; console.log('feedLastItem: [%s] (%s)', feedLastItem, feedUrl);
$feedLink.text(feedTitle)
$feedLink
.attr('href', feedUrl) .attr('href', feedUrl)
.attr('title', feedTitle + ' (' + feedUrl + ')')
.removeClass('danger'); .removeClass('danger');
console.log('feedLastItem: [%s] (%s)', feedLastItem, feedUrl);
try { try {
let feed = await PTL.db.get(feedUrl); let feedInDb = await PTL.db.get(feedUrl);
if (feed) {
// console.log('Feed is in the DB, feedLastItem: %s (%s)', feedLastItem);
$feedBody.html(feed.content);
try {
let currentLastItem = $dataStore.attr('data-lastitem');
console.log('currentLastItem: [%s] feedLastItem: [%s] (%s)', currentLastItem, feedLastItem, feedUrl);
let fetchFeed = await PTL.feed.fetchFeed(feedUrl, currentLastItem);
if (fetchFeed.lastItem) {
// console.log('yes, fetchFeed.lastItem: %s (feedLastItem %s)', fetchFeed.lastItem, feedLastItem);
}
$dataStore.attr('data-lastitem', fetchFeed.lastItem);
if (fetchFeed.thereAreNewItems) {
let lastItems = await PTL.feed.lastItems(fetchFeed.feedItems, $dataStore);
console.log('thereAreNewItems: %s (%s)', fetchFeed.thereAreNewItems, feedUrl);
// console.log('feedLastItem [%s] lastItems: (%s)', feedLastItem, JSON.stringify(lastItems[0]));
$feedBody.prepend(lastItems[0]);
PTL.db.put(feedUrl, $feedBody.html());
$badge.fadeIn('slow').text(lastItems[1]);
} else { if (feedInDb) $feedBody.html(feedInDb.content);
$badge.fadeOut('slow');
}
$refreshButton try {
.prop('title', PTL.tr('Refresh this feed (%1 - %2)', feedName || feedUrl, timeStamp))
.removeClass('spin');
} catch (error) { let fetchFeed = await PTL.feed.fetchFeed(feedUrl, feedLastItem);
$feedBody.empty().append(PTL.feed.errorFeed(error, feedUrl)); $feedLink
$feedBody.css('height', ''); .text(fetchFeed.feedTitle)
$refreshButton.removeClass('spin'); .attr('title', fetchFeed.feedTitle + ' (' + feedUrl + ')');
if (fetchFeed.thereAreNewItems) {
$dataStore.data('lastitem', fetchFeed.lastItem);
let lastItems = await PTL.feed.lastItems(fetchFeed.feedItems, $dataStore);
$feedBody.prepend(lastItems[0]);
PTL.db.put(feedUrl, $feedBody.html());
$badge.text(lastItems[1]).fadeIn('slow');
} else {
$badge.fadeOut('slow');
} }
} else { $refreshButton
.prop('title', PTL.tr('Refresh this feed (%1 - %2)', feedName || feedUrl, timeStamp))
try { .removeClass('spin');
let fetchFeed = await PTL.feed.fetchFeed(feedUrl, 'feedLastItem');
if (feedName) {
feedTitle = feedName;
} else if (fetchFeed.feedTitle) {
feedTitle = fetchFeed.feedTitle;
$dataStore.attr('data-name', feedTitle);
}
$feedLink.text(feedTitle)
.attr('href', feedUrl)
.attr('title', feedTitle + ' (' + feedUrl + ')');
try {
let lastItems = await PTL.feed.lastItems(fetchFeed.feedItems, $dataStore);
// console.log('trying lastiItems: %s (%s)', JSON.stringify(lastItems[0]));
if (lastItems) {
$feedBody.html(lastItems[0]);
let feedBody = $($feedBody);
} catch (error) {
PTL.db.put(feedUrl, feedBody.html()); $feedBody.empty().append(PTL.feed.errorFeed(error, feedUrl));
$dataStore.attr('data-lastitem', fetchFeed.lastItem); $feedBody.css('height', '');
$refreshButton.removeClass('spin');
$refreshButton
.prop('title',
PTL.tr('Refresh this feed (%1 - %2)', feedName || feedUrl, timeStamp))
.removeClass('spin');
}
} catch (error) {
console.log('lastItems caught: %s (%s)', JSON.stringify(error), feedUrl);
}
} catch (error) {
console.log('fetchFeed caught: %s (%s)', error);
$feedBody.empty().append(PTL.feed.errorFeed(error, feedUrl));
$feedBody.css('height', '');
$refreshButton.removeClass('spin');
}
} }
} catch (error) { } catch (error) {
console.log('getFeed caught: %s (%s)', error); console.log('getFeed caught: %s (%s)', error);
} }
if (progress) progress.increment(); if (progress) progress.increment();
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment