From c12312cbd37343d6ba33784327d0d6661576763f Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Thu, 9 May 2024 18:18:27 +0100 Subject: [PATCH] refactor: Replace UIWindowMoveProgress with UIWindowProgress --- src/UI/UIWindowMoveProgress.js | 81 ---------------------------------- src/helpers.js | 14 +++--- 2 files changed, 9 insertions(+), 86 deletions(-) delete mode 100644 src/UI/UIWindowMoveProgress.js diff --git a/src/UI/UIWindowMoveProgress.js b/src/UI/UIWindowMoveProgress.js deleted file mode 100644 index 5ec74062..00000000 --- a/src/UI/UIWindowMoveProgress.js +++ /dev/null @@ -1,81 +0,0 @@ -/** - * Copyright (C) 2024 Puter Technologies Inc. - * - * This file is part of Puter. - * - * Puter is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import UIWindow from './UIWindow.js' - -// todo do this using uid rather than item_path, since item_path is way mroe expensive on the DB -async function UIWindowMoveProgress(options){ - let h = ''; - h += `
`; - h += `
`; - // spinner - h +=`circle anim`; - // Progress report - h +=`
`; - // msg - h += `${i18n('moving')} `; - h += ``; - h += `
`; - // progress - h += `
`; - h += `
`; - h += `
`; - // cancel - // h += ``; - h +=`
`; - h += `
`; - - const el_window = await UIWindow({ - title: `moveing`, - icon: window.icons[`app-icon-moveing.svg`], - uid: null, - is_dir: false, - body_content: h, - has_head: false, - selectable_body: false, - draggable_body: true, - allow_context_menu: false, - is_resizable: false, - is_droppable: false, - init_center: true, - allow_native_ctxmenu: false, - allow_user_select: false, - window_class: 'window-move-progress', - width: 450, - dominant: true, - window_css:{ - height: 'initial', - }, - body_css: { - padding: '22px', - width: 'initial', - 'background-color': 'rgba(231, 238, 245, .95)', - 'backdrop-filter': 'blur(3px)', - } - }); - - $(el_window).find('.move-cancel-btn').on('click', function(e){ - window.operation_cancelled[options.operation_id] = true; - $(el_window).close(); - }) - - return el_window; -} - -export default UIWindowMoveProgress \ No newline at end of file diff --git a/src/helpers.js b/src/helpers.js index 2b27b285..ce2ffc48 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -25,7 +25,6 @@ import UIWindow from './UI/UIWindow.js' import UIWindowLogin from './UI/UIWindowLogin.js'; import UIWindowSaveAccount from './UI/UIWindowSaveAccount.js'; import UIWindowCopyProgress from './UI/UIWindowCopyProgress.js'; -import UIWindowMoveProgress from './UI/UIWindowMoveProgress.js'; import update_username_in_gui from './helpers/update_username_in_gui.js'; import update_title_based_on_uploads from './helpers/update_title_based_on_uploads.js'; import content_type_to_icon from './helpers/content_type_to_icon.js'; @@ -2132,7 +2131,12 @@ window.move_items = async function(el_items, dest_path, is_undo = false){ // only show progress window if it takes longer than 2s to move let progwin; let progwin_timeout = setTimeout(async () => { - progwin = await UIWindowMoveProgress({operation_id: move_op_id}); + progwin = await UIWindowProgress({ + operation_id: move_op_id, + on_cancel: () => { + window.operation_cancelled[move_op_id] = true; + }, + }); }, 2000); // storing moved items for undo ability @@ -2218,7 +2222,7 @@ window.move_items = async function(el_items, dest_path, is_undo = false){ // moving an item into a trashed directory? deny. else if(dest_path.startsWith(window.trash_path)){ - $(progwin).close(); + progwin?.close(); UIAlert('Cannot move items into a deleted folder.'); return; } @@ -2237,7 +2241,7 @@ window.move_items = async function(el_items, dest_path, is_undo = false){ // -------------------------------------------------------- // update progress window with current item being moved // -------------------------------------------------------- - $(progwin).find('.move-from').html(html_encode(path_to_show_on_progwin)); + progwin?.set_status(i18n('moving') + ' ' + html_encode(path_to_show_on_progwin)); // execute move let resp = await puter.fs.move({ @@ -2444,7 +2448,7 @@ window.move_items = async function(el_items, dest_path, is_undo = false){ if(progwin){ setTimeout(() => { - $(progwin).close(); + progwin.close(); }, window.copy_progress_hide_delay); } }