Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/161 #186

Merged
merged 33 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e911847
feat(time): add optional time format
cpvalente Jul 28, 2022
a8df8ba
feat(time): show 12 hour time in stage timer
cpvalente Jul 29, 2022
ef0dba8
feat(time): override locally
cpvalente Jul 29, 2022
a2662e2
feat(time): show timer in selected format
cpvalente Jul 29, 2022
7f641d7
feat(time): show timer in selected format
cpvalente Jul 29, 2022
406649a
feat(time): show timer in selected format
cpvalente Jul 29, 2022
d6dfb50
feat(time): show timer in selected format
cpvalente Jul 29, 2022
080cc66
feat(time): show timer in selected format
cpvalente Jul 30, 2022
198240b
feat(time): show timer in selected format
cpvalente Jul 30, 2022
0701363
test(time): update tests
cpvalente Jul 30, 2022
8a65dac
fix: prevent checking undefined
cpvalente Jul 30, 2022
fc863da
feat(time): show 12 hour time in table header
cpvalente Jul 30, 2022
feaf5d9
merge master
cpvalente Aug 3, 2022
f725ce8
refactor: extract time formatting into utility
cpvalente Aug 7, 2022
4313e54
refactor: time formatting in views
cpvalente Aug 7, 2022
740fa38
refactor: time formatting in views
cpvalente Aug 7, 2022
bdd4204
refactor: time formatting in views
cpvalente Aug 7, 2022
0eefcfe
chore: update tests
cpvalente Aug 7, 2022
1cc6d08
refactor: remove unused functions
cpvalente Aug 8, 2022
6300821
refactor: migrate datetime library
cpvalente Aug 8, 2022
0fa2f55
chore: update tests
cpvalente Aug 8, 2022
4acb99f
refactor: simplify state
cpvalente Aug 8, 2022
fa61c23
refactor: rename var
cpvalente Aug 8, 2022
95877d1
refactor(settings): simplify state
cpvalente Aug 11, 2022
1498879
add state management dependency
cpvalente Aug 12, 2022
e64654f
refactor(settings): move context to atomic state
cpvalente Aug 12, 2022
c378abd
refactor(formatTime): centralise time formatting for viewers
cpvalente Aug 12, 2022
3789b23
refactor(formatTime): update tests
cpvalente Aug 12, 2022
6baca0d
refactor(formatTime): cleanup
cpvalente Aug 12, 2022
01a7d9f
refactor(formatTime): cleanup
cpvalente Aug 12, 2022
b7e8e30
Merge branch 'feat/161' of https://github.com/cpvalente/ontime into f…
cpvalente Aug 12, 2022
5976dd9
feature(12hour): version bump
cpvalente Aug 29, 2022
7d30a82
merge master
cpvalente Aug 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions client/src/common/atoms/LocalEventSettings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { atomWithStorage, selectAtom } from 'jotai/utils';

export const eventSettingsAtom = atomWithStorage('ontime-eventSettings', {
showQuickEntry: false,
startTimeIsLastEnd: false,
defaultPublic: false,
});

export const showQuickEntryAtom = selectAtom(
eventSettingsAtom,
(settings) => settings.showQuickEntry
);
export const startTimeIsLastEndAtom = selectAtom(
eventSettingsAtom,
(settings) => settings.startTimeIsLastEnd
);
export const defaultPublicAtom = selectAtom(
eventSettingsAtom,
(settings) => settings.defaultPublic
);
4 changes: 1 addition & 3 deletions client/src/common/components/protectRoute/ProtectRoute.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ export default function ProtectRoute({ children }) {
}, [pin, validate]);

// Set window title
useEffect(() => {
document.title = 'ontime';
}, []);
document.title = 'ontime';

// Handle keyboard shortcuts
const handleKeyPress = useCallback(
Expand Down
32 changes: 0 additions & 32 deletions client/src/common/context/LocalEventSettingsContext.jsx

This file was deleted.

37 changes: 16 additions & 21 deletions client/src/features/editors/Editor.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React, { lazy, useEffect } from 'react';
import React, { lazy } from 'react';
import { useDisclosure } from '@chakra-ui/hooks';
import { Box } from '@chakra-ui/layout';
import ErrorBoundary from 'common/components/errorBoundary/ErrorBoundary';
import ModalManager from 'features/modals/ModalManager';

import { LocalEventSettingsProvider } from '../../common/context/LocalEventSettingsContext';
import { LoggingProvider } from '../../common/context/LoggingContext';
import MenuBar from '../menu/MenuBar';

Expand All @@ -19,28 +18,24 @@ export default function Editor() {
const { isOpen, onOpen, onClose } = useDisclosure();

// Set window title
useEffect(() => {
document.title = 'ontime - Editor';
}, []);
document.title = 'ontime - Editor';

return (
<LoggingProvider>
<LocalEventSettingsProvider>
<ErrorBoundary>
<ModalManager isOpen={isOpen} onClose={onClose} />
</ErrorBoundary>
<div className={styles.mainContainer}>
<Box id='settings' className={styles.settings}>
<ErrorBoundary>
<MenuBar onOpen={onOpen} isOpen={isOpen} onClose={onClose} />
</ErrorBoundary>
</Box>
<EventList onOpen={onOpen} isOpen={isOpen} onClose={onClose} />
<MessageControl />
<TimerControl />
<Info />
</div>
</LocalEventSettingsProvider>
<ErrorBoundary>
<ModalManager isOpen={isOpen} onClose={onClose} />
</ErrorBoundary>
<div className={styles.mainContainer}>
<Box id='settings' className={styles.settings}>
<ErrorBoundary>
<MenuBar onOpen={onOpen} isOpen={isOpen} onClose={onClose} />
</ErrorBoundary>
</Box>
<EventList onOpen={onOpen} isOpen={isOpen} onClose={onClose} />
<MessageControl />
<TimerControl />
<Info />
</div>
</LoggingProvider>
);
}
24 changes: 15 additions & 9 deletions client/src/features/editors/EntryBlock/EntryBlock.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import React, { useContext, useEffect, useState } from 'react';
import React, { useEffect, useState } from 'react';
import { Checkbox } from '@chakra-ui/react';
import { Tooltip } from '@chakra-ui/tooltip';
import { useAtomValue } from 'jotai';
import PropTypes from 'prop-types';

import { LocalEventSettingsContext } from '../../../common/context/LocalEventSettingsContext';
import {
defaultPublicAtom,
startTimeIsLastEndAtom,
} from '../../../common/atoms/LocalEventSettings';

import style from './EntryBlock.module.scss';

Expand All @@ -16,13 +20,14 @@ export default function EntryBlock(props) {
disableAddDelay = true,
disableAddBlock,
} = props;
const { starTimeIsLastEnd, defaultPublic } = useContext(LocalEventSettingsContext);
const [doStartTime, setStartTime] = useState(starTimeIsLastEnd);
const startTimeIsLastEnd = useAtomValue(startTimeIsLastEndAtom);
const defaultPublic = useAtomValue(defaultPublicAtom);
const [doStartTime, setStartTime] = useState(startTimeIsLastEnd);
const [doPublic, setPublic] = useState(defaultPublic);

useEffect(() => {
setStartTime(starTimeIsLastEnd);
}, [starTimeIsLastEnd]);
setStartTime(startTimeIsLastEnd);
}, [startTimeIsLastEnd]);

