mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-11 10:23:54 +00:00
3603b836f6
* refactor: typescript migration * chore: remove prop-types package * refactor: file structure * refactor: migrate ontime table to tanstack table 8 * refactor: rundown controller uses service as data source * refactor: convert to typescript * feat: caching store * refactor: add delay values to rundown * feat: toggle past visibility * chore: update tests * refactor: add extra fields to CSV * style: show skipped events * chore: add route to navigation menu * style: allow jumping to bottom * chore: add tests
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import { ChangeEvent, memo, useCallback, useEffect, useState } from 'react';
|
|
|
|
import { AutoTextArea } from '../../../common/components/input/auto-text-area/AutoTextArea';
|
|
|
|
interface EditableCellProps {
|
|
value: string;
|
|
handleUpdate: (newValue: string) => void;
|
|
}
|
|
|
|
const EditableCell = (props: EditableCellProps) => {
|
|
const { value: initialValue, handleUpdate } = props;
|
|
|
|
// We need to keep and update the state of the cell normally
|
|
const [value, setValue] = useState(initialValue);
|
|
|
|
const onChange = useCallback((event: ChangeEvent<HTMLTextAreaElement>) => setValue(event.target.value), []);
|
|
|
|
// We'll only update the external data when the input is blurred
|
|
const onBlur = useCallback(() => handleUpdate(value), [handleUpdate, value]);
|
|
|
|
// If the initialValue is changed external, sync it up with our state
|
|
useEffect(() => {
|
|
setValue(initialValue);
|
|
}, [initialValue]);
|
|
|
|
return (
|
|
<AutoTextArea
|
|
size='sm'
|
|
value={value}
|
|
onChange={onChange}
|
|
onBlur={onBlur}
|
|
rows={1}
|
|
transition='none'
|
|
spellCheck={false}
|
|
style={{ padding: 0 }}
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default memo(EditableCell);
|