GridTextCell.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { CellIdentifier } from '@/appflowy_app/stores/effects/database/cell/cell_bd_svc';
  2. import { CellCache } from '@/appflowy_app/stores/effects/database/cell/cell_cache';
  3. import { FieldController } from '@/appflowy_app/stores/effects/database/field/field_controller';
  4. import { useState, useEffect } from 'react';
  5. import { useCell } from '../../_shared/database-hooks/useCell';
  6. export default function GridTextCell({
  7. cellIdentifier,
  8. cellCache,
  9. fieldController,
  10. }: {
  11. cellIdentifier: CellIdentifier;
  12. cellCache: CellCache;
  13. fieldController: FieldController;
  14. }) {
  15. const { data, cellController } = useCell(cellIdentifier, cellCache, fieldController);
  16. const [value, setValue] = useState((data as string) || '');
  17. useEffect(() => {
  18. if (data) setValue(data as string);
  19. }, [data]);
  20. return (
  21. <input
  22. value={value}
  23. onChange={(e) => {
  24. setValue(e.target.value);
  25. }}
  26. onBlur={async () => {
  27. await cellController?.saveCellData(value);
  28. }}
  29. className='min-h-[32px] w-full p-2 focus:border focus:border-main-accent focus:outline-none '
  30. />
  31. );
  32. }