Commit 0f09cf11 authored by yPhil's avatar yPhil
Browse files

Populate() is async

- Delete feed from db OK
parent 12e298cf
// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later
PTL.db = {
delete: function(db, url) {
const txn = db.transaction(PTL.DbStore, 'readwrite');
const store = txn.objectStore(PTL.DbStore);
let query = store.delete(url);
query.onsuccess = function (event) {
console.log(event);
};
query.onerror = function (event) {
console.log(event.target.errorCode);
};
txn.oncomplete = function () {
db.close();
};
delete: function(url) {
return new Promise((resolve, reject) => {
let dbOpen = indexedDB.open(PTL.DbName, PTL.DbVersion);
dbOpen.onsuccess = event => {
var db = event.target.result;
const txn = db.transaction(PTL.DbStore, 'readwrite');
const store = txn.objectStore(PTL.DbStore);
let query = store.delete(url);
query.onsuccess = function (event) {
console.log(event);
console.log('DEL OK: %s (%s)', event);
};
query.onerror = function (event) {
console.log('DEL NOK: %s (%s)', event.target.errorCode);
};
txn.oncomplete = function () {
db.close();
};
};
});
},
getFeed: function(url) {
......@@ -54,35 +65,35 @@ PTL.db = {
};
});
},
putFeed: function(url, content) {
},
putFeed: function(url, content) {
return new Promise((resolve, reject) => {
return new Promise((resolve, reject) => {
let dbOpen = indexedDB.open(PTL.DbName, PTL.DbVersion);
dbOpen.onsuccess = event => {
let dbOpen = indexedDB.open(PTL.DbName, PTL.DbVersion);
dbOpen.onsuccess = event => {
var db = event.target.result;
var db = event.target.result;
const txn = db.transaction(PTL.DbStore, 'readwrite');
const store = txn.objectStore(PTL.DbStore);
const feed = {url: url, content: content};
let query = store.put(feed);
const txn = db.transaction(PTL.DbStore, 'readwrite');
const store = txn.objectStore(PTL.DbStore);
const feed = {url: url, content: content};
let query = store.put(feed);
query.onsuccess = event => {
resolve();
// console.log(event);
};
query.onsuccess = event => {
resolve();
// console.log(event);
};
query.onerror = event => {
reject();
// console.log(event.target.errorCode);
};
query.onerror = event => {
reject();
// console.log(event.target.errorCode);
};
txn.oncomplete = () => {
db.close();
txn.oncomplete = () => {
db.close();
};
};
};
});
}
});
}
};
This diff is collapsed.
......@@ -609,7 +609,7 @@ PTL.feed = {
if (feed) {
console.log('feed: %s (%s)', JSON.stringify(feed));
console.log('Feed is in the DB, feedLastItem: %s (%s)', feedLastItem);
$feedBody.html(feed.content);
......@@ -617,6 +617,7 @@ PTL.feed = {
let fetchFeed = await PTL.feed.fetchFeed(feedUrl, feedLastItem);
if (fetchFeed.lastItem) {
console.log('yes, fetchFeed.lastItem: %s (feedLastItem %s)', fetchFeed.lastItem, feedLastItem);
$dataStore.attr('data-lastitem', fetchFeed.lastItem);
}
......@@ -624,6 +625,8 @@ PTL.feed = {
let lastItems = await PTL.feed.lastItems(fetchFeed.feedItems, $dataStore);
console.log('feedLastItem [%s] lastItems: (%s)', feedLastItem, JSON.stringify(lastItems[0]));
$feedBody.prepend(lastItems[0]);
PTL.db.putFeed(feedUrl, $feedBody.html());
......
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