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) {
7299 // Set a timeout so multiple flashes don't overlap7299 // Set a timeout so multiple flashes don't overlap
7300 clearTimeout(importFlashTimeout);7300 clearTimeout(importFlashTimeout);
7301 importFlashTimeout = setTimeout(function () {7301 importFlashTimeout = setTimeout(function () {
7302 if (type === 'char_import' || type === 'char_create') {7302 if (type === 'char_import' || type === 'char_create' || type === 'char_import_no_toast') {
7303 // Find the page at which the character is located7303 // Find the page at which the character is located
7304 const avatarFileName = charId;7304 const avatarFileName = charId;
7305 const charData = getEntitiesList({ doFilter: true });7305 const charData = getEntitiesList({ doFilter: true });
@@ -8865,7 +8865,10 @@ export async function processDroppedFiles(files, data = new Map()) {
8865 }8865 }
8866 }8866 }
88678867
8868 await importCharactersTags(avatarFileNames);8868 if (avatarFileNames.length > 0){
8869 await importCharactersTags(avatarFileNames);
8870 selectImportedChar(avatarFileNames[avatarFileNames.length - 1]);
8871 }
8869}8872}
88708873
8871/**8874/**
@@ -8883,6 +8886,18 @@ async function importCharactersTags(avatarFileNames) {
8883}8886}
88848887
8885/**8888/**
8889 * Selects the given imported char
8890 * @param {string} charId char to select
8891 */
8892function 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/**
8886 * Imports a character from a file.8901 * Imports a character from a file.
8887 * @param {File} file File to import8902 * @param {File} file File to import
8888 * @param {object} [options] - Options8903 * @param {object} [options] - Options
@@ -8926,15 +8941,12 @@ async function importCharacter(file, {preserveFileName = '', importTags = false}
8926 if (data.file_name !== undefined) {8941 if (data.file_name !== undefined) {
8927 $('#character_search_bar').val('').trigger('input');8942 $('#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);
8935 let avatarFileName = `${data.file_name}.png`;8945 let avatarFileName = `${data.file_name}.png`;
8936 if (importTags) {8946 if (importTags) {
8937 await importCharactersTags([avatarFileName])8947 await importCharactersTags([avatarFileName]);
8948
8949 selectImportedChar(data.file_name);
8938 }8950 }
8939 return avatarFileName;8951 return avatarFileName;
8940 }8952 }
@@ -10822,7 +10834,11 @@ jQuery(async function () {
10822 avatarFileNames.push(avatarFileName);10834 avatarFileNames.push(avatarFileName);
10823 }10835 }
10824 }10836 }
10825 await importCharactersTags(avatarFileNames);10837
10838 if (avatarFileNames.length > 0){
10839 await importCharactersTags(avatarFileNames);
10840 selectImportedChar(avatarFileNames[avatarFileNames.length - 1]);
10841 }
10826 });10842 });
1082710843
10828 $('#export_button').on('click', function () {10844 $('#export_button').on('click', function () {