diff --git a/public/index.html b/public/index.html index 01b44c3c4..ceb0010ca 100644 --- a/public/index.html +++ b/public/index.html @@ -1336,6 +1336,10 @@
+ + + Back to main chat + Save bookmark diff --git a/public/script.js b/public/script.js index 1503c1917..3baf48172 100644 --- a/public/script.js +++ b/public/script.js @@ -68,6 +68,8 @@ import { nai_settings, } from "./scripts/nai-settings.js"; +import { showBookmarksButtons } from "./scripts/bookmarks.js"; + import { debounce, delay } from "./scripts/utils.js"; //exporting functions and vars for mods @@ -95,6 +97,8 @@ export { setSendButtonState, selectRightMenuWithAnimation, setRightTabSelectedClass, + openCharacterChat, + saveChat, messageFormating, chat, this_chid, @@ -115,7 +119,6 @@ export { system_message_types, talkativeness_default, default_ch_mes, - saveChat, } // API OBJECT FOR EXTERNAL WIRING @@ -154,6 +157,9 @@ const system_avatar = "img/five.png"; let is_colab = false; let is_checked_colab = false; let is_mes_reload_avatar = false; +let optionsPopper = Popper.createPopper(document.getElementById('options_button'), document.getElementById('options'), { + placement: 'top-start', +}); const durationSaveEdit = 200; const saveSettingsDebounced = debounce(() => saveSettings(), durationSaveEdit); @@ -1887,6 +1893,17 @@ function getChatResult() { select_selected_character(this_chid); } +async function openCharacterChat(file_name) { + characters[this_chid]["chat"] = file_name; + clearChat(); + chat.length = 0; + await getChat(); + $("#selected_chat_pole").val(file_name); + $("#create_button").click(); + $("#shadow_select_chat_popup").css("display", "none"); + $("#load_select_chat_div").css("display", "block"); +} + /* function openNavToggle() { if (!$("#nav-toggle").prop("checked")) { $("#nav-toggle").trigger("click"); @@ -3593,12 +3610,13 @@ $(document).ready(function () { $("#options").css("display") === "none" && $("#options").css("opacity") == 0.0 ) { + showBookmarksButtons(); $("#options").css("display", "block"); $("#options").transition({ opacity: 1.0, // the manual setting of CSS via JS is what allows the click-away feature to work duration: 100, easing: animation_rm_easing, - complete: function () { }, + complete: function () { optionsPopper.update(); }, }); } }); @@ -4110,27 +4128,8 @@ $(document).ready(function () { }); $(document).on("click", ".select_chat_block, .bookmark_link", async function () { - let originalChat = characters[this_chid]["chat"]; let file_name = $(this).attr("file_name").replace(".jsonl", ""); - //console.log(characters[this_chid]['chat']); - characters[this_chid]["chat"] = file_name; - clearChat(); - chat.length = 0; - await getChat(); - $("#selected_chat_pole").val(file_name); - $("#create_button").click(); - $("#shadow_select_chat_popup").css("display", "none"); - $("#load_select_chat_div").css("display", "block"); - - // create "return back" message - /*if ($(this).hasClass('bookmark_link')) { - const existingMessageIndex = chat.findIndex(x => x.extras?.type === system_message_types.BOOKMARK_BACK); - - if (existingMessageIndex === -1) { - const messageText = stringFormat(system_messages[system_message_types.BOOKMARK_BACK].mes, originalChat); - sendSystemMessage(system_message_types.BOOKMARK_BACK, messageText); - } - }*/ + openCharacterChat(file_name); }); $('.drawer-toggle').click(function () { diff --git a/public/scripts/bookmarks.js b/public/scripts/bookmarks.js index 55017cc33..24cd1328c 100644 --- a/public/scripts/bookmarks.js +++ b/public/scripts/bookmarks.js @@ -2,11 +2,11 @@ import { characters, saveChat, sendSystemMessage, - deleteLastMessage, token, system_messages, system_message_types, this_chid, + openCharacterChat, } from "../script.js"; import { selected_group } from "./group-chats.js"; @@ -14,14 +14,20 @@ import { stringFormat, } from "./utils.js"; +export { + showBookmarksButtons, +} + +const bookmarkNameToken = 'Bookmark #'; + async function getExistingChatNames() { - const response = await fetch("/getallchatsofcharacter", { + const response = await fetch("/getallchatsofcharacter", { method: 'POST', headers: { 'Content-Type': 'application/json', "X-CSRF-Token": token, }, - body: JSON.stringify({ avatar_url: characters[this_chid].avatar}) + body: JSON.stringify({ avatar_url: characters[this_chid].avatar }) }); if (response.ok) { @@ -31,18 +37,14 @@ async function getExistingChatNames() { } async function getBookmarkName(currentChat) { - const nameToken = 'Bookmark #'; - if (currentChat.includes(nameToken)) { - currentChat = currentChat.substring(0, currentChat.lastIndexOf(nameToken)).trim(); - } - const chatNames = await getExistingChatNames(); + let mainChat = getMainChatName(currentChat); let newChat = Date.now(); let friendlyName = ''; for (let i = 0; i < 1000; i++) { - friendlyName = `${nameToken}${i}`; - newChat = `${currentChat} ${friendlyName}`; + friendlyName = `${bookmarkNameToken}${i}`; + newChat = `${mainChat} ${friendlyName}`; if (!chatNames.includes(newChat)) { break; } @@ -50,11 +52,37 @@ async function getBookmarkName(currentChat) { return { newChat, friendlyName }; } +function getMainChatName(currentChat) { + if (currentChat.includes(bookmarkNameToken)) { + currentChat = currentChat.substring(0, currentChat.lastIndexOf(bookmarkNameToken)).trim(); + } + return currentChat; +} + +function showBookmarksButtons() { + // In groups + if (selected_group) { + $("#option_back_to_main").hide(); + $("#option_new_bookmark").hide(); + } + // In main chat + else if (!characters[this_chid].chat.includes(bookmarkNameToken)) { + $("#option_back_to_main").hide(); + $("#option_new_bookmark").show(); + + } + // In bookmark chat + else { + $("#option_back_to_main").show(); + $("#option_new_bookmark").show(); + } +} + $(document).ready(function () { $('#option_new_bookmark').on('click', async function () { if (selected_group) { - alert('Unsupported for groups'); - throw new Error('not yet implemented'); + alert('Chat bookmarks unsupported for groups'); + throw new Error(); } let { newChat, friendlyName } = await getBookmarkName(characters[this_chid].chat); @@ -64,5 +92,13 @@ $(document).ready(function () { sendSystemMessage(system_message_types.BOOKMARK_CREATED, mainMessage); saveChat(); }); -}); + $('#option_back_to_main').on('click', async function() { + const mainChatName = getMainChatName(characters[this_chid].chat); + const allChats = await getExistingChatNames(); + + if (allChats.includes(mainChatName)) { + openCharacterChat(mainChatName); + } + }); +}); diff --git a/public/style.css b/public/style.css index 17beb176b..f3be7e299 100644 --- a/public/style.css +++ b/public/style.css @@ -309,6 +309,7 @@ margin-top:5px; text-shadow: 0 0 3px black; min-width: 200px; z-index: 2000; + margin-bottom: 13px; } .options-content hr { @@ -1983,7 +1984,7 @@ right: -30px; .select_chat_block_wrapper{ display: grid; - grid-template-columns: auto auto; + grid-template-columns: auto min-content; align-items: center; grid-gap: 10px; } diff --git a/readme.md b/readme.md index 6c21a350d..97e0b094a 100644 --- a/readme.md +++ b/readme.md @@ -103,4 +103,5 @@ Contact us on Discord: Cohee#1207 or RossAscends#1779 * TAI Base by Humi: Unknown license * SillyLossy's TAI mod: Public domain * RossAscends' additions: Public domain -* Portions of CncAnon's TavernAITurbo mod: Unknown license \ No newline at end of file +* Portions of CncAnon's TavernAITurbo mod: Unknown license +* Thanks oobabooga for compiling presets for TextGen