SimpleChatTCRV:iDB:GetKeys: helps decide whether restore btn shown
This commit is contained in:
parent
570131943f
commit
ca8e6ab1a6
|
|
@ -103,3 +103,31 @@ export function db_get(dbName, storeName, key, callerTag, cb) {
|
||||||
cb(false, errReason)
|
cb(false, errReason)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return all keys from a store in a db,
|
||||||
|
* through the provided callback.
|
||||||
|
*
|
||||||
|
* @param {string} dbName
|
||||||
|
* @param {string} storeName
|
||||||
|
* @param {string | undefined} callerTag
|
||||||
|
* @param {(status: boolean, related: IDBValidKey[] | DOMException | null) => void} cb
|
||||||
|
*/
|
||||||
|
export function db_getkeys(dbName, storeName, callerTag, cb) {
|
||||||
|
let tag = `iDB:GetKeys:${callerTag}`;
|
||||||
|
db_open(dbName, storeName, tag).then((/** @type {IDBDatabase} */db)=>{
|
||||||
|
let reqGet = db_trans_store(db, storeName, 'readonly').getAllKeys();
|
||||||
|
reqGet.onsuccess = (evGet) => {
|
||||||
|
console.info(`DBUG:${tag}:transact success`)
|
||||||
|
cb(true, reqGet.result)
|
||||||
|
}
|
||||||
|
reqGet.onerror = (evGet) => {
|
||||||
|
console.info(`ERRR:${tag}:OnError:transact failed:${reqGet.error}`)
|
||||||
|
cb(false, reqGet.error)
|
||||||
|
}
|
||||||
|
}).catch((errReason)=>{
|
||||||
|
console.info(`ERRR:${tag}:Caught:transact failed:${errReason}`)
|
||||||
|
cb(false, errReason)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -737,7 +737,9 @@ sliding window based drop off or even before they kick in, this can help in many
|
||||||
* UI Cleanup - msgs spaced out, toolcall edit hr not always, scroll ui only when required,
|
* UI Cleanup - msgs spaced out, toolcall edit hr not always, scroll ui only when required,
|
||||||
hide settings/info till user requests, heading gradient
|
hide settings/info till user requests, heading gradient
|
||||||
|
|
||||||
* iDB module - add open, transact, put and get. Use for chat session save and load
|
* iDB module
|
||||||
|
* add open, transact, put and get. Use for chat session save and load
|
||||||
|
* getKeys used to show Restore/Load button wrt chat sessions.
|
||||||
|
|
||||||
|
|
||||||
#### ToDo
|
#### ToDo
|
||||||
|
|
|
||||||
|
|
@ -1674,13 +1674,20 @@ export class Me {
|
||||||
* @param {SimpleChat} chat
|
* @param {SimpleChat} chat
|
||||||
*/
|
*/
|
||||||
setup_load(div, chat) {
|
setup_load(div, chat) {
|
||||||
if (!(chat.ods_key() in localStorage)) {
|
let tag = `Me:Load:${chat.chatId}`;
|
||||||
|
mIdb.db_getkeys(DB_NAME, DB_STORE, tag, (status, related)=>{
|
||||||
|
if (!status || (related == null)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (related.constructor.name == DOMException.name) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (/** @type {IDBValidKey[]} */(related).indexOf(chat.ods_key()) == -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
div.innerHTML += `<p class="role-system">Restore</p>
|
div.innerHTML += `<p class="role-system">Restore</p>
|
||||||
<p>Load previously saved chat session, if available</p>`;
|
<p>Load previously saved chat session, if available</p>`;
|
||||||
let btn = ui.el_create_button(chat.ods_key(), (ev)=>{
|
let btn = ui.el_create_button(chat.ods_key(), (ev)=>{
|
||||||
let tag = `Me:Load:${chat.chatId}`;
|
|
||||||
console.log(`DBUG:${tag}`, chat);
|
console.log(`DBUG:${tag}`, chat);
|
||||||
chat.load((loadStatus, dbStatus, related)=>{
|
chat.load((loadStatus, dbStatus, related)=>{
|
||||||
if (!loadStatus || !dbStatus) {
|
if (!loadStatus || !dbStatus) {
|
||||||
|
|
@ -1695,6 +1702,7 @@ export class Me {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
div.appendChild(btn);
|
div.appendChild(btn);
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue