fix toasts and final char selection

d4f23de003997002d33f99bec8a824177f4a0b73

d-ber <davide.bertalero@studenti.unimi.it>

1 files changed, +26 -10Ignore whitespace
public/script.js+26 -10
@@ -7299,7 +7299,7 @@ export function select_rm_info(type, charId, previousCharId = null) {
72997299 // Set a timeout so multiple flashes don't overlap
73007300 clearTimeout(importFlashTimeout);
73017301 importFlashTimeout = setTimeout(function () {
73027302 if (type === 'char_import' || type === 'char_create' || type === 'char_import_no_toast') {
73037303 // Find the page at which the character is located
73047304 const avatarFileName = charId;
73057305 const charData = getEntitiesList({ doFilter: true });
@@ -8865,7 +8865,10 @@ export async function processDroppedFiles(files, data = new Map()) {
88658865 }
88668866 }
88678867
8868- await importCharactersTags(avatarFileNames);
8868+ if (avatarFileNames.length > 0){
8869+ await importCharactersTags(avatarFileNames);
8870+ selectImportedChar(avatarFileNames[avatarFileNames.length - 1]);
8871+ }
88698872}
88708873
88718874/**
@@ -8883,6 +8886,18 @@ async function importCharactersTags(avatarFileNames) {
88838886}
88848887
88858888/**
8889+ * Selects the given imported char
8890+ * @param {string} charId char to select
8891+ */
8892+function selectImportedChar(charId) {
8893+ let oldSelectedChar = null;
8894+ if (this_chid !== undefined) {
8895+ oldSelectedChar = characters[this_chid].avatar;
8896+ }
8897+ select_rm_info('char_import_no_toast', charId, oldSelectedChar);
8898+}
8899+
8900+/**
88868901 * Imports a character from a file.
88878902 * @param {File} file File to import
88888903 * @param {object} [options] - Options
@@ -8926,15 +8941,12 @@ async function importCharacter(file, {preserveFileName = '', importTags = false}
89268941 if (data.file_name !== undefined) {
89278942 $('#character_search_bar').val('').trigger('input');
89288943
8929- let oldSelectedChar = null;
8944+ toastr.success(t`Character Created: ${String(data.file_name).replace('.png', '')}`);
8930- if (this_chid !== undefined) {
8931- oldSelectedChar = characters[this_chid].avatar;
8932- }
8933-
8934- select_rm_info('char_import', data.file_name, oldSelectedChar);
89358945 let avatarFileName = `${data.file_name}.png`;
89368946 if (importTags) {
89378947 await importCharactersTags([avatarFileName]);
8948+
8949+ selectImportedChar(data.file_name);
89388950 }
89398951 return avatarFileName;
89408952 }
@@ -10822,7 +10834,11 @@ jQuery(async function () {
1082210834 avatarFileNames.push(avatarFileName);
1082310835 }
1082410836 }
10825- await importCharactersTags(avatarFileNames);
10837+
10838+ if (avatarFileNames.length > 0){
10839+ await importCharactersTags(avatarFileNames);
10840+ selectImportedChar(avatarFileNames[avatarFileNames.length - 1]);
10841+ }
1082610842 });
1082710843
1082810844 $('#export_button').on('click', function () {