Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
chore: create cell component for each field type
ascarbek3635b6b63e78
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/database-hooks/useCell.ts b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/database-hooks/useCell.tsindex ff5f0ef07b..f8abcb8734 100644--- a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/database-hooks/useCell.ts+++ b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/database-hooks/useCell.ts@@ -2,31 +2,18 @@ import { CellIdentifier } from '../../../stores/effects/database/cell/cell_bd_svimport { CellCache } from '../../../stores/effects/database/cell/cell_cache';import { FieldController } from '../../../stores/effects/database/field/field_controller';import { CellControllerBuilder } from '../../../stores/effects/database/cell/controller_builder';-import { DateCellDataPB, FieldType, SelectOptionCellDataPB } from '../../../../services/backend';+import { DateCellDataPB, SelectOptionCellDataPB, URLCellDataPB } from '../../../../services/backend';import { useState } from 'react';export const useCell = (cellIdentifier: CellIdentifier, cellCache: CellCache, fieldController: FieldController) => {- const [data, setData] = useState<string[]>([]);+ const [data, setData] = useState<DateCellDataPB | URLCellDataPB | SelectOptionCellDataPB | string | undefined>();const loadCell = async () => {const builder = new CellControllerBuilder(cellIdentifier, cellCache, fieldController);const cellController = builder.build();cellController.subscribeChanged({onCellChanged: (value) => {- if (- cellIdentifier.fieldType === FieldType.Checklist ||- cellIdentifier.fieldType === FieldType.MultiSelect ||- cellIdentifier.fieldType === FieldType.SingleSelect- ) {- const v = value.unwrap() as SelectOptionCellDataPB;- setData(v.select_options.map((option) => option.id));- } else if (cellIdentifier.fieldType === FieldType.DateTime) {- const v = value.unwrap() as DateCellDataPB;- setData([v.date]);- } else {- const v = value.unwrap() as string;- setData([v]);- }+ setData(value.unwrap());},});diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/board/BoardCell.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/board/BoardCell.tsxindex e0a0dc66cc..adb72ddec4 100644--- a/frontend/appflowy_tauri/src/appflowy_app/components/board/BoardCell.tsx+++ b/frontend/appflowy_tauri/src/appflowy_app/components/board/BoardCell.tsx@@ -2,7 +2,11 @@ import { useCell } from '../_shared/database-hooks/useCell';import { CellIdentifier } from '../../stores/effects/database/cell/cell_bd_svc';import { CellCache } from '../../stores/effects/database/cell/cell_cache';import { FieldController } from '../../stores/effects/database/field/field_controller';-import {useEffect} from "react";+import { useEffect } from 'react';+import { DateCellDataPB, FieldType, SelectOptionCellDataPB } from '../../../services/backend';+import { BoardOptionsCell } from './BoardOptionsCell';+import { BoardDateCell } from './BoardDateCell';+import { BoardTextCell } from './BoardTextCell';export const BoardCell = ({cellIdentifier,@@ -16,8 +20,21 @@ export const BoardCell = ({const { loadCell, data } = useCell(cellIdentifier, cellCache, fieldController);useEffect(() => {void (async () => {- await loadCell()+ await loadCell();})();- }, [])- return <div>{data}</div>;+ }, []);++ return (+ <>+ {cellIdentifier.fieldType === FieldType.SingleSelect ||+ cellIdentifier.fieldType === FieldType.MultiSelect ||+ cellIdentifier.fieldType === FieldType.Checklist ? (+ <BoardOptionsCell value={data as SelectOptionCellDataPB | undefined}></BoardOptionsCell>+ ) : cellIdentifier.fieldType === FieldType.DateTime ? (+ <BoardDateCell value={data as DateCellDataPB | undefined}></BoardDateCell>+ ) : (+ <BoardTextCell value={data as string | undefined}></BoardTextCell>+ )}+ </>+ );};diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/board/BoardDateCell.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/board/BoardDateCell.tsxnew file mode 100644index 0000000000..8a9df089ba--- /dev/null+++ b/frontend/appflowy_tauri/src/appflowy_app/components/board/BoardDateCell.tsx@@ -0,0 +1,5 @@+import { DateCellDataPB } from '../../../services/backend';++export const BoardDateCell = ({ value }: { value: DateCellDataPB | undefined }) => {+ return <div>{value?.date || ''}</div>;+};diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/board/BoardOptionsCell.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/board/BoardOptionsCell.tsxnew file mode 100644index 0000000000..2c3e29a416--- /dev/null+++ b/frontend/appflowy_tauri/src/appflowy_app/components/board/BoardOptionsCell.tsx@@ -0,0 +1,5 @@+import { SelectOptionCellDataPB, SelectOptionColorPB } from '../../../services/backend';++export const BoardOptionsCell = ({ value }: { value: SelectOptionCellDataPB | undefined }) => {+ return <>{value?.select_options?.map((option, index) => <div key={index}>{option?.name || ''}</div>) || ''}</>;+};diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/board/BoardTextCell.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/board/BoardTextCell.tsxnew file mode 100644index 0000000000..1cc6efb2fa--- /dev/null+++ b/frontend/appflowy_tauri/src/appflowy_app/components/board/BoardTextCell.tsx@@ -0,0 +1,3 @@+export const BoardTextCell = ({ value }: { value: string | undefined }) => {+ return <div>{value || ''}</div>;+};