mirror of
https://github.com/cpvalente/ontime.git
synced 2026-09-03 13:29:06 +00:00
refactor: remove isNextDay block property
This commit is contained in:
committed by
Carlos Valente
parent
ab8bfbcd59
commit
a98c14406d
@@ -6,7 +6,6 @@ import * as Editor from '../../../common/components/editor-utils/EditorUtils';
|
|||||||
import SwatchSelect from '../../../common/components/input/colour-input/SwatchSelect';
|
import SwatchSelect from '../../../common/components/input/colour-input/SwatchSelect';
|
||||||
import NullableTimeInput from '../../../common/components/input/time-input/NullableTimeInput';
|
import NullableTimeInput from '../../../common/components/input/time-input/NullableTimeInput';
|
||||||
import AppLink from '../../../common/components/link/app-link/AppLink';
|
import AppLink from '../../../common/components/link/app-link/AppLink';
|
||||||
import Switch from '../../../common/components/switch/Switch';
|
|
||||||
import { useEntryActions } from '../../../common/hooks/useEntryAction';
|
import { useEntryActions } from '../../../common/hooks/useEntryAction';
|
||||||
import useCustomFields from '../../../common/hooks-query/useCustomFields';
|
import useCustomFields from '../../../common/hooks-query/useCustomFields';
|
||||||
import { enDash, timerPlaceholder } from '../../../common/utils/styleUtils';
|
import { enDash, timerPlaceholder } from '../../../common/utils/styleUtils';
|
||||||
@@ -21,7 +20,6 @@ import style from './EntryEditor.module.scss';
|
|||||||
// title + colour + custom field labels
|
// title + colour + custom field labels
|
||||||
export type BlockEditorUpdateTextFields = 'targetDuration' | 'title' | 'colour' | string;
|
export type BlockEditorUpdateTextFields = 'targetDuration' | 'title' | 'colour' | string;
|
||||||
export type BlockEditorUpdateMaybeNumberFields = 'targetDuration';
|
export type BlockEditorUpdateMaybeNumberFields = 'targetDuration';
|
||||||
export type BlockEditorBooleanFields = 'isNextDay';
|
|
||||||
|
|
||||||
interface BlockEditorProps {
|
interface BlockEditorProps {
|
||||||
block: OntimeBlock;
|
block: OntimeBlock;
|
||||||
@@ -32,10 +30,7 @@ export default function BlockEditor({ block }: BlockEditorProps) {
|
|||||||
const { updateEntry } = useEntryActions();
|
const { updateEntry } = useEntryActions();
|
||||||
|
|
||||||
const handleSubmit = useCallback(
|
const handleSubmit = useCallback(
|
||||||
(
|
(field: BlockEditorUpdateTextFields | BlockEditorUpdateMaybeNumberFields, value: string | boolean) => {
|
||||||
field: BlockEditorUpdateTextFields | BlockEditorUpdateMaybeNumberFields | BlockEditorBooleanFields,
|
|
||||||
value: string | boolean,
|
|
||||||
) => {
|
|
||||||
// Handle custom fields
|
// Handle custom fields
|
||||||
if (typeof field === 'string' && field.startsWith('custom-')) {
|
if (typeof field === 'string' && field.startsWith('custom-')) {
|
||||||
const fieldLabel = field.split('custom-')[1];
|
const fieldLabel = field.split('custom-')[1];
|
||||||
@@ -51,10 +46,6 @@ export default function BlockEditor({ block }: BlockEditorProps) {
|
|||||||
return updateEntry({ id: block.id, targetDuration: parseUserTime(value as string) });
|
return updateEntry({ id: block.id, targetDuration: parseUserTime(value as string) });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (field === 'isNextDay') {
|
|
||||||
return updateEntry({ id: block.id, isNextDay: value as boolean });
|
|
||||||
}
|
|
||||||
|
|
||||||
// all other strings are text fields
|
// all other strings are text fields
|
||||||
return updateEntry({ id: block.id, [field]: value as string });
|
return updateEntry({ id: block.id, [field]: value as string });
|
||||||
},
|
},
|
||||||
@@ -112,18 +103,6 @@ export default function BlockEditor({ block }: BlockEditorProps) {
|
|||||||
</TextLikeInput>
|
</TextLikeInput>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
|
||||||
<Editor.Label htmlFor='isNextDay'>Is next day?</Editor.Label>
|
|
||||||
<Editor.Label className={style.switchLabel}>
|
|
||||||
<Switch
|
|
||||||
checked={block.isNextDay}
|
|
||||||
onCheckedChange={(checked) => {
|
|
||||||
handleSubmit('isNextDay', checked);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
{block.isNextDay ? 'Events start the day after' : '-'}
|
|
||||||
</Editor.Label>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={style.column}>
|
<div className={style.column}>
|
||||||
|
|||||||
@@ -135,7 +135,6 @@ export function createBlockPatch(originalBlock: OntimeBlock, patchBlock: Partial
|
|||||||
title: makeString(patchBlock.title, originalBlock.title),
|
title: makeString(patchBlock.title, originalBlock.title),
|
||||||
note: makeString(patchBlock.note, originalBlock.note),
|
note: makeString(patchBlock.note, originalBlock.note),
|
||||||
entries: patchBlock.entries ?? originalBlock.entries,
|
entries: patchBlock.entries ?? originalBlock.entries,
|
||||||
isNextDay: typeof patchBlock.isNextDay === 'boolean' ? patchBlock.isNextDay : originalBlock.isNextDay,
|
|
||||||
targetDuration: maybeTargetDuration(),
|
targetDuration: maybeTargetDuration(),
|
||||||
colour: makeString(patchBlock.colour, originalBlock.colour),
|
colour: makeString(patchBlock.colour, originalBlock.colour),
|
||||||
revision: originalBlock.revision,
|
revision: originalBlock.revision,
|
||||||
@@ -231,7 +230,6 @@ export function createBlock(patch?: Partial<OntimeBlock>): OntimeBlock {
|
|||||||
title: patch.title ?? '',
|
title: patch.title ?? '',
|
||||||
note: patch.note ?? '',
|
note: patch.note ?? '',
|
||||||
entries: patch.entries ?? [],
|
entries: patch.entries ?? [],
|
||||||
isNextDay: patch.isNextDay ?? false,
|
|
||||||
targetDuration: patch.targetDuration ?? null,
|
targetDuration: patch.targetDuration ?? null,
|
||||||
colour: makeString(patch.colour, ''),
|
colour: makeString(patch.colour, ''),
|
||||||
custom: patch.custom ?? {},
|
custom: patch.custom ?? {},
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ export const demoDb: DatabaseModel = {
|
|||||||
id: 'block',
|
id: 'block',
|
||||||
title: 'Test Block',
|
title: 'Test Block',
|
||||||
note: '',
|
note: '',
|
||||||
isNextDay: false,
|
|
||||||
targetDuration: null,
|
targetDuration: null,
|
||||||
colour: 'hotpink',
|
colour: 'hotpink',
|
||||||
revision: 0,
|
revision: 0,
|
||||||
@@ -212,7 +211,6 @@ export const demoDb: DatabaseModel = {
|
|||||||
note: '',
|
note: '',
|
||||||
colour: '',
|
colour: '',
|
||||||
entries: [],
|
entries: [],
|
||||||
isNextDay: false,
|
|
||||||
targetDuration: null,
|
targetDuration: null,
|
||||||
custom: {},
|
custom: {},
|
||||||
revision: 0,
|
revision: 0,
|
||||||
@@ -375,7 +373,6 @@ export const demoDb: DatabaseModel = {
|
|||||||
note: '',
|
note: '',
|
||||||
colour: '',
|
colour: '',
|
||||||
entries: [],
|
entries: [],
|
||||||
isNextDay: false,
|
|
||||||
targetDuration: null,
|
targetDuration: null,
|
||||||
custom: {},
|
custom: {},
|
||||||
revision: 0,
|
revision: 0,
|
||||||
|
|||||||
@@ -58,7 +58,6 @@ export const block: Omit<OntimeBlock, 'id'> = {
|
|||||||
title: '',
|
title: '',
|
||||||
note: '',
|
note: '',
|
||||||
entries: [],
|
entries: [],
|
||||||
isNextDay: false,
|
|
||||||
targetDuration: null,
|
targetDuration: null,
|
||||||
colour: '',
|
colour: '',
|
||||||
custom: {},
|
custom: {},
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ export type OntimeBlock = OntimeBaseEvent & {
|
|||||||
title: string;
|
title: string;
|
||||||
note: string;
|
note: string;
|
||||||
entries: EntryId[];
|
entries: EntryId[];
|
||||||
isNextDay: boolean;
|
|
||||||
targetDuration: MaybeNumber;
|
targetDuration: MaybeNumber;
|
||||||
colour: string;
|
colour: string;
|
||||||
custom: EntryCustomFields;
|
custom: EntryCustomFields;
|
||||||
|
|||||||
Reference in New Issue
Block a user