Skip to content

Commit 0ea0373

Browse files
authored
Cron tab (#24)
1 parent 2ebabbd commit 0ea0373

File tree

9 files changed

+109
-4
lines changed

9 files changed

+109
-4
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
name: Test
22

3-
on: [push, pull_request]
3+
on: [push]
44

55
jobs:
66
release:
77
runs-on: ${{ matrix.os }}
88

99
strategy:
1010
matrix:
11-
os: [macos-latest, windows-latest, ubuntu-latest]
11+
os: [macos-latest]
1212

1313
steps:
1414
- name: Check out Git repository

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
## Tools list
1515

1616
- [x] Unix Timestamp Converter
17+
- [x] Cron Editor
1718
- [x] Markdown to HTML Converter
1819
- [x] HTML Preview
1920
- [x] QRCode Generator

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@
256256
"@tailwindcss/typography": "^0.4.1",
257257
"caniuse-lite": "^1.0.30001246",
258258
"classnames": "^2.3.1",
259+
"cronstrue": "^1.117.0",
259260
"dayjs": "^1.10.6",
260261
"diff": "^5.0.0",
261262
"electron-debug": "^3.1.0",

src/components/Main.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import QRCodeReader from './qrcode/QrCodeReader';
1616
import RegexTester from './regex/RegexTester';
1717
import JwtDebugger from './jwt/JwtDebugger';
1818
import Auto from './auto/Auto';
19+
import CronEditor from './cron/Cron';
1920

2021
const defaultRoutes = [
2122
{
@@ -30,6 +31,12 @@ const defaultRoutes = [
3031
name: 'Unix Time Converter',
3132
Component: UnixTimestamp,
3233
},
34+
{
35+
icon: <FontAwesomeIcon icon="retweet" />,
36+
path: '/cron-editor',
37+
name: 'Cron Editor',
38+
Component: CronEditor,
39+
},
3340
{
3441
icon: <FontAwesomeIcon icon="registered" />,
3542
path: '/regex-tester',

src/components/cron/Cron.tsx

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import React, { useEffect, useState } from 'react';
2+
import { clipboard } from 'electron';
3+
import cronstrue from 'cronstrue';
4+
import classNames from 'classnames';
5+
6+
const CronEditor = () => {
7+
const [input, setInput] = useState('* * * * *');
8+
const [output, setOutput] = useState(cronstrue.toString('* * * * *'));
9+
const [inputErr, setInputErr] = useState(false);
10+
11+
const handleChangeInput = (evt: { target: { value: string } }) =>
12+
setInput(evt.target.value);
13+
14+
const handleClipboardInput = () => {
15+
setInput(clipboard.readText());
16+
};
17+
18+
useEffect(() => {
19+
try {
20+
const mean = cronstrue.toString(input);
21+
setOutput(mean);
22+
setInputErr(false);
23+
} catch (e) {
24+
setOutput(e);
25+
setInputErr(true);
26+
}
27+
}, [input]);
28+
29+
return (
30+
<div className="flex flex-col h-full">
31+
<section className="flex flex-col flex-1 w-full h-full space-y-8">
32+
<section className="flex flex-col">
33+
<div className="flex justify-between mb-1">
34+
<button
35+
type="button"
36+
className="btn"
37+
onClick={handleClipboardInput}
38+
>
39+
Clipboard
40+
</button>
41+
</div>
42+
<div className="flex items-center space-x-2">
43+
<input
44+
onChange={handleChangeInput}
45+
className="flex-1 px-2 py-1 text-lg text-center bg-white rounded-md"
46+
value={input}
47+
/>
48+
</div>
49+
</section>
50+
<section
51+
className={classNames({
52+
'flex flex-col flex-shrink-0 text-center text-lg': true,
53+
'text-blue-500': !inputErr,
54+
'text-red-500': inputErr,
55+
})}
56+
>
57+
{!inputErr && '“'}
58+
{output}
59+
{!inputErr && '”'}
60+
</section>
61+
<section className="flex flex-col items-center justify-start flex-1 opacity-70">
62+
<table>
63+
<tbody>
64+
<tr className="flex space-x-4">
65+
<th>*</th>
66+
<td>any value</td>
67+
</tr>
68+
<tr className="flex space-x-4">
69+
<th>,</th>
70+
<td>value list separator</td>
71+
</tr>
72+
<tr className="flex space-x-4">
73+
<th>-</th>
74+
<td>range of values</td>
75+
</tr>
76+
<tr className="flex space-x-4">
77+
<th>/</th>
78+
<td>step values</td>
79+
</tr>
80+
</tbody>
81+
</table>
82+
</section>
83+
</section>
84+
</div>
85+
);
86+
};
87+
88+
export default CronEditor;

src/helpers/fontAwesome.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
faKey,
2020
faCheckCircle,
2121
faRobot,
22+
faRetweet,
2223
} from '@fortawesome/free-solid-svg-icons';
2324

2425
library.add(
@@ -38,5 +39,6 @@ library.add(
3839
faCamera,
3940
faKey,
4041
faCheckCircle,
41-
faRobot
42+
faRobot,
43+
faRetweet
4244
);

src/main.dev.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ const createWindow = async () => {
9494
icon: getAssetPath('icon.png'),
9595
webPreferences: {
9696
nodeIntegration: true,
97+
contextIsolation: false,
9798
},
9899
});
99100

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "plainbelt",
33
"productName": "PlainBelt",
4-
"version": "0.0.12",
4+
"version": "0.0.13",
55
"description": "A plain toolbelt for developers",
66
"main": "./main.prod.js",
77
"author": {

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3967,6 +3967,11 @@ create-hmac@^1.1.0, create-hmac@^1.1.4, create-hmac@^1.1.7:
39673967
safe-buffer "^5.0.1"
39683968
sha.js "^2.4.8"
39693969

3970+
cronstrue@^1.117.0:
3971+
version "1.117.0"
3972+
resolved "https://registry.yarnpkg.com/cronstrue/-/cronstrue-1.117.0.tgz#a7413ca510a85935380ae1ad8fef99d5b31ce8a4"
3973+
integrity sha512-XeRPOHNnkitGDqiLj3V6XJgn/UbrRSaWdVrDjV/IBt2cT+SRPeURiTt6Fbm16liCp78+XFklwuwWpPzPBg08NQ==
3974+
39703975
cross-env@^7.0.2:
39713976
version "7.0.2"
39723977
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.2.tgz#bd5ed31339a93a3418ac4f3ca9ca3403082ae5f9"

0 commit comments

Comments
 (0)