Skip to content

Commit

Permalink
feat: add keyboard shortcut for saving experiments and update save bu…
Browse files Browse the repository at this point in the history
…tton icon to show loading state
  • Loading branch information
drikusroor committed Jan 8, 2025
1 parent 8564426 commit ad422e8
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createExperimentEntityUrl } from '../config';
import { useNavigate, useParams, Routes, Route, useLocation } from 'react-router-dom';
import Page from './Page';
import { TranslatedContentForms } from './TranslatedContentForms';
import { FiSave, FiArrowLeft, FiGlobe, FiLayers } from 'react-icons/fi';
import { FiSave, FiArrowLeft, FiGlobe, FiLayers, FiLoader } from 'react-icons/fi';
import { Button } from './Button';
import { Tabs } from './Tabs';
import { FormField } from './form/FormField';
Expand Down Expand Up @@ -73,6 +73,20 @@ const ExperimentForm: React.FC<ExperimentFormProps> = () => {
}
}, [location]);

useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
if ((event.ctrlKey || event.metaKey) && event.key === 's') {
event.preventDefault();
handleSubmit(event as unknown as React.FormEvent);
}
};

document.addEventListener('keydown', handleKeyDown);
return () => {
document.removeEventListener('keydown', handleKeyDown);
};
}, [experiment]);

const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const { name, type, checked, value } = e.target;
patchExperiment({
Expand Down Expand Up @@ -236,7 +250,7 @@ const ExperimentForm: React.FC<ExperimentFormProps> = () => {
type="submit"
disabled={saveLoading}
variant="success"
icon={<FiSave />}
icon={!saveLoading ? <FiSave /> : <div className="animate-spin"><FiLoader /></div>}
className="mt-5"
>
{saveLoading ? 'Saving...' : (experimentId ? 'Update Experiment' : 'Create Experiment')}
Expand Down

0 comments on commit ad422e8

Please sign in to comment.