mirror of
https://github.com/plankanban/planka.git
synced 2025-07-19 05:09:43 +02:00
feat: Add multiple task creation with Ctrl+Enter (#921)
This commit is contained in:
parent
588f513a91
commit
aad6eda3e9
1 changed files with 28 additions and 15 deletions
|
@ -13,6 +13,8 @@ const DEFAULT_DATA = {
|
|||
name: '',
|
||||
};
|
||||
|
||||
const MULTIPLE_REGEX = /\s*\r?\n\s*/;
|
||||
|
||||
const Add = React.forwardRef(({ children, onCreate }, ref) => {
|
||||
const [t] = useTranslation();
|
||||
const [isOpened, setIsOpened] = useState(false);
|
||||
|
@ -29,7 +31,8 @@ const Add = React.forwardRef(({ children, onCreate }, ref) => {
|
|||
setIsOpened(false);
|
||||
}, []);
|
||||
|
||||
const submit = useCallback(() => {
|
||||
const submit = useCallback(
|
||||
(isMultiple = false) => {
|
||||
const cleanData = {
|
||||
...data,
|
||||
name: data.name.trim(),
|
||||
|
@ -40,11 +43,22 @@ const Add = React.forwardRef(({ children, onCreate }, ref) => {
|
|||
return;
|
||||
}
|
||||
|
||||
if (isMultiple) {
|
||||
cleanData.name.split(MULTIPLE_REGEX).forEach((name) => {
|
||||
onCreate({
|
||||
...cleanData,
|
||||
name,
|
||||
});
|
||||
});
|
||||
} else {
|
||||
onCreate(cleanData);
|
||||
}
|
||||
|
||||
setData(DEFAULT_DATA);
|
||||
focusNameField();
|
||||
}, [onCreate, data, setData, focusNameField]);
|
||||
},
|
||||
[onCreate, data, setData, focusNameField],
|
||||
);
|
||||
|
||||
useImperativeHandle(
|
||||
ref,
|
||||
|
@ -63,8 +77,7 @@ const Add = React.forwardRef(({ children, onCreate }, ref) => {
|
|||
(event) => {
|
||||
if (event.key === 'Enter') {
|
||||
event.preventDefault();
|
||||
|
||||
submit();
|
||||
submit(event.ctrlKey);
|
||||
}
|
||||
},
|
||||
[submit],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue