add bookmarks view
This commit is contained in:
62
data/static/js/bits/bookmarks.js
Normal file
62
data/static/js/bits/bookmarks.js
Normal file
@@ -0,0 +1,62 @@
|
||||
export const b = {
|
||||
init: 'restoreCollectionDetails restoreThreadDetails restorePostDetails',
|
||||
}
|
||||
|
||||
const COLLECTION_DETAILS_KEY = 'collectionsOpen';
|
||||
const THREAD_DETAILS_KEY = 'threadsOpen';
|
||||
const POST_DETAILS_KEY = 'postsOpen';
|
||||
|
||||
let collectionDetailsData = {};
|
||||
let collectionThreadDetailsData = {};
|
||||
let collectionPostDetailsData = {};
|
||||
|
||||
async function setDetailsData(obj, key, id, isOpen) {
|
||||
obj[id] = isOpen;
|
||||
await b.savePageData(obj, key);
|
||||
}
|
||||
|
||||
export async function restoreCollectionDetails(_, __, el) {
|
||||
collectionDetailsData = await b.loadPageData(COLLECTION_DETAILS_KEY, {});
|
||||
el.open = collectionDetailsData[el.dataset.id] === true;
|
||||
}
|
||||
|
||||
export async function setCollectionDetails(ev, sender, el) {
|
||||
if (el !== sender) {
|
||||
return;
|
||||
}
|
||||
if (ev.target !== el.querySelector('summary')) {
|
||||
return;
|
||||
}
|
||||
console.log(!el.open);
|
||||
await setDetailsData(collectionDetailsData, COLLECTION_DETAILS_KEY, el.dataset.id, !el.open);
|
||||
}
|
||||
|
||||
export async function restoreThreadDetails(_, __, el) {
|
||||
collectionThreadDetailsData = await b.loadPageData(THREAD_DETAILS_KEY, {});
|
||||
el.open = collectionThreadDetailsData[el.dataset.id] === true;
|
||||
}
|
||||
|
||||
export async function setThreadDetails(ev, sender, el) {
|
||||
if (el !== sender) {
|
||||
return;
|
||||
}
|
||||
if (ev.target !== el.querySelector('summary')) {
|
||||
return;
|
||||
}
|
||||
await setDetailsData(collectionThreadDetailsData, THREAD_DETAILS_KEY, el.dataset.id, !el.open);
|
||||
}
|
||||
|
||||
export async function restorePostDetails(_, __, el) {
|
||||
collectionPostDetailsData = await b.loadPageData(POST_DETAILS_KEY, {});
|
||||
el.open = collectionPostDetailsData[el.dataset.id] === true;
|
||||
}
|
||||
|
||||
export async function setPostDetails(ev, sender, el) {
|
||||
if (el !== sender) {
|
||||
return;
|
||||
}
|
||||
if (ev.target !== el.querySelector('summary')) {
|
||||
return;
|
||||
}
|
||||
await setDetailsData(collectionPostDetailsData, POST_DETAILS_KEY, el.dataset.id, !el.open);
|
||||
}
|
||||
Reference in New Issue
Block a user