useEffect(() => {
setPublic(defaultPublic);
Expand All @@ -36,7 +41,7 @@ export default function EntryBlock(props) {
onClick={() =>
eventsHandler(
'add',
{ type: 'event', after: previousId, isPublic: doPublic },
{ type: 'event', after: previousId, isPublic: doPublic },
{ startIsLastEnd: doStartTime ? previousId : undefined }
)
}
Expand Down Expand Up @@ -68,7 +73,9 @@ export default function EntryBlock(props) {
size='sm'
colorScheme='blue'
isChecked={doStartTime}
onChange={(e) => setStartTime(e.target.checked)}
onChange={(e) => {
setStartTime(e.target.checked);
}}
>
Start time is last end
</Checkbox>
Expand All @@ -93,4 +100,3 @@ EntryBlock.propTypes = {
disableAddDelay: PropTypes.bool,
disableAddBlock: PropTypes.bool,
};

40 changes: 22 additions & 18 deletions client/src/features/editors/list/EventList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import React, { createRef, useCallback, useContext, useEffect, useState } from '
import { DragDropContext, Droppable } from 'react-beautiful-dnd';
import Empty from 'common/components/state/Empty';
import { useSocket } from 'common/context/socketContext';
import { useAtomValue } from 'jotai';

import { showQuickEntryAtom } from '../../../common/atoms/LocalEventSettings';
import { CursorContext } from '../../../common/context/CursorContext';
import { LocalEventSettingsContext } from '../../../common/context/LocalEventSettingsContext';
import EntryBlock from '../EntryBlock/EntryBlock';

import EventListItem from './EventListItem';
Expand All @@ -19,21 +20,24 @@ export default function EventList(props) {
const [selectedId, setSelectedId] = useState(null);
const [nextId, setNextId] = useState(null);
const cursorRef = createRef();
const { showQuickEntry } = useContext(LocalEventSettingsContext);

const insertAtCursor = useCallback((type, cursor) => {
if (cursor === -1) {
eventsHandler('add', { type: type });
} else {
const previousEvent = events[cursor];
const nextEvent = events[cursor + 1];
if (type === 'event') {
eventsHandler('add', { type: type, after: previousEvent.id });
} else if (previousEvent?.type !== type && nextEvent?.type !== type) {
eventsHandler('add', { type: type, after: previousEvent.id });
const showQuickEntry = useAtomValue(showQuickEntryAtom);

const insertAtCursor = useCallback(
cpvalente marked this conversation as resolved.
Show resolved Hide resolved
(type, cursor) => {
if (cursor === -1) {
eventsHandler('add', { type: type });
} else {
const previousEvent = events[cursor];
const nextEvent = events[cursor + 1];
if (type === 'event') {
eventsHandler('add', { type: type, after: previousEvent.id });
} else if (previousEvent?.type !== type && nextEvent?.type !== type) {
eventsHandler('add', { type: type, after: previousEvent.id });
}
}
}
},[events, eventsHandler])
},
[events, eventsHandler]
);

// Handle keyboard shortcuts
const handleKeyPress = useCallback(
Expand All @@ -54,19 +58,19 @@ export default function EventList(props) {
if (e.key === 'e' || e.key === 'E') {
e.preventDefault();
if (cursor == null) return;
insertAtCursor('event', cursor)
insertAtCursor('event', cursor);
}
// D
if (e.key === 'd' || e.key === 'D') {
e.preventDefault();
if (cursor == null) return;
insertAtCursor('delay', cursor)
insertAtCursor('delay', cursor);
}
// B
if (e.key === 'b' || e.key === 'B') {
e.preventDefault();
if (cursor == null) return;
insertAtCursor('block', cursor)
insertAtCursor('block', cursor);
}
}
},
Expand Down
30 changes: 13 additions & 17 deletions client/src/features/editors/list/EventListItem.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import React, { memo, useCallback, useContext } from 'react';
import { useAtomValue } from 'jotai';
import PropTypes from 'prop-types';

import { LocalEventSettingsContext } from '../../../common/context/LocalEventSettingsContext';
import {
defaultPublicAtom,
startTimeIsLastEndAtom,
} from '../../../common/atoms/LocalEventSettings';
import { LoggingContext } from '../../../common/context/LoggingContext';
import BlockBlock from '../BlockBlock/BlockBlock';
import DelayBlock from '../DelayBlock/DelayBlock';
Expand All @@ -19,19 +23,11 @@ const areEqual = (prevProps, nextProps) => {
};

const EventListItem = (props) => {
const {
type,
index,
eventIndex,
data,
selected,
next,
eventsHandler,
delay,
previousEnd,
} = props;
const { type, index, eventIndex, data, selected, next, eventsHandler, delay, previousEnd } =
props;
const { emitError } = useContext(LoggingContext);
const { starTimeIsLastEnd, defaultPublic } = useContext(LocalEventSettingsContext);
const startTimeIsLastEnd = useAtomValue(startTimeIsLastEndAtom);
const defaultPublic = useAtomValue(defaultPublicAtom);

/**
* @description calculates duration from given options
Expand All @@ -56,7 +52,7 @@ const EventListItem = (props) => {
after: data.id,
isPublic: defaultPublic,
},
{ startIsLastEnd: starTimeIsLastEnd ? data.id : undefined }
{ startIsLastEnd: startTimeIsLastEnd ? data.id : undefined }
);
break;
case 'delay':
Expand Down Expand Up @@ -103,7 +99,7 @@ const EventListItem = (props) => {
break;
}
},
[calculateDuration, data, defaultPublic, emitError, eventsHandler, starTimeIsLastEnd]
[calculateDuration, data, defaultPublic, emitError, eventsHandler, startTimeIsLastEnd]
);

switch (type) {
Expand Down Expand Up @@ -147,5 +143,5 @@ EventListItem.propTypes = {
next: PropTypes.bool,
eventsHandler: PropTypes.func,
delay: PropTypes.number,
previousEnd: PropTypes.number
}
previousEnd: PropTypes.number,
};
Loading