mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: edit url cell
This commit is contained in:
parent
c50c23bc3a
commit
f86254c8ef
@ -0,0 +1,29 @@
|
|||||||
|
import { CellController } from '$app/stores/effects/database/cell/cell_controller';
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
|
export const EditCellNumber = ({
|
||||||
|
data,
|
||||||
|
cellController,
|
||||||
|
}: {
|
||||||
|
data: string | undefined;
|
||||||
|
cellController: CellController<any, any>;
|
||||||
|
}) => {
|
||||||
|
const [value, setValue] = useState('');
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setValue(data || '');
|
||||||
|
}, [data]);
|
||||||
|
|
||||||
|
const save = async () => {
|
||||||
|
await cellController?.saveCellData(value);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<input
|
||||||
|
value={value}
|
||||||
|
onChange={(e) => setValue(e.target.value)}
|
||||||
|
onBlur={() => save()}
|
||||||
|
className={'w-full px-4 py-2'}
|
||||||
|
></input>
|
||||||
|
);
|
||||||
|
};
|
@ -1,11 +1,18 @@
|
|||||||
import { CellController } from '$app/stores/effects/database/cell/cell_controller';
|
import { CellController } from '$app/stores/effects/database/cell/cell_controller';
|
||||||
import { useEffect, useState, KeyboardEvent, useMemo } from 'react';
|
import { useEffect, useState, KeyboardEvent, useMemo } from 'react';
|
||||||
|
|
||||||
export const EditCellText = ({ data, cellController }: { data: string; cellController: CellController<any, any> }) => {
|
export const EditCellText = ({
|
||||||
|
data,
|
||||||
|
cellController,
|
||||||
|
}: {
|
||||||
|
data: string | undefined;
|
||||||
|
cellController: CellController<any, any>;
|
||||||
|
}) => {
|
||||||
const [value, setValue] = useState('');
|
const [value, setValue] = useState('');
|
||||||
const [contentRows, setContentRows] = useState(1);
|
const [contentRows, setContentRows] = useState(1);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setValue(data);
|
setValue(data || '');
|
||||||
}, [data]);
|
}, [data]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -21,9 +28,9 @@ export const EditCellText = ({ data, cellController }: { data: string; cellContr
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={'px-4 py-2'}>
|
<div className={''}>
|
||||||
<textarea
|
<textarea
|
||||||
className={'h-full w-full resize-none'}
|
className={'mt-0.5 h-full w-full resize-none px-4 py-2'}
|
||||||
rows={contentRows}
|
rows={contentRows}
|
||||||
value={value}
|
value={value}
|
||||||
onChange={(e) => onTextFieldChange(e.target.value)}
|
onChange={(e) => onTextFieldChange(e.target.value)}
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
import { URLCellDataPB } from '@/services/backend';
|
||||||
|
import { CellController } from '$app/stores/effects/database/cell/cell_controller';
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { URLCellController } from '$app/stores/effects/database/cell/controller_builder';
|
||||||
|
|
||||||
|
export const EditCellUrl = ({
|
||||||
|
data,
|
||||||
|
cellController,
|
||||||
|
}: {
|
||||||
|
data: URLCellDataPB | undefined;
|
||||||
|
cellController: CellController<any, any>;
|
||||||
|
}) => {
|
||||||
|
const [url, setUrl] = useState('');
|
||||||
|
const [content, setContent] = useState('');
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setUrl((data as URLCellDataPB)?.url || '');
|
||||||
|
}, [data]);
|
||||||
|
|
||||||
|
const save = async () => {
|
||||||
|
await (cellController as URLCellController)?.saveCellData(url);
|
||||||
|
// console.log('saving url');
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={'flex flex-col px-4 py-2'}>
|
||||||
|
<label className={'mb-1'}>URL:</label>
|
||||||
|
<input
|
||||||
|
value={url}
|
||||||
|
onChange={(e) => setUrl(e.target.value)}
|
||||||
|
className={'-mx-2 mb-4 rounded bg-white px-2 py-1'}
|
||||||
|
onBlur={() => save()}
|
||||||
|
/>
|
||||||
|
<label className={'mb-1'}>Content:</label>
|
||||||
|
<input
|
||||||
|
value={content}
|
||||||
|
onChange={(e) => setContent(e.target.value)}
|
||||||
|
className={'-mx-2 mb-2 rounded bg-white px-2 py-1'}
|
||||||
|
onBlur={() => save()}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
@ -2,16 +2,16 @@ import { CellIdentifier } from '$app/stores/effects/database/cell/cell_bd_svc';
|
|||||||
import { useCell } from '$app/components/_shared/database-hooks/useCell';
|
import { useCell } from '$app/components/_shared/database-hooks/useCell';
|
||||||
import { CellCache } from '$app/stores/effects/database/cell/cell_cache';
|
import { CellCache } from '$app/stores/effects/database/cell/cell_cache';
|
||||||
import { FieldController } from '$app/stores/effects/database/field/field_controller';
|
import { FieldController } from '$app/stores/effects/database/field/field_controller';
|
||||||
import { DateCellDataPB, FieldType, SelectOptionCellDataPB } from '@/services/backend';
|
import { DateCellDataPB, FieldType, SelectOptionCellDataPB, URLCellDataPB } from '@/services/backend';
|
||||||
import { useAppSelector } from '$app/stores/store';
|
import { useAppSelector } from '$app/stores/store';
|
||||||
import { getBgColor } from '$app/components/_shared/getColor';
|
|
||||||
import { EditorCheckSvg } from '$app/components/_shared/svg/EditorCheckSvg';
|
|
||||||
import { EditorUncheckSvg } from '$app/components/_shared/svg/EditorUncheckSvg';
|
|
||||||
import { EditCellText } from '$app/components/_shared/EditRow/EditCellText';
|
import { EditCellText } from '$app/components/_shared/EditRow/EditCellText';
|
||||||
import { FieldTypeIcon } from '$app/components/_shared/EditRow/FieldTypeIcon';
|
import { FieldTypeIcon } from '$app/components/_shared/EditRow/FieldTypeIcon';
|
||||||
import { EditCellDate } from '$app/components/_shared/EditRow/EditCellDate';
|
import { EditCellDate } from '$app/components/_shared/EditRow/EditCellDate';
|
||||||
import { useRef } from 'react';
|
import { useRef } from 'react';
|
||||||
import { CellOptions } from '$app/components/_shared/EditRow/CellOptions';
|
import { CellOptions } from '$app/components/_shared/EditRow/CellOptions';
|
||||||
|
import { EditCellNumber } from '$app/components/_shared/EditRow/EditCellNumber';
|
||||||
|
import { EditCheckboxCell } from '$app/components/_shared/EditRow/EditCheckboxCell';
|
||||||
|
import { EditCellUrl } from '$app/components/_shared/EditRow/EditCellUrl';
|
||||||
|
|
||||||
export const EditCellWrapper = ({
|
export const EditCellWrapper = ({
|
||||||
cellIdentifier,
|
cellIdentifier,
|
||||||
@ -61,20 +61,25 @@ export const EditCellWrapper = ({
|
|||||||
></CellOptions>
|
></CellOptions>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{cellIdentifier.fieldType === FieldType.Checkbox && (
|
{cellIdentifier.fieldType === FieldType.Checkbox && cellController && (
|
||||||
<div className={'h-8 w-8 px-4 py-2'}>
|
<EditCheckboxCell data={data as boolean | undefined} cellController={cellController}></EditCheckboxCell>
|
||||||
{(data as boolean | undefined) ? <EditorCheckSvg></EditorCheckSvg> : <EditorUncheckSvg></EditorUncheckSvg>}
|
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{cellIdentifier.fieldType === FieldType.DateTime && cellController && (
|
{cellIdentifier.fieldType === FieldType.DateTime && cellController && (
|
||||||
<EditCellDate data={data as DateCellDataPB | undefined} cellController={cellController}></EditCellDate>
|
<EditCellDate data={data as DateCellDataPB | undefined} cellController={cellController}></EditCellDate>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{(cellIdentifier.fieldType === FieldType.RichText ||
|
{cellIdentifier.fieldType === FieldType.Number && cellController && (
|
||||||
cellIdentifier.fieldType === FieldType.URL ||
|
<EditCellNumber data={data as string | undefined} cellController={cellController}></EditCellNumber>
|
||||||
cellIdentifier.fieldType === FieldType.Number) &&
|
)}
|
||||||
cellController && <EditCellText data={data as string} cellController={cellController}></EditCellText>}
|
|
||||||
|
{cellIdentifier.fieldType === FieldType.URL && cellController && (
|
||||||
|
<EditCellUrl data={data as URLCellDataPB | undefined} cellController={cellController}></EditCellUrl>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{cellIdentifier.fieldType === FieldType.RichText && cellController && (
|
||||||
|
<EditCellText data={data as string | undefined} cellController={cellController}></EditCellText>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
import { EditorCheckSvg } from '$app/components/_shared/svg/EditorCheckSvg';
|
||||||
|
import { EditorUncheckSvg } from '$app/components/_shared/svg/EditorUncheckSvg';
|
||||||
|
import { CellController } from '$app/stores/effects/database/cell/cell_controller';
|
||||||
|
|
||||||
|
export const EditCheckboxCell = ({
|
||||||
|
data,
|
||||||
|
cellController,
|
||||||
|
}: {
|
||||||
|
data: boolean | undefined;
|
||||||
|
cellController: CellController<any, any>;
|
||||||
|
}) => {
|
||||||
|
const toggleValue = async () => {
|
||||||
|
await cellController?.saveCellData(!data);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div onClick={() => toggleValue()} className={'block px-4 py-2'}>
|
||||||
|
<button className={'h-5 w-5'}>
|
||||||
|
{data ? <EditorCheckSvg></EditorCheckSvg> : <EditorUncheckSvg></EditorUncheckSvg>}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
@ -5,6 +5,7 @@ import { FieldType } from '../../../services/backend';
|
|||||||
import { BoardOptionsCell } from './BoardOptionsCell';
|
import { BoardOptionsCell } from './BoardOptionsCell';
|
||||||
import { BoardDateCell } from './BoardDateCell';
|
import { BoardDateCell } from './BoardDateCell';
|
||||||
import { BoardTextCell } from './BoardTextCell';
|
import { BoardTextCell } from './BoardTextCell';
|
||||||
|
import { BoardUrlCell } from '$app/components/board/BoardUrlCell';
|
||||||
|
|
||||||
export const BoardCell = ({
|
export const BoardCell = ({
|
||||||
cellIdentifier,
|
cellIdentifier,
|
||||||
@ -31,6 +32,12 @@ export const BoardCell = ({
|
|||||||
cellCache={cellCache}
|
cellCache={cellCache}
|
||||||
fieldController={fieldController}
|
fieldController={fieldController}
|
||||||
></BoardDateCell>
|
></BoardDateCell>
|
||||||
|
) : cellIdentifier.fieldType === FieldType.URL ? (
|
||||||
|
<BoardUrlCell
|
||||||
|
cellIdentifier={cellIdentifier}
|
||||||
|
cellCache={cellCache}
|
||||||
|
fieldController={fieldController}
|
||||||
|
></BoardUrlCell>
|
||||||
) : (
|
) : (
|
||||||
<BoardTextCell
|
<BoardTextCell
|
||||||
cellIdentifier={cellIdentifier}
|
cellIdentifier={cellIdentifier}
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
import { CellIdentifier } from '$app/stores/effects/database/cell/cell_bd_svc';
|
||||||
|
import { CellCache } from '$app/stores/effects/database/cell/cell_cache';
|
||||||
|
import { FieldController } from '$app/stores/effects/database/field/field_controller';
|
||||||
|
import { useCell } from '$app/components/_shared/database-hooks/useCell';
|
||||||
|
import { URLCellDataPB } from '@/services/backend';
|
||||||
|
|
||||||
|
export const BoardUrlCell = ({
|
||||||
|
cellIdentifier,
|
||||||
|
cellCache,
|
||||||
|
fieldController,
|
||||||
|
}: {
|
||||||
|
cellIdentifier: CellIdentifier;
|
||||||
|
cellCache: CellCache;
|
||||||
|
fieldController: FieldController;
|
||||||
|
}) => {
|
||||||
|
const { data } = useCell(cellIdentifier, cellCache, fieldController);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<a
|
||||||
|
className={'text-main-accent hover:underline'}
|
||||||
|
href={(data as URLCellDataPB | undefined)?.url || ''}
|
||||||
|
target={'_blank'}
|
||||||
|
>
|
||||||
|
{(data as URLCellDataPB | undefined)?.content || ''}
|
||||||
|
</a>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user