mirror of
https://github.com/phishingclub/phishingclub.git
synced 2026-06-13 01:37:52 +02:00
ctrl+s update keep position
Signed-off-by: Ronni Skansing <rskansing@gmail.com>
This commit is contained in:
@@ -15,10 +15,13 @@
|
||||
|
||||
function handleKeydown(event) {
|
||||
if (event.ctrlKey && event.key === 's') {
|
||||
// Only trigger if the form or its descendants have focus and we're in update mode
|
||||
// only trigger if the form or its descendants have focus and we're in update mode
|
||||
if (modalMode === 'update' && formElement && formElement.contains(document.activeElement)) {
|
||||
event.preventDefault();
|
||||
dispatch('submit', { ...event, saveOnly: true });
|
||||
event.stopPropagation();
|
||||
event.stopImmediatePropagation();
|
||||
// dispatch to our event handler, not native form submit
|
||||
dispatch('submit', { saveOnly: true });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,7 +37,6 @@
|
||||
|
||||
<form
|
||||
on:submit|preventDefault
|
||||
inert={isSubmitting}
|
||||
class="grid grid-cols-3 grid-rows-1 w-full h-full flex-col bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 transition-colors duration-200"
|
||||
class:opacity-70={isSubmitting}
|
||||
bind:this={formElement}
|
||||
|
||||
@@ -18,26 +18,35 @@
|
||||
let lastFocusableElement;
|
||||
|
||||
let modalInitialized = false;
|
||||
let wasVisible = false;
|
||||
|
||||
$: {
|
||||
// only handle focus when modal visibility actually changes and not during submission
|
||||
if (visible && !modalInitialized) {
|
||||
window.addEventListener('keydown', keyHandler);
|
||||
// Prevent body scrolling when modal is open
|
||||
document.body.style.overflow = 'hidden';
|
||||
handleModalOpen();
|
||||
if (!isSubmitting) {
|
||||
handleModalOpen();
|
||||
}
|
||||
modalInitialized = true;
|
||||
wasVisible = true;
|
||||
} else if (!visible && modalInitialized) {
|
||||
window.removeEventListener('keydown', keyHandler);
|
||||
// Restore body scrolling when modal is closed
|
||||
document.body.style.overflow = 'auto';
|
||||
handleModalClose();
|
||||
modalInitialized = false;
|
||||
wasVisible = false;
|
||||
}
|
||||
}
|
||||
|
||||
const keyHandler = (e) => {
|
||||
if (e.key === 'Escape') {
|
||||
close();
|
||||
// don't close modal during submission
|
||||
if (!isSubmitting) {
|
||||
close();
|
||||
}
|
||||
} else if (e.key === 'Tab') {
|
||||
// Check if the focused element is a dropdown option button
|
||||
const focusedElement = document.activeElement;
|
||||
@@ -227,6 +236,11 @@
|
||||
};
|
||||
|
||||
const handleModalOpen = async () => {
|
||||
// don't manage focus during form submission
|
||||
if (isSubmitting) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Store the currently focused element
|
||||
previousActiveElement = document.activeElement;
|
||||
|
||||
@@ -285,6 +299,10 @@
|
||||
});
|
||||
|
||||
const close = () => {
|
||||
// prevent closing during submission
|
||||
if (isSubmitting) {
|
||||
return;
|
||||
}
|
||||
visible = false;
|
||||
window.removeEventListener('keydown', keyHandler);
|
||||
// Restore body scrolling when modal is closed
|
||||
|
||||
@@ -194,8 +194,9 @@
|
||||
addToast(saveOnly ? 'API sender saved' : 'Updated API sender', 'Success');
|
||||
if (!saveOnly) {
|
||||
closeEditModal();
|
||||
// only refresh the table when actually closing the modal
|
||||
refreshConfigurations();
|
||||
}
|
||||
refreshConfigurations();
|
||||
} catch (err) {
|
||||
addToast('Failed to update API sender', 'Error');
|
||||
console.error('failed to update API sender:', err);
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
let contextCompanyID = null;
|
||||
let form = null;
|
||||
let sendTestForm = null;
|
||||
|
||||
let formValues = {
|
||||
id: null,
|
||||
name: null,
|
||||
@@ -141,8 +142,8 @@
|
||||
|
||||
const onSubmit = async (event) => {
|
||||
try {
|
||||
isSubmitting = true;
|
||||
const saveOnly = event?.detail?.saveOnly || false;
|
||||
isSubmitting = true;
|
||||
if (modalMode === 'create' || modalMode === 'copy') {
|
||||
await onClickCreate();
|
||||
return;
|
||||
@@ -198,8 +199,9 @@
|
||||
addToast(saveOnly ? 'Email saved' : 'Email updated', 'Success');
|
||||
if (!saveOnly) {
|
||||
closeModal();
|
||||
// only refresh the table when actually closing the modal
|
||||
refreshEmails();
|
||||
}
|
||||
refreshEmails();
|
||||
} catch (e) {
|
||||
addToast(saveOnly ? 'Failed to save email' : 'Failed to update email', 'Error');
|
||||
console.error('failed to update email', e);
|
||||
|
||||
@@ -189,8 +189,9 @@
|
||||
addToast(saveOnly ? 'Page saved' : 'Page updated', 'Success');
|
||||
if (!saveOnly) {
|
||||
closeModal();
|
||||
// only refresh the table when actually closing the modal
|
||||
refreshPages();
|
||||
}
|
||||
refreshPages();
|
||||
} catch (e) {
|
||||
addToast(saveOnly ? 'Failed to save page' : 'Failed to update page', 'Error');
|
||||
console.error('failed to update page', e);
|
||||
|
||||
@@ -277,8 +277,9 @@ portal.example.com:
|
||||
addToast(saveOnly ? 'Proxy saved' : 'Proxy updated', 'Success');
|
||||
if (!saveOnly) {
|
||||
closeModal();
|
||||
// only refresh the table when actually closing the modal
|
||||
refreshProxies();
|
||||
}
|
||||
refreshProxies();
|
||||
} catch (e) {
|
||||
addToast(saveOnly ? 'Failed to save Proxy' : 'Failed to update Proxy', 'Error');
|
||||
console.error('failed to update Proxy', e);
|
||||
|
||||
Reference in New Issue
Block a user