Fix imported char flashing with pagination

This commit is contained in:
Cohee 2023-08-27 04:01:13 +03:00
parent 2685bf95fe
commit 0d8a83e6b6

View File

@ -320,6 +320,7 @@ let safetychat = [
}, },
]; ];
let chatSaveTimeout; let chatSaveTimeout;
let importFlashTimeout;
export let isChatSaving = false; export let isChatSaving = false;
let chat_create_date = 0; let chat_create_date = 0;
let firstRun = false; let firstRun = false;
@ -5708,19 +5709,39 @@ function select_rm_info(type, charId, previousCharId = null) {
selectRightMenuWithAnimation('rm_characters_block'); selectRightMenuWithAnimation('rm_characters_block');
setTimeout(function () { // Set a timeout so multiple flashes don't overlap
clearTimeout(importFlashTimeout);
importFlashTimeout = setTimeout(function () {
if (type === 'char_import' || type === 'char_create') { if (type === 'char_import' || type === 'char_create') {
const element = $(`#rm_characters_block [title="${charId}"]`).parent().get(0); // Find the page at which the character is located
console.log(element); const charData = getEntitiesList({ doFilter: true });
element.scrollIntoView({ behavior: 'smooth', block: 'start' }); const charIndex = charData.findIndex((x) => x?.item?.avatar?.startsWith(charId));
if (charIndex === -1) {
console.log(`Could not find character ${charId} in the list`);
return;
}
try { try {
if (element !== undefined || element !== null) { const perPage = Number(localStorage.getItem('Characters_PerPage'));
const page = Math.floor(charIndex / perPage) + 1;
const selector = `#rm_print_characters_block [title^="${charId}"]`;
$('#rm_print_characters_pagination').pagination('go', page);
waitUntilCondition(() => document.querySelector(selector) !== null).then(() => {
const element = $(selector).parent().get(0);
if (!element) {
console.log(`Could not find element for character ${charId}`);
return;
}
element.scrollIntoView({ behavior: 'smooth', block: 'start' });
$(element).addClass('flash animated'); $(element).addClass('flash animated');
setTimeout(function () { setTimeout(function () {
$(element).removeClass('flash animated'); $(element).removeClass('flash animated');
}, 5000); }, 5000);
} else { console.log('didnt find the element'); } });
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }
@ -5741,7 +5762,7 @@ function select_rm_info(type, charId, previousCharId = null) {
console.error(e); console.error(e);
} }
} }
}, 100); }, 250);
if (previousCharId) { if (previousCharId) {
const newId = characters.findIndex((x) => x.avatar == previousCharId); const newId = characters.findIndex((x) => x.avatar == previousCharId);
@ -8682,9 +8703,9 @@ $(document).ready(function () {
} }
// Set the height of "autoSetHeight" textareas within the drawer to their scroll height // Set the height of "autoSetHeight" textareas within the drawer to their scroll height
$(this).closest('.drawer').find('.drawer-content textarea.autoSetHeight').each(function() { $(this).closest('.drawer').find('.drawer-content textarea.autoSetHeight').each(function () {
resetScrollHeight($(this)); resetScrollHeight($(this));
}); });
} else if (drawerWasOpenAlready) { //to close manually } else if (drawerWasOpenAlready) { //to close manually
icon.toggleClass('closedIcon openIcon'); icon.toggleClass('closedIcon openIcon');
@ -8753,7 +8774,7 @@ $(document).ready(function () {
$(this).closest('.inline-drawer').find('.inline-drawer-content').stop().slideToggle(); $(this).closest('.inline-drawer').find('.inline-drawer-content').stop().slideToggle();
// Set the height of "autoSetHeight" textareas within the inline-drawer to their scroll height // Set the height of "autoSetHeight" textareas within the inline-drawer to their scroll height
$(this).closest('.inline-drawer').find('.inline-drawer-content textarea.autoSetHeight').each(function() { $(this).closest('.inline-drawer').find('.inline-drawer-content textarea.autoSetHeight').each(function () {
resetScrollHeight($(this)); resetScrollHeight($(this));
}); });
}); });