From cb6c098f95a393039166a37c5c5da29a6712a1d3 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Thu, 9 May 2024 18:17:15 +0100 Subject: [PATCH] refactor: Replace UIWindowProgressEmptyTrash with UIWindowProgress I noticed during this that emptying the trash from inside the Trash window uses a different code path without a progress dialog, so I've added a TODO to merge that in. I tried just using it directly but the behaviour is a bit different. (The Trash one makes all the items fade out.) --- src/UI/UIWindow.js | 1 + src/UI/UIWindowProgressEmptyTrash.js | 74 ---------------------------- src/helpers.js | 8 +-- 3 files changed, 5 insertions(+), 78 deletions(-) delete mode 100644 src/UI/UIWindowProgressEmptyTrash.js diff --git a/src/UI/UIWindow.js b/src/UI/UIWindow.js index dbcbbf38..06def551 100644 --- a/src/UI/UIWindow.js +++ b/src/UI/UIWindow.js @@ -2086,6 +2086,7 @@ async function UIWindow(options) { html: i18n('empty_trash'), disabled: false, onClick: async function(){ + // TODO: Merge this with window.empty_trash() const alert_resp = await UIAlert({ message: i18n('empty_trash_confirmation'), buttons:[ diff --git a/src/UI/UIWindowProgressEmptyTrash.js b/src/UI/UIWindowProgressEmptyTrash.js deleted file mode 100644 index 8f8a8aff..00000000 --- a/src/UI/UIWindowProgressEmptyTrash.js +++ /dev/null @@ -1,74 +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 UIWindowProgressEmptyTrash(options){ - let h = ''; - h += `
`; - h += `
`; - // spinner - h +=`circle anim`; - // message - h +=`
`; - // text - h += `${i18n('emptying_trash')}`; - h += `
`; - h +=`
`; - h += `
`; - - const el_window = await UIWindow({ - title: i18n('emptying_trash'), - icon: window.icons[`app-icon-newfolder.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-newfolder-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('.newfolder-cancel-btn').on('click', function(e){ - window.operation_cancelled[options.operation_id] = true; - $(el_window).close(); - }) - - return el_window; -} - -export default UIWindowProgressEmptyTrash \ No newline at end of file diff --git a/src/helpers.js b/src/helpers.js index e0980a7a..2b27b285 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -26,7 +26,6 @@ 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 UIWindowProgressEmptyTrash from './UI/UIWindowProgressEmptyTrash.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'; @@ -2790,7 +2789,8 @@ window.empty_trash = async function(){ let progwin; let op_id = window.uuidv4(); let progwin_timeout = setTimeout(async () => { - progwin = await UIWindowProgressEmptyTrash({operation_id: op_id}); + progwin = await UIWindowProgress({operation_id: op_id}); + progwin.set_status(i18n('emptying_trash')); }, 500); await puter.fs.delete({ @@ -2814,13 +2814,13 @@ window.empty_trash = async function(){ // close progress window clearTimeout(progwin_timeout); setTimeout(() => { - $(progwin).close(); + progwin?.close(); }, Math.max(0, window.copy_progress_hide_delay - (Date.now() - init_ts))); }, error: async function (err){ clearTimeout(progwin_timeout); setTimeout(() => { - $(progwin).close(); + progwin?.close(); }, Math.max(0, window.copy_progress_hide_delay - (Date.now() - init_ts))); } });