-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
109 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { clipboard } from 'electron'; | ||
import cronstrue from 'cronstrue'; | ||
import classNames from 'classnames'; | ||
|
||
const CronEditor = () => { | ||
const [input, setInput] = useState('* * * * *'); | ||
const [output, setOutput] = useState(cronstrue.toString('* * * * *')); | ||
const [inputErr, setInputErr] = useState(false); | ||
|
||
const handleChangeInput = (evt: { target: { value: string } }) => | ||
setInput(evt.target.value); | ||
|
||
const handleClipboardInput = () => { | ||
setInput(clipboard.readText()); | ||
}; | ||
|
||
useEffect(() => { | ||
try { | ||
const mean = cronstrue.toString(input); | ||
setOutput(mean); | ||
setInputErr(false); | ||
} catch (e) { | ||
setOutput(e); | ||
setInputErr(true); | ||
} | ||
}, [input]); | ||
|
||
return ( | ||
<div className="flex flex-col h-full"> | ||
<section className="flex flex-col flex-1 w-full h-full space-y-8"> | ||
<section className="flex flex-col"> | ||
<div className="flex justify-between mb-1"> | ||
<button | ||
type="button" | ||
className="btn" | ||
onClick={handleClipboardInput} | ||
> | ||
Clipboard | ||
</button> | ||
</div> | ||
<div className="flex items-center space-x-2"> | ||
<input | ||
onChange={handleChangeInput} | ||
className="flex-1 px-2 py-1 text-lg text-center bg-white rounded-md" | ||
value={input} | ||
/> | ||
</div> | ||
</section> | ||
<section | ||
className={classNames({ | ||
'flex flex-col flex-shrink-0 text-center text-lg': true, | ||
'text-blue-500': !inputErr, | ||
'text-red-500': inputErr, | ||
})} | ||
> | ||
{!inputErr && '“'} | ||
{output} | ||
{!inputErr && '”'} | ||
</section> | ||
<section className="flex flex-col items-center justify-start flex-1 opacity-70"> | ||
<table> | ||
<tbody> | ||
<tr className="flex space-x-4"> | ||
<th>*</th> | ||
<td>any value</td> | ||
</tr> | ||
<tr className="flex space-x-4"> | ||
<th>,</th> | ||
<td>value list separator</td> | ||
</tr> | ||
<tr className="flex space-x-4"> | ||
<th>-</th> | ||
<td>range of values</td> | ||
</tr> | ||
<tr className="flex space-x-4"> | ||
<th>/</th> | ||
<td>step values</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</section> | ||
</section> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CronEditor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters