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 importFlashTimeout;
export let isChatSaving = false;
let chat_create_date = 0;
let firstRun = false;
@ -5708,19 +5709,39 @@ function select_rm_info(type, charId, previousCharId = null) {
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') {
const element = $(`#rm_characters_block [title="${charId}"]`).parent().get(0);
console.log(element);
element.scrollIntoView({ behavior: 'smooth', block: 'start' });
// Find the page at which the character is located
const charData = getEntitiesList({ doFilter: true });
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 {
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');
setTimeout(function () {
$(element).removeClass('flash animated');
}, 5000);
} else { console.log('didnt find the element'); }
});
} catch (e) {
console.error(e);
}
@ -5741,7 +5762,7 @@ function select_rm_info(type, charId, previousCharId = null) {
console.error(e);
}
}
}, 100);
}, 250);
if (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
$(this).closest('.drawer').find('.drawer-content textarea.autoSetHeight').each(function() {
$(this).closest('.drawer').find('.drawer-content textarea.autoSetHeight').each(function () {
resetScrollHeight($(this));
});
});
} else if (drawerWasOpenAlready) { //to close manually
icon.toggleClass('closedIcon openIcon');
@ -8753,7 +8774,7 @@ $(document).ready(function () {
$(this).closest('.inline-drawer').find('.inline-drawer-content').stop().slideToggle();
// 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));
});
});