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 = {
newName = DOMPurify.sanitize($(this).find('input#feedNameInput').val()),
newType = $('#feedTypeDiv :radio:checked').attr('id');
$dataStore
.data('url', newUrl)
.attr('data-dummyurl', newUrl)
.data('name', newName)
.data('type', newType);
......
......@@ -95,28 +95,29 @@ PTL.feed = {
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>')
.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);
.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>')
// .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') {
$refreshIcon.removeClass('icon-pin')
......@@ -572,7 +573,7 @@ PTL.feed = {
await PTL.feed.fetchIcon(feedHost).then((iconhash) => {
if (iconhash) {
$favIcon.attr('src', '/favicons/' + iconhash + '.favicon');
$dataStore.attr('data-iconhash', iconhash);
$dataStore.data('iconhash', iconhash);
PTL.tab.saveTabs();
}
}).catch((error) => {
......@@ -586,124 +587,52 @@ PTL.feed = {
console.log('Catched favicon error: %s (%s)', error);
}
feedTitle = (feedName) ? feedName : feedUrl;
$feedLink.text(feedTitle)
console.log('feedLastItem: [%s] (%s)', feedLastItem, feedUrl);
$feedLink
.attr('href', feedUrl)
.attr('title', feedTitle + ' (' + feedUrl + ')')
.removeClass('danger');
console.log('feedLastItem: [%s] (%s)', feedLastItem, feedUrl);
try {
let feed = 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]);
let feedInDb = await PTL.db.get(feedUrl);
} else {
$badge.fadeOut('slow');
}
if (feedInDb) $feedBody.html(feedInDb.content);
$refreshButton
.prop('title', PTL.tr('Refresh this feed (%1 - %2)', feedName || feedUrl, timeStamp))
.removeClass('spin');
try {
} catch (error) {
let fetchFeed = await PTL.feed.fetchFeed(feedUrl, feedLastItem);
$feedBody.empty().append(PTL.feed.errorFeed(error, feedUrl));
$feedBody.css('height', '');
$refreshButton.removeClass('spin');
$feedLink
.text(fetchFeed.feedTitle)
.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 {
try {
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);
$refreshButton
.prop('title', PTL.tr('Refresh this feed (%1 - %2)', feedName || feedUrl, timeStamp))
.removeClass('spin');
} catch (error) {
PTL.db.put(feedUrl, feedBody.html());
$dataStore.attr('data-lastitem', fetchFeed.lastItem);
$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');
}
$feedBody.empty().append(PTL.feed.errorFeed(error, feedUrl));
$feedBody.css('height', '');
$refreshButton.removeClass('spin');
}
} catch (error) {
console.log('getFeed caught: %s (%s)', error);
}
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