mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-19 22:24:11 +00:00
refract: cleanup
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
// TODO: should be defined dynamically?
|
||||||
|
export const serverURL = 'http://localhost:4001/';
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { addMinutes, format, parseISO } from "date-fns";
|
||||||
|
|
||||||
export const timeFormat = 'HH:mm';
|
export const timeFormat = 'HH:mm';
|
||||||
export const timeFormatSeconds = 'HH:mm:ss';
|
export const timeFormatSeconds = 'HH:mm:ss';
|
||||||
|
|
||||||
@@ -6,3 +8,10 @@ export const timeToDate = (time) => {
|
|||||||
const today = new Date();
|
const today = new Date();
|
||||||
return new Date(today.toDateString() + ' ' + time);
|
return new Date(today.toDateString() + ' ' + time);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// small shorthand for adding delay and formatting date
|
||||||
|
export const addAndFormat = (time, delay) => {
|
||||||
|
const fTime = parseISO(time, 1);
|
||||||
|
return format(addMinutes(fTime, delay), timeFormat);
|
||||||
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { AddIcon, MinusIcon } from '@chakra-ui/icons';
|
|||||||
import style from './List.module.css';
|
import style from './List.module.css';
|
||||||
|
|
||||||
export default function BlockBlock(props) {
|
export default function BlockBlock(props) {
|
||||||
|
const { eventsHandler, index, data } = props;
|
||||||
return (
|
return (
|
||||||
<div className={style.blockContainer}>
|
<div className={style.blockContainer}>
|
||||||
<div className={style.actionOverlay}>
|
<div className={style.actionOverlay}>
|
||||||
@@ -10,13 +11,15 @@ export default function BlockBlock(props) {
|
|||||||
size='xs'
|
size='xs'
|
||||||
icon={<MinusIcon />}
|
icon={<MinusIcon />}
|
||||||
colorScheme='red'
|
colorScheme='red'
|
||||||
onClick={() => props.deleteEvent(props.index)}
|
onClick={() => eventsHandler('delete', data.id)}
|
||||||
/>
|
/>
|
||||||
<IconButton
|
<IconButton
|
||||||
size='xs'
|
size='xs'
|
||||||
icon={<AddIcon />}
|
icon={<AddIcon />}
|
||||||
colorScheme='blue'
|
colorScheme='blue'
|
||||||
onClick={() => props.createEvent(props.index)}
|
onClick={() =>
|
||||||
|
eventsHandler('add', { type: 'event', order: index + 1 })
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import style from './List.module.css';
|
|||||||
|
|
||||||
export default function DelayBlock(props) {
|
export default function DelayBlock(props) {
|
||||||
const [delay, setDelay] = useState(0);
|
const [delay, setDelay] = useState(0);
|
||||||
const { data, ...rest } = props;
|
const { data, eventsHandler, index, updateData } = props;
|
||||||
|
|
||||||
// update delay value in parent
|
// update delay value in parent
|
||||||
const populateDelay = (value) => {
|
const populateDelay = (value) => {
|
||||||
@@ -22,7 +22,7 @@ export default function DelayBlock(props) {
|
|||||||
const newData = { ...data, timerDuration: delay };
|
const newData = { ...data, timerDuration: delay };
|
||||||
|
|
||||||
// request update in parent
|
// request update in parent
|
||||||
props.updateData(props.index, newData);
|
updateData(index, newData);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -53,13 +53,15 @@ export default function DelayBlock(props) {
|
|||||||
size='xs'
|
size='xs'
|
||||||
icon={<MinusIcon />}
|
icon={<MinusIcon />}
|
||||||
colorScheme='red'
|
colorScheme='red'
|
||||||
onClick={() => props.deleteEvent(props.index)}
|
onClick={() => eventsHandler('delete', data.id)}
|
||||||
/>
|
/>
|
||||||
<IconButton
|
<IconButton
|
||||||
size='xs'
|
size='xs'
|
||||||
icon={<AddIcon />}
|
icon={<AddIcon />}
|
||||||
colorScheme='blue'
|
colorScheme='blue'
|
||||||
onClick={() => props.createEvent(props.index)}
|
onClick={() =>
|
||||||
|
eventsHandler('add', { type: 'event', order: index + 1 })
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -12,33 +12,23 @@ import {
|
|||||||
EditablePreview,
|
EditablePreview,
|
||||||
EditableInput,
|
EditableInput,
|
||||||
} from '@chakra-ui/react';
|
} from '@chakra-ui/react';
|
||||||
import { addMinutes, format } from 'date-fns';
|
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { timeFormat, timeToDate } from '../../../common/dateConfig';
|
import { addAndFormat, timeToDate } from '../../../common/dateConfig';
|
||||||
|
import { showErrorToast } from '../../../common/helpers/toastManager';
|
||||||
import style from './List.module.css';
|
import style from './List.module.css';
|
||||||
|
|
||||||
// small shorthand for adding delay and formatting date
|
|
||||||
const addAndFormat = (time, delay) => {
|
|
||||||
return format(addMinutes(time, delay), timeFormat);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default function EventListItem(props) {
|
export default function EventListItem(props) {
|
||||||
const [more, setMore] = useState(false);
|
const { data, selected, delay, index, eventsHandler, updateData } = props;
|
||||||
// const [timeStart, setTimeStart] = useState(
|
|
||||||
// addAndFormat(props.data.timeStart, props.delay)
|
|
||||||
// );
|
|
||||||
const [timeStart, setTimeStart] = useState(0);
|
|
||||||
const [timeEnd, setTimeEnd] = useState(
|
|
||||||
addAndFormat(props.data.timeEnd, props.delay)
|
|
||||||
);
|
|
||||||
|
|
||||||
const { data, selected, delay, ...rest } = props;
|
const [more, setMore] = useState(false);
|
||||||
|
const [timeStart, setTimeStart] = useState(0);
|
||||||
|
const [timeEnd, setTimeEnd] = useState(addAndFormat(data.timeEnd, delay));
|
||||||
|
|
||||||
// prepare time fields
|
// prepare time fields
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTimeStart(addAndFormat(props.data.timeStart, props.delay));
|
setTimeStart(addAndFormat(data.timeStart, delay));
|
||||||
setTimeEnd(addAndFormat(props.data.timeEnd, props.delay));
|
setTimeEnd(addAndFormat(data.timeEnd, delay));
|
||||||
}, [props.data, props.delay]);
|
}, [data, delay]);
|
||||||
|
|
||||||
const updateValues = (field, value) => {
|
const updateValues = (field, value) => {
|
||||||
// validate field
|
// validate field
|
||||||
@@ -47,9 +37,9 @@ export default function EventListItem(props) {
|
|||||||
const newData = { ...data, [field]: value };
|
const newData = { ...data, [field]: value };
|
||||||
|
|
||||||
// request update in parent
|
// request update in parent
|
||||||
props.updateData(props.index, newData);
|
updateData(index, newData);
|
||||||
} else {
|
} else {
|
||||||
console.log('field error', field);
|
showErrorToast('Field Error: ' + field);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -148,25 +138,31 @@ export default function EventListItem(props) {
|
|||||||
size='xs'
|
size='xs'
|
||||||
icon={<MinusIcon />}
|
icon={<MinusIcon />}
|
||||||
colorScheme='red'
|
colorScheme='red'
|
||||||
onClick={() => props.deleteEvent(props.index)}
|
onClick={() => eventsHandler('delete', data.id)}
|
||||||
/>
|
/>
|
||||||
<IconButton
|
<IconButton
|
||||||
size='xs'
|
size='xs'
|
||||||
icon={<AddIcon />}
|
icon={<AddIcon />}
|
||||||
colorScheme='blue'
|
colorScheme='blue'
|
||||||
onClick={() => props.createEvent(props.index)}
|
onClick={() =>
|
||||||
|
eventsHandler('add', { type: 'event', order: index + 1 })
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
<IconButton
|
<IconButton
|
||||||
size='xs'
|
size='xs'
|
||||||
icon={<TimeIcon />}
|
icon={<TimeIcon />}
|
||||||
colorScheme='yellow'
|
colorScheme='yellow'
|
||||||
onClick={() => props.createDelay(props.index)}
|
onClick={() =>
|
||||||
|
eventsHandler('add', { type: 'delay', order: index + 1 })
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
<IconButton
|
<IconButton
|
||||||
size='xs'
|
size='xs'
|
||||||
icon={<NotAllowedIcon />}
|
icon={<NotAllowedIcon />}
|
||||||
colorScheme='purple'
|
colorScheme='purple'
|
||||||
onClick={() => props.createBlock(props.index)}
|
onClick={() =>
|
||||||
|
eventsHandler('add', { type: 'block', order: index + 1 })
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -11,10 +11,12 @@ import {
|
|||||||
import style from './EventListMenu.module.css';
|
import style from './EventListMenu.module.css';
|
||||||
|
|
||||||
export default function EventListMenu(props) {
|
export default function EventListMenu(props) {
|
||||||
|
const { eventsHandler } = props;
|
||||||
const buttonProps = {
|
const buttonProps = {
|
||||||
size: 'sm',
|
size: 'sm',
|
||||||
variant: 'outline',
|
variant: 'outline',
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={style.headerButtons}>
|
<div className={style.headerButtons}>
|
||||||
<Menu>
|
<Menu>
|
||||||
@@ -47,7 +49,7 @@ export default function EventListMenu(props) {
|
|||||||
size='sm'
|
size='sm'
|
||||||
icon={<AddIcon />}
|
icon={<AddIcon />}
|
||||||
colorScheme='blue'
|
colorScheme='blue'
|
||||||
onClick={() => props.createEvent()}
|
onClick={() => eventsHandler('add', { type: 'event', order: 0 })}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
+1
-7
@@ -57,10 +57,7 @@ class Timer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#getExpectedFinish() {
|
#getExpectedFinish() {
|
||||||
return (
|
return this.#finishAt + (this.#pausedInterval + this.#pausedTotal);
|
||||||
this.#finishAt +
|
|
||||||
(this.#pausedInterval + this.#pausedTotal)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// getObject
|
// getObject
|
||||||
@@ -98,7 +95,6 @@ class Timer {
|
|||||||
|
|
||||||
// change state
|
// change state
|
||||||
this.state = 'start';
|
this.state = 'start';
|
||||||
console.log('started');
|
|
||||||
}
|
}
|
||||||
pause() {
|
pause() {
|
||||||
// do we need to change
|
// do we need to change
|
||||||
@@ -109,8 +105,6 @@ class Timer {
|
|||||||
|
|
||||||
// change state
|
// change state
|
||||||
this.state = 'pause';
|
this.state = 'pause';
|
||||||
|
|
||||||
console.log('paused');
|
|
||||||
}
|
}
|
||||||
stop() {
|
stop() {
|
||||||
console.log('stop: not yet implemented');
|
console.log('stop: not yet implemented');
|
||||||
|
|||||||
Reference in New Issue
Block a user