Skip to content

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.

Fix/tauri warning to error (#3869)

Kilu.He5f49c1748f2d
diff --git a/frontend/appflowy_tauri/.eslintrc.cjs b/frontend/appflowy_tauri/.eslintrc.cjs
index 7223e5cb39..2047d4f962 100644
--- a/frontend/appflowy_tauri/.eslintrc.cjs
+++ b/frontend/appflowy_tauri/.eslintrc.cjs
@@ -15,20 +15,20 @@ module.exports = {
plugins: ['@typescript-eslint', "react-hooks"],
rules: {
"react-hooks/rules-of-hooks": "error",
- "react-hooks/exhaustive-deps": "warn",
+ "react-hooks/exhaustive-deps": "error",
'@typescript-eslint/adjacent-overload-signatures': 'error',
'@typescript-eslint/no-empty-function': 'error',
- '@typescript-eslint/no-empty-interface': 'warn',
- '@typescript-eslint/no-floating-promises': 'warn',
+ '@typescript-eslint/no-empty-interface': 'error',
+ '@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/no-namespace': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/no-redeclare': 'error',
- '@typescript-eslint/prefer-for-of': 'warn',
+ '@typescript-eslint/prefer-for-of': 'error',
'@typescript-eslint/triple-slash-reference': 'error',
- '@typescript-eslint/unified-signatures': 'warn',
+ '@typescript-eslint/unified-signatures': 'error',
'no-shadow': 'off',
- '@typescript-eslint/no-shadow': 'warn',
+ '@typescript-eslint/no-shadow': 'off',
'constructor-super': 'error',
eqeqeq: ['error', 'always'],
'no-cond-assign': 'error',
@@ -47,18 +47,18 @@ module.exports = {
'no-throw-literal': 'error',
'no-unsafe-finally': 'error',
'no-unused-labels': 'error',
- 'no-var': 'warn',
+ 'no-var': 'error',
'no-void': 'off',
- 'prefer-const': 'warn',
+ 'prefer-const': 'error',
'prefer-spread': 'off',
'@typescript-eslint/no-unused-vars': [
- 'warn',
+ 'error',
{
argsIgnorePattern: '^_',
}
],
'padding-line-between-statements': [
- "warn",
+ "error",
{ blankLine: "always", prev: ["const", "let", "var"], next: "*"},
{ blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"]},
{ blankLine: "always", prev: "import", next: "*" },
diff --git a/frontend/appflowy_tauri/package.json b/frontend/appflowy_tauri/package.json
index 6c65dae94d..e92fdc163f 100644
--- a/frontend/appflowy_tauri/package.json
+++ b/frontend/appflowy_tauri/package.json
@@ -9,7 +9,7 @@
"preview": "vite preview",
"format": "prettier --write .",
"test:code": "eslint --max-warnings=0 --ext .js,.ts,.tsx .",
- "test:errors": "pnpm sync:i18n && tsc --noEmit && eslint --quiet --ext .js,.ts,.tsx .",
+ "test:errors": "pnpm sync:i18n && tsc --noEmit && eslint --ext .js,.ts,.tsx .",
"test:prettier": "pnpm prettier --list-different src",
"tauri:clean": "cargo make --cwd .. tauri_clean",
"tauri:dev": "pnpm sync:i18n && tauri dev",
diff --git a/frontend/appflowy_tauri/src/appflowy_app/assets/close.svg b/frontend/appflowy_tauri/src/appflowy_app/assets/close.svg
new file mode 100644
index 0000000000..b519b419c0
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/assets/close.svg
@@ -0,0 +1,4 @@
+<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
+<rect x="15.7124" y="7.22656" width="1.5" height="12" rx="0.75" transform="rotate(45 15.7124 7.22656)" fill="#333333"/>
+<rect x="16.7729" y="15.7109" width="1.5" height="12" rx="0.75" transform="rotate(135 16.7729 15.7109)" fill="#333333"/>
+</svg>
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/BlockDraggable/BlockDragDropContext.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/BlockDraggable/BlockDragDropContext.tsx
index 2b0a307a37..0d7076b9bc 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/BlockDraggable/BlockDragDropContext.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/BlockDraggable/BlockDragDropContext.tsx
@@ -66,7 +66,7 @@ function BlockDragDropContext({ children }: { children: React.ReactNode }) {
};
const onDragEnd = () => {
- dispatch(onDragEndThunk());
+ void dispatch(onDragEndThunk());
unlisten();
};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/BlockDraggable/index.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/BlockDraggable/index.tsx
index eaf0530c21..9ae0ebc545 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/BlockDraggable/index.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/BlockDraggable/index.tsx
@@ -18,7 +18,7 @@ function BlockDraggable(
} & HTMLAttributes<HTMLDivElement>,
ref: React.Ref<HTMLDivElement>
) {
- const { onDragStart, beforeDropping, afterDropping, childDropping, isDragging } = useDraggableState(id, type);
+ const { onDragStart, beforeDropping, afterDropping, childDropping } = useDraggableState(id, type);
const commonCls = 'pointer-events-none absolute z-10 w-[100%] bg-fill-hover transition-all duration-200';
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/Database.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/Database.hooks.ts
index 50de845116..9b0955793e 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/Database.hooks.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/Database.hooks.ts
@@ -1,11 +1,6 @@
-import { useAppDispatch, useAppSelector } from '../../stores/store';
-import { useEffect, useState } from 'react';
-import { databaseActions, IDatabase } from '../../stores/reducers/database/slice';
-import { nanoid } from 'nanoid';
-import { FieldType } from '../../../services/backend';
+import { useAppSelector } from '$app/stores/store';
export const useDatabase = () => {
- const dispatch = useAppDispatch();
const database = useAppSelector((state) => state.database);
const newField = () => {
@@ -22,7 +17,7 @@ export const useDatabase = () => {
console.log('depreciated');
};
- const renameField = (fieldId: string, newTitle: string) => {
+ const renameField = (_fieldId: string, _newTitle: string) => {
/* const field = database.fields[fieldId];
field.title = newTitle;
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/DatabaseFilter/DatabaseFilterItem.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/DatabaseFilter/DatabaseFilterItem.tsx
index 87c766c814..b0b7d41322 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/DatabaseFilter/DatabaseFilterItem.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/DatabaseFilter/DatabaseFilterItem.tsx
@@ -75,6 +75,7 @@ export const DatabaseFilterItem = ({
value: currentValue,
});
}
+ // eslint-disable-next-line react-hooks/exhaustive-deps
}, [currentFieldId, currentFieldType, currentOperator, currentValue, textInputActive]);
// 1. not all field types support filtering
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/DatabaseSort/DatabaseSortItem.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/DatabaseSort/DatabaseSortItem.tsx
index bc308e574c..5e096dce6e 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/DatabaseSort/DatabaseSortItem.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/DatabaseSort/DatabaseSortItem.tsx
@@ -54,6 +54,7 @@ export const DatabaseSortItem = ({
fieldType: fields[currentFieldId].fieldType,
});
}
+ // eslint-disable-next-line react-hooks/exhaustive-deps
}, [currentFieldId, currentOrder]);
const onSelectFieldClick = (id: string) => {
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/DatabaseSort/DatabaseSortPopup.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/DatabaseSort/DatabaseSortPopup.tsx
index fe2c89772a..98247e3a1a 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/DatabaseSort/DatabaseSortPopup.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/DatabaseSort/DatabaseSortPopup.tsx
@@ -1,5 +1,5 @@
import { t } from 'i18next';
-import { MouseEventHandler, useMemo, useRef, useState } from 'react';
+import { MouseEventHandler, useMemo, useState } from 'react';
import { useAppSelector } from '$app/stores/store';
import { IDatabaseSort } from '$app_reducers/database/slice';
import { DatabaseSortItem } from '$app/components/_shared/DatabaseSort/DatabaseSortItem';
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/CheckList/NewCheckListOption.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/CheckList/NewCheckListOption.tsx
index 1b9a24c116..940929660a 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/CheckList/NewCheckListOption.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/CheckList/NewCheckListOption.tsx
@@ -19,6 +19,7 @@ export const NewCheckListOption = ({
const updateNewOption = (value: string) => {
const newOptionsCopy = [...newOptions];
+
newOptionsCopy[index] = value;
setNewOptions(newOptionsCopy);
};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/DateFormatPopup.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/DateFormatPopup.tsx
index 0ba94e5777..58e68fd281 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/DateFormatPopup.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/DateFormatPopup.tsx
@@ -29,6 +29,7 @@ export const DateFormatPopup = ({
useEffect(() => {
setDateType(databaseStore.fields[cellIdentifier.fieldId]?.fieldOptions as IDateType);
+ // eslint-disable-next-line react-hooks/exhaustive-deps
}, [databaseStore]);
const changeFormat = async (format: DateFormatPB) => {
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/DatePickerPopup.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/DatePickerPopup.tsx
index e9eb02af8e..8d5de41e41 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/DatePickerPopup.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/DatePickerPopup.tsx
@@ -30,6 +30,7 @@ export const DatePickerPopup = ({
useEffect(() => {
const date_pb = data as DateCellDataPB | undefined;
+
if (!date_pb || !date_pb?.date.length) return;
setSelectedDate(dayjs(date_pb.date).toDate());
@@ -39,6 +40,7 @@ export const DatePickerPopup = ({
if (v instanceof Date) {
setSelectedDate(v);
const date = new CalendarData(dayjs(v).add(dayjs().utcOffset(), 'minutes').toDate(), false);
+
await cellController?.saveCellData(date);
}
};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/DateTimeFormat.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/DateTimeFormat.hooks.ts
index e024881350..25784c2efc 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/DateTimeFormat.hooks.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/DateTimeFormat.hooks.ts
@@ -8,11 +8,14 @@ import { FieldController } from '$app/stores/effects/database/field/field_contro
export const useDateTimeFormat = (cellIdentifier: CellIdentifier, fieldController: FieldController) => {
const changeFormat = async (change: (option: DateTypeOptionPB) => void) => {
const fieldInfo = fieldController.getField(cellIdentifier.fieldId);
+
if (!fieldInfo) return;
const typeOptionController = new TypeOptionController(cellIdentifier.viewId, Some(fieldInfo), FieldType.DateTime);
+
await typeOptionController.initialize();
const dateTypeOptionContext = makeDateTypeOptionContext(typeOptionController);
const typeOption = await dateTypeOptionContext.getTypeOption().then((a) => a.unwrap());
+
change(typeOption);
await dateTypeOptionContext.setTypeOption(typeOption);
};
@@ -20,11 +23,13 @@ export const useDateTimeFormat = (cellIdentifier: CellIdentifier, fieldControlle
const changeDateFormat = async (format: DateFormatPB) => {
await changeFormat((option) => (option.date_format = format));
};
+
const changeTimeFormat = async (format: TimeFormatPB) => {
await changeFormat((option) => (option.time_format = format));
};
- const includeTime = async (include: boolean) => {
- await changeFormat((option) => {
+
+ const includeTime = async (_include: boolean) => {
+ await changeFormat((_option) => {
// option.include_time = include;
});
};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/DateTypeOptions.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/DateTypeOptions.tsx
index 0b3f9415d2..c5e813b8b5 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/DateTypeOptions.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/DateTypeOptions.tsx
@@ -1,8 +1,6 @@
import { DateFormatPopup } from '$app/components/_shared/EditRow/Date/DateFormatPopup';
import { TimeFormatPopup } from '$app/components/_shared/EditRow/Date/TimeFormatPopup';
import { MoreSvg } from '$app/components/_shared/svg/MoreSvg';
-import { EditorCheckSvg } from '$app/components/_shared/svg/EditorCheckSvg';
-import { EditorUncheckSvg } from '$app/components/_shared/svg/EditorUncheckSvg';
import { MouseEventHandler, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { IDateType } from '$app_reducers/database/slice';
@@ -27,14 +25,16 @@ export const DateTypeOptions = ({
const [showTimeFormatPopup, setShowTimeFormatPopup] = useState(false);
const [timeFormatTop, setTimeFormatTop] = useState(0);
const [timeFormatLeft, setTimeFormatLeft] = useState(0);
-
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
const [dateType, setDateType] = useState<IDateType | undefined>();
const databaseStore = useAppSelector((state) => state.database);
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
const { includeTime } = useDateTimeFormat(cellIdentifier, fieldController);
useEffect(() => {
setDateType(databaseStore.fields[cellIdentifier.fieldId]?.fieldOptions as IDateType);
+ // eslint-disable-next-line react-hooks/exhaustive-deps
}, [databaseStore]);
const onDateFormatClick = (_left: number, _top: number) => {
@@ -87,7 +87,7 @@ export const DateTypeOptions = ({
return (
<div className={'flex flex-col'}>
- <hr className={'border-line-divider -mx-2 my-2'} />
+ <hr className={'-mx-2 my-2 border-line-divider'} />
<button
onClick={_onDateFormatClick}
className={
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/EditCellDate.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/EditCellDate.tsx
index 08f0871d7c..1fb6656c6f 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/EditCellDate.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/EditCellDate.tsx
@@ -13,6 +13,7 @@ export const EditCellDate = ({
const onClick: MouseEventHandler = () => {
if (!ref.current) return;
const { left, top } = ref.current.getBoundingClientRect();
+
onEditClick(left, top);
};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/NumberFormat.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/NumberFormat.hooks.ts
index 945074e460..81bc6f797c 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/NumberFormat.hooks.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/NumberFormat.hooks.ts
@@ -8,11 +8,14 @@ import { makeNumberTypeOptionContext } from '$app/stores/effects/database/field/
export const useNumberFormat = (cellIdentifier: CellIdentifier, fieldController: FieldController) => {
const changeNumberFormat = async (format: NumberFormatPB) => {
const fieldInfo = fieldController.getField(cellIdentifier.fieldId);
+
if (!fieldInfo) return;
const typeOptionController = new TypeOptionController(cellIdentifier.viewId, Some(fieldInfo), FieldType.Number);
+
await typeOptionController.initialize();
const numberTypeOptionContext = makeNumberTypeOptionContext(typeOptionController);
const typeOption = await numberTypeOptionContext.getTypeOption().then((a) => a.unwrap());
+
typeOption.format = format;
await numberTypeOptionContext.setTypeOption(typeOption);
};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/NumberFormatPopup.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/NumberFormatPopup.tsx
index 297f2caa2e..df4749befc 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/NumberFormatPopup.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/NumberFormatPopup.tsx
@@ -66,6 +66,7 @@ export const NumberFormatPopup = ({
useEffect(() => {
setNumberType(databaseStore.fields[cellIdentifier.fieldId]?.fieldOptions as INumberType);
+ // eslint-disable-next-line react-hooks/exhaustive-deps
}, [databaseStore]);
const changeNumberFormatClick = async (format: NumberFormatPB) => {
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/TimeFormatPopup.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/TimeFormatPopup.tsx
index ecdbf7e8a0..287d93a091 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/TimeFormatPopup.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Date/TimeFormatPopup.tsx
@@ -28,6 +28,7 @@ export const TimeFormatPopup = ({
useEffect(() => {
setDateType(databaseStore.fields[cellIdentifier.fieldId]?.fieldOptions as IDateType);
+ // eslint-disable-next-line react-hooks/exhaustive-deps
}, [databaseStore]);
const { changeTimeFormat } = useDateTimeFormat(cellIdentifier, fieldController);
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/EditFieldPopup.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/EditFieldPopup.tsx
index b29220bd99..6d9e041990 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/EditFieldPopup.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/EditFieldPopup.tsx
@@ -59,6 +59,7 @@ export const EditFieldPopup = ({
const save = async () => {
if (!controller) return;
const fieldInfo = controller.fieldController.getField(cellIdentifier.fieldId);
+
if (!fieldInfo) return;
const typeOptionController = new TypeOptionController(viewId, Some(fieldInfo));
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/EditRow.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/EditRow.tsx
index 490d1cddb5..9939c8b9cc 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/EditRow.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/EditRow.tsx
@@ -66,7 +66,9 @@ export const EditRow = ({
const [editCheckListLeft, setEditCheckListLeft] = useState(0);
const [showNumberFormatPopup, setShowNumberFormatPopup] = useState(false);
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
const [numberFormatTop, setNumberFormatTop] = useState(0);
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
const [numberFormatLeft, setNumberFormatLeft] = useState(0);
const [showCheckListPopup, setShowCheckListPopup] = useState(false);
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/FieldTypeName.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/FieldTypeName.tsx
index daeff4cdf0..06d1f601ce 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/FieldTypeName.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/FieldTypeName.tsx
@@ -3,6 +3,7 @@ import { useTranslation } from 'react-i18next';
export const FieldTypeName = ({ fieldType }: { fieldType: FieldType }) => {
const { t } = useTranslation();
+
return (
<>
{fieldType === FieldType.RichText && t('grid.field.textFieldName')}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/InlineEditFields/EditCheckboxCell.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/InlineEditFields/EditCheckboxCell.tsx
index f05684d6d6..efed3a23ba 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/InlineEditFields/EditCheckboxCell.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/InlineEditFields/EditCheckboxCell.tsx
@@ -1,6 +1,5 @@
import { EditorCheckSvg } from '$app/components/_shared/svg/EditorCheckSvg';
import { EditorUncheckSvg } from '$app/components/_shared/svg/EditorUncheckSvg';
-import { CheckboxCellController } from '$app/stores/effects/database/cell/controller_builder';
export const EditCheckboxCell = ({ data, onToggle }: { data: 'Yes' | 'No' | undefined; onToggle: () => void }) => {
// const toggleValue = async () => {
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Options/MultiSelectTypeOptions.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Options/MultiSelectTypeOptions.tsx
index 9812e92523..f7a87e5507 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Options/MultiSelectTypeOptions.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/Options/MultiSelectTypeOptions.tsx
@@ -4,7 +4,6 @@ import { CellOption } from '$app/components/_shared/EditRow/Options/CellOption';
import { SelectOptionPB } from '@/services/backend';
import { useAppSelector } from '$app/stores/store';
import { KeyboardEventHandler, useEffect, useRef, useState } from 'react';
-import { useTranslation } from 'react-i18next';
import { SelectOptionCellBackendService } from '$app/stores/effects/database/cell/select_option_bd_svc';
export const MultiSelectTypeOptions = ({
@@ -16,7 +15,6 @@ export const MultiSelectTypeOptions = ({
}) => {
const inputRef = useRef<HTMLInputElement>(null);
const inputContainerRef = useRef<HTMLDivElement>(null);
- const { t } = useTranslation();
const fieldsStore = useAppSelector((state) => state.database.fields);
const [value, setValue] = useState('');
const [showInput, setShowInput] = useState(false);
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/LanguageSelectPopup.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/LanguageSelectPopup.tsx
index 62968e179a..84d50e3451 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/LanguageSelectPopup.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/LanguageSelectPopup.tsx
@@ -37,6 +37,7 @@ export const LanguageSelectPopup = ({ onClose }: { onClose: () => void }) => {
title: item.title,
icon: <></>,
}));
+
return (
<PopupSelect
items={items}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/database-hooks/loadField.ts b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/database-hooks/loadField.ts
index e21936894d..b3226bfe8f 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/database-hooks/loadField.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/database-hooks/loadField.ts
@@ -1,9 +1,8 @@
import { TypeOptionController } from '$app/stores/effects/database/field/type_option/type_option_controller';
import { Some } from 'ts-results';
import { IDatabaseField, ISelectOption } from '$app_reducers/database/slice';
-import { ChecklistTypeOptionPB, FieldType, MultiSelectTypeOptionPB, SingleSelectTypeOptionPB } from '@/services/backend';
+import { FieldType, MultiSelectTypeOptionPB, SingleSelectTypeOptionPB } from '@/services/backend';
import {
- makeChecklistTypeOptionContext,
makeDateTypeOptionContext,
makeMultiSelectTypeOptionContext,
makeNumberTypeOptionContext,
@@ -32,9 +31,11 @@ export default async function (viewId: string, fieldInfo: FieldInfo, dispatch?:
if (dispatch) {
dispatch(boardActions.setGroupingFieldId({ fieldId: field.id }));
}
+
groupingFieldSelected = true;
}
}
+
if (field.field_type === FieldType.MultiSelect) {
typeOption = (await makeMultiSelectTypeOptionContext(typeOptionController).getTypeOption()).unwrap();
}
@@ -63,6 +64,7 @@ export default async function (viewId: string, fieldInfo: FieldInfo, dispatch?:
case FieldType.Number: {
const typeOption = (await makeNumberTypeOptionContext(typeOptionController).getTypeOption()).unwrap();
+
return {
fieldId: field.id,
title: field.name,
@@ -77,6 +79,7 @@ export default async function (viewId: string, fieldInfo: FieldInfo, dispatch?:
case FieldType.DateTime: {
const typeOption = (await makeDateTypeOptionContext(typeOptionController).getTypeOption()).unwrap();
+
return {
fieldId: field.id,
title: field.name,
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.ts
index a67525c206..91a516ebeb 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
@@ -10,6 +10,7 @@ import { databaseActions, ISelectOptionType } from '$app_reducers/database/slice
export const useCell = (cellIdentifier: CellIdentifier, cellCache: CellCache, fieldController: FieldController) => {
const [data, setData] = useState<DateCellDataPB | URLCellDataPB | SelectOptionCellDataPB | string | undefined>();
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
const [cellController, setCellController] = useState<CellController<any, any>>();
const databaseStore = useAppSelector((state) => state.database);
const dispatch = useAppDispatch();
@@ -18,12 +19,14 @@ export const useCell = (cellIdentifier: CellIdentifier, cellCache: CellCache, fi
if (!cellIdentifier || !cellCache || !fieldController) return;
const builder = new CellControllerBuilder(cellIdentifier, cellCache, fieldController);
const c = builder.build();
+
setCellController(c);
c.subscribeChanged({
onCellChanged: (cellData) => {
if (cellData.some) {
const value = cellData.val;
+
setData(value);
// update redux store for database field if there are new select options
@@ -59,6 +62,7 @@ export const useCell = (cellIdentifier: CellIdentifier, cellCache: CellCache, fi
void (async () => {
try {
const cellData = await c.getCellData();
+
if (cellData.some) {
setData(cellData.unwrap());
}
@@ -70,6 +74,7 @@ export const useCell = (cellIdentifier: CellIdentifier, cellCache: CellCache, fi
return () => {
void c.dispose();
};
+ // eslint-disable-next-line react-hooks/exhaustive-deps
}, [cellIdentifier, cellCache, fieldController]);
return {
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/database-hooks/useDatabase.ts b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/database-hooks/useDatabase.ts
index 77fb4490b5..70a10d19c7 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/database-hooks/useDatabase.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/database-hooks/useDatabase.ts
@@ -186,6 +186,7 @@ export const useDatabase = (viewId: string, type?: ViewLayoutPB) => {
return () => {
void controller?.dispose();
};
+ // eslint-disable-next-line react-hooks/exhaustive-deps
}, [controller, queue]);
const onNewRowClick = async (index: number) => {
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/database-hooks/useRow.ts b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/database-hooks/useRow.ts
index eb1182b844..2d08a5b399 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/database-hooks/useRow.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/database-hooks/useRow.ts
@@ -18,6 +18,7 @@ export const useRow = (viewId: string, databaseController: DatabaseController, r
const rowCache = databaseController.databaseViewCache.getRowCache();
const fieldController = databaseController.fieldController;
const c = new RowController(rowInfo, fieldController, rowCache);
+
setRowController(c);
return () => {
@@ -46,6 +47,7 @@ export const useRow = (viewId: string, databaseController: DatabaseController, r
const onNewColumnClick = async (initialFieldType: FieldType = FieldType.RichText, name?: string) => {
if (!databaseController) return;
const controller = new TypeOptionController(viewId, None, initialFieldType);
+
await controller.initialize();
if (name) {
await controller.setFieldName(name);
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/useOutsideClick.ts b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/useOutsideClick.ts
index 6cfe5b4727..00a6876d25 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/_shared/useOutsideClick.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/_shared/useOutsideClick.ts
@@ -1,5 +1,6 @@
import { useEffect } from 'react';
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
export default function useOutsideClick(ref: any, handler: (e: MouseEvent | TouchEvent) => void) {
useEffect(
() => {
@@ -8,8 +9,10 @@ export default function useOutsideClick(ref: any, handler: (e: MouseEvent | Touc
if (!ref?.current || ref.current.contains(event.target)) {
return;
}
+
handler(event);
};
+
document.addEventListener('mousedown', listener);
document.addEventListener('touchstart', listener);
return () => {
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/auth/Login/Login.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/components/auth/Login/Login.hooks.ts
index 7d07a339b2..15d607e812 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/auth/Login/Login.hooks.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/auth/Login/Login.hooks.ts
@@ -1,6 +1,6 @@
import { useState } from 'react';
-import { currentUserActions } from '../../../stores/reducers/current-user/slice';
-import { useAppDispatch, useAppSelector } from '../../../stores/store';
+import { currentUserActions } from '$app_reducers/current-user/slice';
+import { useAppDispatch } from '$app/stores/store';
import { useNavigate } from 'react-router-dom';
import { useAuth } from '../auth.hooks';
import { nanoid } from 'nanoid';
@@ -10,7 +10,6 @@ export const useLogin = () => {
const [password, setPassword] = useState('');
const [showPassword, setShowPassword] = useState(false);
const appDispatch = useAppDispatch();
- const currentUser = useAppSelector((state) => state.currentUser);
const navigate = useNavigate();
const { login, register } = useAuth();
const [authError, setAuthError] = useState(false);
@@ -36,6 +35,7 @@ export const useLogin = () => {
const fakePassword = 'AppFlowy123@';
const userProfile = await register(fakeEmail, fakePassword, 'Me');
const { id, name, token } = userProfile;
+
appDispatch(
currentUserActions.updateUser({
id: id,
@@ -55,6 +55,7 @@ export const useLogin = () => {
try {
const userProfile = await login(email, password);
const { id, name, token } = userProfile;
+
appDispatch(
currentUserActions.updateUser({
id: id,
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/auth/ProtectedRoutes.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/auth/ProtectedRoutes.tsx
index f67033f83d..3f55079677 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/auth/ProtectedRoutes.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/auth/ProtectedRoutes.tsx
@@ -21,6 +21,7 @@ export const ProtectedRoutes = () => {
throw new Error(result.val.msg);
}
});
+ // eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
if (isLoading) {
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/auth/SignUp/SignUp.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/components/auth/SignUp/SignUp.hooks.ts
index 3fcf26378b..c97b73117b 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/auth/SignUp/SignUp.hooks.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/auth/SignUp/SignUp.hooks.ts
@@ -1,6 +1,6 @@
import { useState } from 'react';
-import { useAppDispatch, useAppSelector } from '../../../stores/store';
-import { currentUserActions } from '../../../stores/reducers/current-user/slice';
+import { useAppDispatch } from '$app/stores/store';
+import { currentUserActions } from '$app_reducers/current-user/slice';
import { useNavigate } from 'react-router-dom';
import { useAuth } from '../auth.hooks';
@@ -12,7 +12,6 @@ export const useSignUp = () => {
const [showPassword, setShowPassword] = useState(false);
const [showConfirmPassword, setShowConfirmPassword] = useState(false);
const appDispatch = useAppDispatch();
- const currentUser = useAppSelector((state) => state.currentUser);
const navigate = useNavigate();
const { register } = useAuth();
const [authError, setAuthError] = useState(false);
@@ -49,6 +48,7 @@ export const useSignUp = () => {
try {
const result = await register(email, password, displayName);
const { id, token } = result;
+
appDispatch(
currentUserActions.updateUser({
id,
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/board/BoardCheckboxCell.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/board/BoardCheckboxCell.tsx
index 6df65344d3..3d591c880d 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/board/BoardCheckboxCell.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/board/BoardCheckboxCell.tsx
@@ -15,6 +15,7 @@ export const BoardCheckboxCell = ({
fieldController: FieldController;
}) => {
const { data } = useCell(cellIdentifier, cellCache, fieldController);
+
return (
<i className={'h-5 w-5'}>
{data === 'Yes' ? <EditorCheckSvg></EditorCheckSvg> : <EditorUncheckSvg></EditorUncheckSvg>}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/board/BoardDateCell.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/board/BoardDateCell.tsx
index 29a7c0629c..d924c9a54d 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/board/BoardDateCell.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/board/BoardDateCell.tsx
@@ -14,5 +14,6 @@ export const BoardDateCell = ({
fieldController: FieldController;
}) => {
const { data } = useCell(cellIdentifier, cellCache, fieldController);
+
return <div>{(data as DateCellDataPB | undefined)?.date ?? ''}&nbsp;</div>;
};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/board/BoardSettingsPopup.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/board/BoardSettingsPopup.tsx
index e55101b40c..e1eec1e876 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/board/BoardSettingsPopup.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/board/BoardSettingsPopup.tsx
@@ -37,6 +37,7 @@ export const BoardSettingsPopup = ({
onClick: onGroupClick,
},
]);
+ // eslint-disable-next-line react-hooks/exhaustive-deps
}, [t]);
return (
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/Database.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/Database.hooks.ts
new file mode 100644
index 0000000000..1c8f6724ed
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/Database.hooks.ts
@@ -0,0 +1,84 @@
+import { RefObject, createContext, createRef, useContext, useCallback, useMemo, useEffect } from 'react';
+import { useSearchParams } from 'react-router-dom';
+import { proxy, useSnapshot } from 'valtio';
+import { DatabaseLayoutPB, DatabaseNotification } from '@/services/backend';
+import { subscribeNotifications } from '$app/hooks';
+import {
+ Database,
+ databaseService,
+ fieldService,
+ rowListeners,
+ sortListeners,
+} from './application';
+
+const VerticalScrollElementRefContext = createContext<RefObject<Element>>(createRef());
+
+export const VerticalScrollElementProvider = VerticalScrollElementRefContext.Provider;
+export const useVerticalScrollElement = () => useContext(VerticalScrollElementRefContext);
+
+export function useSelectDatabaseView() {
+ const key = 'v';
+ const [searchParams, setSearchParams] = useSearchParams();
+
+ const selectedViewId = useMemo(() => searchParams.get(key), [searchParams]);
+
+ const selectViewId = useCallback((value: string) => {
+ setSearchParams({ [key]: value });
+ }, [setSearchParams]);
+
+ return [selectedViewId, selectViewId] as const;
+}
+
+const DatabaseContext = createContext<Database>({
+ id: '',
+ isLinked: false,
+ layoutType: DatabaseLayoutPB.Grid,
+ fields: [],
+ rowMetas: [],
+ filters: [],
+ sorts: [],
+ groupSettings: [],
+ groups: [],
+});
+
+export const DatabaseProvider = DatabaseContext.Provider;
+
+export const useDatabase = () => useSnapshot(useContext(DatabaseContext));
+
+export const useConnectDatabase = (viewId: string) => {
+ const database = useMemo(() => {
+ const proxyDatabase = proxy<Database>({
+ id: '',
+ isLinked: false,
+ layoutType: DatabaseLayoutPB.Grid,
+ fields: [],
+ rowMetas: [],
+ filters: [],
+ sorts: [],
+ groupSettings: [],
+ groups: [],
+ });
+
+ void databaseService.openDatabase(viewId).then(value => Object.assign(proxyDatabase, value));
+
+ return proxyDatabase;
+ }, [viewId]);
+
+ useEffect(() => {
+ const unsubscribePromise = subscribeNotifications({
+ [DatabaseNotification.DidUpdateFields]: async () => {
+ database.fields = await fieldService.getFields(viewId);
+ },
+
+ [DatabaseNotification.DidUpdateViewRows]: changeset => rowListeners.didUpdateViewRows(database, changeset),
+ [DatabaseNotification.DidReorderRows]: changeset => rowListeners.didReorderRows(database, changeset),
+ [DatabaseNotification.DidReorderSingleRow]: changeset => rowListeners.didReorderSingleRow(database, changeset),
+
+ [DatabaseNotification.DidUpdateSort]: changeset => sortListeners.didUpdateSort(database, changeset),
+ }, { id: viewId });
+
+ return () => void unsubscribePromise.then(unsubscribe => unsubscribe());
+ }, [viewId, database]);
+
+ return database;
+};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/Database.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/Database.tsx
index a770d8ad2d..2e57c7fe9d 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/Database.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/Database.tsx
@@ -1,41 +1,42 @@
-import { useEffect, useRef, useState } from 'react';
-import { proxy } from 'valtio';
-import { subscribeKey } from 'valtio/utils';
-import { DatabaseLayoutPB } from '@/services/backend';
-import { DndContext, DndContextDescriptor } from './_shared';
-import { VerticalScrollElementRefContext, DatabaseContext } from './database.context';
-import { useViewId, useConnectDatabase } from './database.hooks';
-import { DatabaseHeader } from './DatabaseHeader';
-import { Grid } from './grid';
+import { useEffect, useMemo, useState } from 'react';
+import { useViewId } from '$app/hooks';
+import { DatabaseView as DatabaseViewType, databaseViewService } from './application';
+import { DatabaseTabBar } from './components';
+import { useSelectDatabaseView } from './Database.hooks';
+import { DatabaseLoader } from './DatabaseLoader';
+import { DatabaseView } from './DatabaseView';
+import { DatabaseSettings } from './components/database_settings';
export const Database = () => {
const viewId = useViewId();
- const verticalScrollElementRef = useRef<HTMLDivElement>(null);
- const database = useConnectDatabase(viewId);
- const [ layoutType, setLayoutType ] = useState(database.layoutType);
- const dndContext = useRef(proxy<DndContextDescriptor>({
- dragging: null,
- }));
+ const [views, setViews] = useState<DatabaseViewType[]>([]);
+ const [selectedViewId, selectViewId] = useSelectDatabaseView();
+ const activeView = useMemo(() => views?.find((view) => view.id === selectedViewId), [views, selectedViewId]);
useEffect(() => {
- return subscribeKey(database, 'layoutType', (value) => {
- setLayoutType(value);
+ setViews([]);
+ void databaseViewService.getDatabaseViews(viewId).then((value) => {
+ setViews(value);
});
- }, [database]);
+ }, [viewId]);
- return (
- <div
- ref={verticalScrollElementRef}
- className="h-full overflow-y-auto"
- >
- <DatabaseHeader />
- <VerticalScrollElementRefContext.Provider value={verticalScrollElementRef}>
- <DndContext.Provider value={dndContext.current}>
- <DatabaseContext.Provider value={database}>
- {layoutType === DatabaseLayoutPB.Grid ? <Grid /> : null}
- </DatabaseContext.Provider>
- </DndContext.Provider >
- </VerticalScrollElementRefContext.Provider>
- </div>
- );
+ useEffect(() => {
+ if (!activeView) {
+ const firstViewId = views?.[0]?.id;
+
+ if (firstViewId) {
+ selectViewId(firstViewId);
+ }
+ }
+ }, [views, activeView, selectViewId]);
+
+ return activeView ? (
+ <DatabaseLoader viewId={viewId}>
+ <div className='px-16'>
+ <DatabaseTabBar views={views} />
+ <DatabaseSettings />
+ </div>
+ <DatabaseView />
+ </DatabaseLoader>
+ ) : null;
};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/DatabaseLoader.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/DatabaseLoader.tsx
new file mode 100644
index 0000000000..7ccfeef296
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/DatabaseLoader.tsx
@@ -0,0 +1,22 @@
+import { FC, PropsWithChildren } from 'react';
+import { ViewIdProvider } from '$app/hooks';
+import { DatabaseProvider, useConnectDatabase } from './Database.hooks';
+
+export interface DatabaseLoaderProps {
+ viewId: string
+}
+
+export const DatabaseLoader: FC<PropsWithChildren<DatabaseLoaderProps>> = ({
+ viewId,
+ children,
+}) => {
+ const database = useConnectDatabase(viewId);
+
+ return (
+ <DatabaseProvider value={database}>
+ <ViewIdProvider value={viewId}>
+ {children}
+ </ViewIdProvider>
+ </DatabaseProvider>
+ );
+};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/DatabaseHeader.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/DatabaseTitle.tsx
similarity index 93%
rename from frontend/appflowy_tauri/src/appflowy_app/components/database/DatabaseHeader.tsx
rename to frontend/appflowy_tauri/src/appflowy_app/components/database/DatabaseTitle.tsx
index 2c1a5ca0e3..57689caf38 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/DatabaseHeader.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/DatabaseTitle.tsx
@@ -1,9 +1,9 @@
import { FormEventHandler, useCallback, useEffect, useMemo, useState } from 'react';
import { t } from 'i18next';
import { PageController } from '$app/stores/effects/workspace/page/page_controller';
-import { useViewId } from './database.hooks';
+import { useViewId } from '$app/hooks';
-export const DatabaseHeader = () => {
+export const DatabaseTitle = () => {
const viewId = useViewId();
const [ title, setTitle ] = useState('');
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/DatabaseView.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/DatabaseView.tsx
new file mode 100644
index 0000000000..f2b0966e9b
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/DatabaseView.tsx
@@ -0,0 +1,19 @@
+import { DatabaseLayoutPB } from '@/services/backend';
+import { FC } from 'react';
+import { useDatabase } from './Database.hooks';
+import { Grid } from './grid';
+import { Board } from './board';
+import { Calendar } from './calendar';
+
+const ViewMap: Record<DatabaseLayoutPB, FC | null> = {
+ [DatabaseLayoutPB.Grid]: Grid,
+ [DatabaseLayoutPB.Board]: Board,
+ [DatabaseLayoutPB.Calendar]: Calendar,
+};
+
+export const DatabaseView: FC = () => {
+ const { layoutType } = useDatabase();
+ const View = ViewMap[layoutType];
+
+ return View && <View />;
+};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/_shared/dnd/drag.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/_shared/dnd/drag.hooks.ts
index da5c840597..4df6623d04 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/_shared/dnd/drag.hooks.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/_shared/dnd/drag.hooks.ts
@@ -1,17 +1,11 @@
-import {
- DragEventHandler,
- useCallback,
- useContext,
- useMemo,
- useRef,
- useState,
-} from 'react';
+import { DragEventHandler, useCallback, useContext, useMemo, useRef, useState } from 'react';
import { DndContext } from './dnd.context';
import { autoScrollOnEdge, EdgeGap, getScrollParent, ScrollDirection } from './utils';
export interface UseDraggableOptions {
type: string;
effectAllowed?: DataTransfer['effectAllowed'];
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
data?: Record<string, any>;
disabled?: boolean;
scrollOnEdge?: {
@@ -34,7 +28,7 @@ export const useDraggable = ({
const typeRef = useRef(type);
const dataRef = useRef(data);
const previewRef = useRef<Element | null>(null);
- const [ isDragging, setIsDragging ] = useState(false);
+ const [isDragging, setIsDragging] = useState(false);
typeRef.current = type;
dataRef.current = data;
@@ -53,49 +47,55 @@ export const useDraggable = ({
};
}, [disabled]);
- const onDragStart = useCallback<DragEventHandler>((event) => {
- setIsDragging(true);
- context.dragging = {
- type: typeRef.current,
- data: dataRef.current ?? {},
- };
+ const onDragStart = useCallback<DragEventHandler>(
+ (event) => {
+ setIsDragging(true);
+ context.dragging = {
+ type: typeRef.current,
+ data: dataRef.current ?? {},
+ };
- const { dataTransfer } = event;
- const previewNode = previewRef.current;
+ const { dataTransfer } = event;
+ const previewNode = previewRef.current;
- dataTransfer.effectAllowed = effectAllowed;
+ dataTransfer.effectAllowed = effectAllowed;
- if (previewNode) {
- const { clientX, clientY } = event;
- const rect = previewNode.getBoundingClientRect();
+ if (previewNode) {
+ const { clientX, clientY } = event;
+ const rect = previewNode.getBoundingClientRect();
- dataTransfer.setDragImage(previewNode, clientX - rect.x, clientY - rect.y);
- }
+ dataTransfer.setDragImage(previewNode, clientX - rect.x, clientY - rect.y);
+ }
- if (scrollDirection === undefined) {
- return;
- }
+ if (scrollDirection === undefined) {
+ return;
+ }
- const scrollParent: HTMLElement | null = getScrollParent(event.target as HTMLElement, scrollDirection);
+ const scrollParent: HTMLElement | null = getScrollParent(event.target as HTMLElement, scrollDirection);
- if (scrollParent) {
- autoScrollOnEdge({
- element: scrollParent,
- direction: scrollDirection,
- edgeGap,
- });
- }
- }, [ context, effectAllowed, scrollDirection, edgeGap ]);
+ if (scrollParent) {
+ autoScrollOnEdge({
+ element: scrollParent,
+ direction: scrollDirection,
+ edgeGap,
+ });
+ }
+ },
+ [context, effectAllowed, scrollDirection, edgeGap]
+ );
const onDragEnd = useCallback<DragEventHandler>(() => {
setIsDragging(false);
context.dragging = null;
- }, [ context ]);
-
- const listeners = useMemo(() => ({
- onDragStart,
- onDragEnd,
- }), [ onDragStart, onDragEnd]);
+ }, [context]);
+
+ const listeners = useMemo(
+ () => ({
+ onDragStart,
+ onDragEnd,
+ }),
+ [onDragStart, onDragEnd]
+ );
return {
isDragging,
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/_shared/dnd/utils.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/_shared/dnd/utils.ts
index 562af3cbef..8c3f8a5783 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/_shared/dnd/utils.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/_shared/dnd/utils.ts
@@ -162,7 +162,6 @@ export const autoScrollOnEdge = ({
};
const cleanup = () => {
- console.log('document drag end');
keepScroll.cancel();
element.removeEventListener('dragover', onDragOver);
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/cell/cell_service.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/cell/cell_service.ts
new file mode 100644
index 0000000000..876610c7ce
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/cell/cell_service.ts
@@ -0,0 +1,120 @@
+import {
+ CellIdPB,
+ CellChangesetPB,
+ SelectOptionCellChangesetPB,
+ ChecklistCellDataChangesetPB,
+ DateChangesetPB,
+ FieldType,
+} from '@/services/backend';
+import {
+ DatabaseEventGetCell,
+ DatabaseEventUpdateCell,
+ DatabaseEventUpdateSelectOptionCell,
+ DatabaseEventUpdateChecklistCell,
+ DatabaseEventUpdateDateCell,
+} from '@/services/backend/events/flowy-database2';
+import { SelectOption } from '../field';
+import { Cell, pbToCell } from './cell_types';
+
+export async function getCell(viewId: string, rowId: string, fieldId: string, fieldType?: FieldType): Promise<Cell> {
+ const payload = CellIdPB.fromObject({
+ view_id: viewId,
+ row_id: rowId,
+ field_id: fieldId,
+ });
+
+ const result = await DatabaseEventGetCell(payload);
+
+ return result.map(value => pbToCell(value, fieldType)).unwrap();
+}
+
+export async function updateCell(viewId: string, rowId: string, fieldId: string, changeset: string): Promise<void> {
+ const payload = CellChangesetPB.fromObject({
+ view_id: viewId,
+ row_id: rowId,
+ field_id: fieldId,
+ cell_changeset: changeset,
+ });
+
+ const result = await DatabaseEventUpdateCell(payload);
+
+ return result.unwrap();
+}
+
+export async function updateSelectCell(
+ viewId: string,
+ rowId: string,
+ fieldId: string,
+ data: {
+ insertOptionIds?: string[];
+ deleteOptionIds?: string[];
+ },
+): Promise<void> {
+ const payload = SelectOptionCellChangesetPB.fromObject({
+ cell_identifier: {
+ view_id: viewId,
+ row_id: rowId,
+ field_id: fieldId,
+ },
+ insert_option_ids: data.insertOptionIds,
+ delete_option_ids: data.deleteOptionIds,
+ });
+
+ const result = await DatabaseEventUpdateSelectOptionCell(payload);
+
+ return result.unwrap();
+}
+
+export async function updateChecklistCell(
+ viewId: string,
+ rowId: string,
+ fieldId: string,
+ data: {
+ insertOptions?: string[];
+ selectedOptionIds?: string[];
+ deleteOptionIds?: string[];
+ updateOptions?: Partial<SelectOption>[];
+ },
+): Promise<void> {
+ const payload = ChecklistCellDataChangesetPB.fromObject({
+ view_id: viewId,
+ row_id: rowId,
+ field_id: fieldId,
+ insert_options: data.insertOptions,
+ selected_option_ids: data.selectedOptionIds,
+ delete_option_ids: data.deleteOptionIds,
+ update_options: data.updateOptions,
+ });
+
+ const result = await DatabaseEventUpdateChecklistCell(payload);
+
+ return result.unwrap();
+}
+
+export async function updateDateCell(
+ viewId: string,
+ rowId: string,
+ fieldId: string,
+ data: {
+ date?: number;
+ time?: string;
+ includeTime?: boolean;
+ clearFlag?: boolean;
+ },
+): Promise<void> {
+ const payload = DateChangesetPB.fromObject({
+ cell_id: {
+ view_id: viewId,
+ row_id: rowId,
+ field_id: fieldId,
+ },
+ date: data.date,
+ time: data.time,
+ include_time: data.includeTime,
+ clear_flag: data.clearFlag,
+ });
+
+ const result = await DatabaseEventUpdateDateCell(payload);
+
+ return result.unwrap();
+}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/cell/cell_types.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/cell/cell_types.ts
new file mode 100644
index 0000000000..5dfeda618c
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/cell/cell_types.ts
@@ -0,0 +1,128 @@
+import {
+ CellPB,
+ ChecklistCellDataPB,
+ DateCellDataPB,
+ FieldType,
+ SelectOptionCellDataPB,
+ URLCellDataPB,
+} from '@/services/backend';
+
+export interface Cell {
+ rowId: string;
+ fieldId: string;
+ fieldType: FieldType;
+ data: unknown;
+}
+
+export interface TextCell extends Cell {
+ fieldType: FieldType.RichText;
+ data: string;
+}
+
+export interface NumberCell extends Cell {
+ fieldType: FieldType.Number;
+ data: string;
+}
+
+export interface CheckboxCell extends Cell {
+ fieldType: FieldType.Checkbox;
+ data: 'Yes' | 'No';
+}
+
+export interface UrlCell extends Cell {
+ fieldType: FieldType.URL;
+ data: UrlCellData;
+}
+
+export interface UrlCellData {
+ url: string;
+ content?: string;
+}
+
+export interface SelectCell extends Cell {
+ fieldType: FieldType.SingleSelect | FieldType.MultiSelect;
+ data: SelectCellData;
+}
+
+export interface SelectCellData {
+ selectedOptionIds?: string[];
+}
+
+export interface DateTimeCell extends Cell {
+ fieldType: FieldType.DateTime;
+ data: DateTimeCellData;
+}
+
+export interface DateTimeCellData {
+ date?: string;
+ time?: string;
+ timestamp?: number;
+ includeTime?: boolean;
+}
+
+export interface ChecklistCell extends Cell {
+ fieldType: FieldType.Checklist;
+ data: ChecklistCellData;
+}
+
+export interface ChecklistCellData {
+ /**
+ * link to [SelectOption's id property]{@link SelectOption#id}.
+ */
+ selectedOptions?: string[];
+ percentage?: number;
+}
+
+export type UndeterminedCell = TextCell | NumberCell | DateTimeCell | SelectCell | CheckboxCell | UrlCell | ChecklistCell;
+
+const pbToDateCellData = (pb: DateCellDataPB): DateTimeCellData => ({
+ date: pb.date,
+ time: pb.time,
+ timestamp: pb.timestamp,
+ includeTime: pb.include_time,
+});
+
+export const pbToSelectCellData = (pb: SelectOptionCellDataPB): SelectCellData => {
+ return {
+ selectedOptionIds: pb.select_options.map(option => option.id),
+ };
+};
+
+const pbToURLCellData = (pb: URLCellDataPB): UrlCellData => ({
+ url: pb.url,
+ content: pb.content,
+});
+
+export const pbToChecklistCellData = (pb: ChecklistCellDataPB): ChecklistCellData => ({
+ selectedOptions: pb.selected_options.map(({ id }) => id),
+ percentage: pb.percentage,
+});
+
+function bytesToCellData(bytes: Uint8Array, fieldType: FieldType) {
+ switch (fieldType) {
+ case FieldType.RichText:
+ case FieldType.Number:
+ case FieldType.Checkbox:
+ return new TextDecoder().decode(bytes);
+ case FieldType.DateTime:
+ case FieldType.LastEditedTime:
+ case FieldType.CreatedTime:
+ return pbToDateCellData(DateCellDataPB.deserialize(bytes));
+ case FieldType.SingleSelect:
+ case FieldType.MultiSelect:
+ return pbToSelectCellData(SelectOptionCellDataPB.deserialize(bytes));
+ case FieldType.URL:
+ return pbToURLCellData(URLCellDataPB.deserialize(bytes));
+ case FieldType.Checklist:
+ return pbToChecklistCellData(ChecklistCellDataPB.deserialize(bytes));
+ }
+}
+
+export const pbToCell = (pb: CellPB, fieldType: FieldType = pb.field_type): Cell => {
+ return {
+ rowId: pb.row_id,
+ fieldId: pb.field_id,
+ fieldType: fieldType,
+ data: bytesToCellData(pb.data, fieldType),
+ };
+};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/cell/index.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/cell/index.ts
new file mode 100644
index 0000000000..f15008d47c
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/cell/index.ts
@@ -0,0 +1,2 @@
+export * from './cell_types';
+export * as cellService from './cell_service';
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/database/database_service.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/database/database_service.ts
new file mode 100644
index 0000000000..ca61a966bd
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/database/database_service.ts
@@ -0,0 +1,87 @@
+import { DatabaseViewIdPB } from '@/services/backend';
+import {
+ DatabaseEventGetDatabase,
+ DatabaseEventGetDatabaseId,
+ DatabaseEventGetDatabaseSetting,
+} from '@/services/backend/events/flowy-database2';
+import { fieldService } from '../field';
+import { pbToFilter } from '../filter';
+import { groupService, pbToGroupSetting } from '../group';
+import { pbToRowMeta } from '../row';
+import { pbToSort } from '../sort';
+import { Database } from './database_types';
+
+export async function getDatabaseId(viewId: string): Promise<string> {
+ const payload = DatabaseViewIdPB.fromObject({ value: viewId });
+
+ const result = await DatabaseEventGetDatabaseId(payload);
+
+ return result.map(value => value.value).unwrap();
+}
+
+
+export async function getDatabase(viewId: string) {
+ const payload = DatabaseViewIdPB.fromObject({
+ value: viewId,
+ });
+
+ const result = await DatabaseEventGetDatabase(payload);
+
+ return result.map(value => {
+ return {
+ id: value.id,
+ isLinked: value.is_linked,
+ layoutType: value.layout_type,
+ fieldIds: value.fields.map(field => field.field_id),
+ rowMetas: value.rows.map(pbToRowMeta),
+ };
+ }).unwrap();
+}
+
+export async function getDatabaseSetting(viewId: string) {
+ const payload = DatabaseViewIdPB.fromObject({
+ value: viewId,
+ });
+
+ const result = await DatabaseEventGetDatabaseSetting(payload);
+
+ return result.map(value => {
+ return {
+ filters: value.filters.items.map(pbToFilter),
+ sorts: value.sorts.items.map(pbToSort),
+ groupSettings: value.group_settings.items.map(pbToGroupSetting),
+ };
+ }).unwrap();
+}
+
+export async function openDatabase(viewId: string): Promise<Database> {
+ const {
+ id,
+ isLinked,
+ layoutType,
+ fieldIds,
+ rowMetas,
+ } = await getDatabase(viewId);
+
+ const {
+ filters,
+ sorts,
+ groupSettings,
+ } = await getDatabaseSetting(viewId);
+
+ const fields = await fieldService.getFields(viewId, fieldIds);
+
+ const groups = await groupService.getGroups(viewId);
+
+ return {
+ id,
+ isLinked,
+ layoutType,
+ fields,
+ rowMetas,
+ filters,
+ sorts,
+ groups,
+ groupSettings,
+ };
+}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/database/database_types.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/database/database_types.ts
new file mode 100644
index 0000000000..2265421687
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/database/database_types.ts
@@ -0,0 +1,18 @@
+import { DatabaseLayoutPB } from '@/services/backend';
+import { Field } from '../field';
+import { Filter } from '../filter';
+import { GroupSetting, Group } from '../group';
+import { RowMeta } from '../row';
+import { Sort } from '../sort';
+
+export interface Database {
+ id: string;
+ isLinked: boolean;
+ layoutType: DatabaseLayoutPB,
+ fields: Field[];
+ rowMetas: RowMeta[];
+ filters: Filter[];
+ sorts: Sort[];
+ groupSettings: GroupSetting[];
+ groups: Group[];
+}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/database/index.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/database/index.ts
new file mode 100644
index 0000000000..e656d98287
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/database/index.ts
@@ -0,0 +1,2 @@
+export * from './database_types';
+export * as databaseService from './database_service';
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/database_view/database_view_service.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/database_view/database_view_service.ts
new file mode 100644
index 0000000000..8827267baf
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/database_view/database_view_service.ts
@@ -0,0 +1,70 @@
+import {
+ CreateViewPayloadPB,
+ RepeatedViewIdPB,
+ UpdateViewPayloadPB,
+ ViewIdPB,
+ ViewLayoutPB,
+} from '@/services/backend';
+import {
+ FolderEventCreateView,
+ FolderEventDeleteView,
+ FolderEventReadView,
+ FolderEventUpdateView,
+} from '@/services/backend/events/flowy-folder2';
+import { databaseService } from '../database';
+import { DatabaseView, DatabaseViewLayout, pbToDatabaseView } from './database_view_types';
+
+export async function getDatabaseViews(viewId: string): Promise<DatabaseView[]> {
+ const payload = ViewIdPB.fromObject({ value: viewId });
+
+ const result = await FolderEventReadView(payload);
+
+ return result.map(value => {
+ return [
+ pbToDatabaseView(value),
+ ...value.child_views.map(pbToDatabaseView),
+ ];
+ }).unwrap();
+}
+
+export async function createDatabaseView(
+ viewId: string,
+ layout: DatabaseViewLayout,
+ name: string,
+ databaseId?: string,
+): Promise<DatabaseView> {
+ const payload = CreateViewPayloadPB.fromObject({
+ parent_view_id: viewId,
+ name,
+ layout,
+ meta: {
+ 'database_id': databaseId || await databaseService.getDatabaseId(viewId),
+ },
+ });
+
+ const result = await FolderEventCreateView(payload);
+
+ return result.map(pbToDatabaseView).unwrap();
+}
+
+export async function updateView(viewId: string, view: { name?: string; layout?: ViewLayoutPB }): Promise<DatabaseView> {
+ const payload = UpdateViewPayloadPB.fromObject({
+ view_id: viewId,
+ name: view.name,
+ layout: view.layout,
+ });
+
+ const result = await FolderEventUpdateView(payload);
+
+ return result.map(pbToDatabaseView).unwrap();
+}
+
+export async function deleteView(viewId: string): Promise<void> {
+ const payload = RepeatedViewIdPB.fromObject({
+ items: [viewId],
+ });
+
+ const result = await FolderEventDeleteView(payload);
+
+ return result.unwrap();
+}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/database_view/database_view_types.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/database_view/database_view_types.ts
new file mode 100644
index 0000000000..2135a50f5a
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/database_view/database_view_types.ts
@@ -0,0 +1,25 @@
+import { CalendarLayoutPB, ViewLayoutPB, ViewPB } from '@/services/backend';
+
+export type DatabaseViewLayout = ViewLayoutPB.Grid | ViewLayoutPB.Board | ViewLayoutPB.Calendar;
+
+export interface DatabaseView {
+ id: string;
+ name: string;
+ layout: DatabaseViewLayout;
+}
+
+export interface CalendarLayoutSetting {
+ fieldId?: string;
+ layoutTy?: CalendarLayoutPB;
+ firstDayOfWeek?: number;
+ showWeekends?: boolean;
+ showWeekNumbers?: boolean;
+}
+
+export function pbToDatabaseView(viewPB: ViewPB): DatabaseView {
+ return {
+ id: viewPB.id,
+ layout: viewPB.layout as DatabaseViewLayout,
+ name: viewPB.name,
+ };
+}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/database_view/index.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/database_view/index.ts
new file mode 100644
index 0000000000..2ffada0e45
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/database_view/index.ts
@@ -0,0 +1,2 @@
+export * from './database_view_types';
+export * as databaseViewService from './database_view_service';
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/field/field_service.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/field/field_service.ts
new file mode 100644
index 0000000000..abb0c53f99
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/field/field_service.ts
@@ -0,0 +1,126 @@
+import {
+ CreateFieldPayloadPB,
+ DeleteFieldPayloadPB,
+ DuplicateFieldPayloadPB,
+ FieldChangesetPB,
+ FieldType,
+ GetFieldPayloadPB,
+ MoveFieldPayloadPB,
+ RepeatedFieldIdPB,
+ UpdateFieldTypePayloadPB,
+} from '@/services/backend';
+import {
+ DatabaseEventDuplicateField,
+ DatabaseEventUpdateField,
+ DatabaseEventUpdateFieldType,
+ DatabaseEventMoveField,
+ DatabaseEventGetFields,
+ DatabaseEventDeleteField,
+ DatabaseEventCreateTypeOption,
+} from '@/services/backend/events/flowy-database2';
+import { Field, pbToField } from './field_types';
+import { bytesToTypeOption, getTypeOption } from './type_option';
+
+export async function getFields(viewId: string, fieldIds?: string[]): Promise<Field[]> {
+ const payload = GetFieldPayloadPB.fromObject({
+ view_id: viewId,
+ field_ids: fieldIds ? RepeatedFieldIdPB.fromObject({
+ items: fieldIds.map(fieldId => ({ field_id: fieldId })),
+ }) : undefined,
+ });
+
+ const result = await DatabaseEventGetFields(payload);
+
+ const fields = result.map((value) => value.items.map(pbToField)).unwrap();
+
+ await Promise.all(fields.map(async field => {
+ const typeOption = await getTypeOption(viewId, field.id, field.type);
+
+ field.typeOption = typeOption;
+ }));
+
+ return fields;
+}
+
+export async function createField(viewId: string, fieldType?: FieldType, data?: Uint8Array): Promise<Field> {
+ const payload = CreateFieldPayloadPB.fromObject({
+ view_id: viewId,
+ field_type: fieldType,
+ type_option_data: data,
+ });
+
+ const result = await DatabaseEventCreateTypeOption(payload);
+
+ return result.map(value => {
+ const field = pbToField(value.field);
+
+ field.typeOption = bytesToTypeOption(value.type_option_data, field.type);
+
+ return field;
+ }).unwrap();
+}
+
+export async function duplicateField(viewId: string, fieldId: string): Promise<void> {
+ const payload = DuplicateFieldPayloadPB.fromObject({
+ view_id: viewId,
+ field_id: fieldId,
+ });
+
+ const result = await DatabaseEventDuplicateField(payload);
+
+ return result.unwrap();
+}
+
+export async function updateField(viewId: string, fieldId: string, data: {
+ name?: string;
+ desc?: string;
+ frozen?: boolean;
+ visibility?: boolean;
+ width?: number;
+}): Promise<void> {
+ const payload = FieldChangesetPB.fromObject({
+ view_id: viewId,
+ field_id: fieldId,
+ ...data,
+ });
+
+ const result = await DatabaseEventUpdateField(payload);
+
+ return result.unwrap();
+}
+
+export async function updateFieldType(viewId: string, fieldId: string, fieldType: FieldType): Promise<void> {
+ const payload = UpdateFieldTypePayloadPB.fromObject({
+ view_id: viewId,
+ field_id: fieldId,
+ field_type: fieldType,
+ });
+
+ const result = await DatabaseEventUpdateFieldType(payload);
+
+ return result.unwrap();
+}
+
+export async function moveField(viewId: string, fieldId: string, fromIndex: number, toIndex: number): Promise<void> {
+ const payload = MoveFieldPayloadPB.fromObject({
+ view_id: viewId,
+ field_id: fieldId,
+ from_index: fromIndex,
+ to_index: toIndex,
+ });
+
+ const result = await DatabaseEventMoveField(payload);
+
+ return result.unwrap();
+}
+
+export async function deleteField(viewId: string, fieldId: string): Promise<void> {
+ const payload = DeleteFieldPayloadPB.fromObject({
+ view_id: viewId,
+ field_id: fieldId,
+ });
+
+ const result = await DatabaseEventDeleteField(payload);
+
+ return result.unwrap();
+}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/field/field_types.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/field/field_types.ts
new file mode 100644
index 0000000000..c685e478be
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/field/field_types.ts
@@ -0,0 +1,41 @@
+import {
+ FieldPB,
+ FieldType,
+} from '@/services/backend';
+import { DateTimeTypeOption, NumberTypeOption, SelectTypeOption } from './type_option/type_option_types';
+
+export interface Field {
+ id: string;
+ name: string;
+ type: FieldType;
+ typeOption?: unknown;
+ visibility: boolean;
+ width: number;
+ isPrimary: boolean;
+}
+
+export interface NumberField extends Field {
+ type: FieldType.Number;
+ typeOption: NumberTypeOption;
+}
+
+export interface DateTimeField extends Field {
+ type: FieldType.DateTime;
+ typeOption: DateTimeTypeOption;
+}
+
+export interface SelectField extends Field {
+ type: FieldType.SingleSelect | FieldType.MultiSelect;
+ typeOption: SelectTypeOption;
+}
+
+export type UndeterminedField = NumberField | DateTimeField | SelectField | Field;
+
+export const pbToField = (pb: FieldPB): Field => ({
+ id: pb.id,
+ name: pb.name,
+ type: pb.field_type,
+ visibility: pb.visibility,
+ width: pb.width,
+ isPrimary: pb.is_primary,
+});
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/field/index.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/field/index.ts
new file mode 100644
index 0000000000..2cb812dc0d
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/field/index.ts
@@ -0,0 +1,4 @@
+export * from './select_option';
+export * from './type_option';
+export * from './field_types';
+export * as fieldService from './field_service';
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/field/select_option/index.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/field/select_option/index.ts
new file mode 100644
index 0000000000..f0b9e58852
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/field/select_option/index.ts
@@ -0,0 +1,2 @@
+export * from './select_option_types';
+export * as selectOptionService from './select_option_service';
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/field/select_option/select_option_service.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/field/select_option/select_option_service.ts
new file mode 100644
index 0000000000..0e32c94ffd
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/field/select_option/select_option_service.ts
@@ -0,0 +1,61 @@
+import {
+ CreateSelectOptionPayloadPB,
+ RepeatedSelectOptionPayload,
+} from '@/services/backend';
+import {
+ DatabaseEventCreateSelectOption,
+ DatabaseEventInsertOrUpdateSelectOption,
+ DatabaseEventDeleteSelectOption,
+} from '@/services/backend/events/flowy-database2';
+import { pbToSelectOption, SelectOption } from './select_option_types';
+
+export async function createSelectOption(viewId: string, fieldId: string, optionName: string): Promise<SelectOption> {
+ const payload = CreateSelectOptionPayloadPB.fromObject({
+ view_id: viewId,
+ field_id: fieldId,
+ option_name: optionName,
+ });
+
+ const result = await DatabaseEventCreateSelectOption(payload);
+
+ return result.map(pbToSelectOption).unwrap();
+}
+
+/**
+ * @param [rowId] If pass the rowId, the cell will select this option after insert or update.
+ */
+export async function insertOrUpdateSelectOption(
+ viewId: string,
+ fieldId: string,
+ items: Partial<SelectOption>[],
+ rowId?: string,
+): Promise<void> {
+ const payload = RepeatedSelectOptionPayload.fromObject({
+ view_id: viewId,
+ field_id: fieldId,
+ row_id: rowId,
+ items: items,
+ });
+
+ const result = await DatabaseEventInsertOrUpdateSelectOption(payload);
+
+ return result.unwrap();
+}
+
+export async function deleteSelectOption(
+ viewId: string,
+ fieldId: string,
+ items: Partial<SelectOption>[],
+ rowId?: string,
+): Promise<void> {
+ const payload = RepeatedSelectOptionPayload.fromObject({
+ view_id: viewId,
+ field_id: fieldId,
+ row_id: rowId,
+ items: items,
+ });
+
+ const result = await DatabaseEventDeleteSelectOption(payload);
+
+ return result.unwrap();
+}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/field/select_option/select_option_types.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/field/select_option/select_option_types.ts
new file mode 100644
index 0000000000..ec36639a7c
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/field/select_option/select_option_types.ts
@@ -0,0 +1,15 @@
+import { SelectOptionColorPB, SelectOptionPB } from '@/services/backend';
+
+export interface SelectOption {
+ id: string;
+ name: string;
+ color: SelectOptionColorPB;
+}
+
+export function pbToSelectOption(pb: SelectOptionPB): SelectOption {
+ return {
+ id: pb.id,
+ name: pb.name,
+ color: pb.color,
+ };
+}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/field/type_option/index.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/field/type_option/index.ts
new file mode 100644
index 0000000000..d0b9122d90
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/field/type_option/index.ts
@@ -0,0 +1,2 @@
+export * from './type_option_types';
+export * from './type_option_service';
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/field/type_option/type_option_service.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/field/type_option/type_option_service.ts
new file mode 100644
index 0000000000..046eeb5139
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/field/type_option/type_option_service.ts
@@ -0,0 +1,18 @@
+import {
+ FieldType,
+ TypeOptionPathPB,
+} from '@/services/backend';
+import { DatabaseEventGetTypeOption } from '@/services/backend/events/flowy-database2';
+import { bytesToTypeOption } from './type_option_types';
+
+export async function getTypeOption(viewId: string, fieldId: string, fieldType: FieldType) {
+ const payload = TypeOptionPathPB.fromObject({
+ view_id: viewId,
+ field_id: fieldId,
+ field_type: fieldType,
+ });
+
+ const result = await DatabaseEventGetTypeOption(payload);
+
+ return result.map(value => bytesToTypeOption(value.type_option_data, fieldType)).unwrap();
+}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/field/type_option/type_option_types.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/field/type_option/type_option_types.ts
new file mode 100644
index 0000000000..cc291bd1e2
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/field/type_option/type_option_types.ts
@@ -0,0 +1,68 @@
+import {
+ CheckboxTypeOptionPB,
+ DateFormatPB,
+ FieldType,
+ MultiSelectTypeOptionPB,
+ NumberFormatPB,
+ NumberTypeOptionPB,
+ RichTextTypeOptionPB,
+ SingleSelectTypeOptionPB,
+ TimeFormatPB,
+} from '@/services/backend';
+import { pbToSelectOption, SelectOption } from '../select_option';
+
+export interface TextTypeOption {
+ data?: string;
+}
+
+export interface NumberTypeOption {
+ format?: NumberFormatPB;
+ scale?: number;
+ symbol?: string;
+ name?: string;
+}
+
+export interface DateTimeTypeOption {
+ dateFormat?: DateFormatPB;
+ timeFormat?: TimeFormatPB;
+ timezoneId?: string;
+ fieldType?: FieldType;
+}
+
+export interface SelectTypeOption {
+ options?: SelectOption[];
+ disableColor?: boolean;
+}
+
+export interface CheckboxTypeOption {
+ isSelected?: boolean;
+}
+
+
+function pbToSelectTypeOption(pb: SingleSelectTypeOptionPB | MultiSelectTypeOptionPB): SelectTypeOption {
+ return {
+ options: pb.options?.map(pbToSelectOption),
+ disableColor: pb.disable_color,
+ };
+}
+
+function pbToCheckboxTypeOption(pb: CheckboxTypeOptionPB): CheckboxTypeOption {
+ return {
+ isSelected: pb.is_selected,
+ };
+}
+
+export function bytesToTypeOption(data: Uint8Array, fieldType: FieldType) {
+ switch (fieldType) {
+ case FieldType.RichText:
+ return RichTextTypeOptionPB.deserialize(data).toObject() as TextTypeOption;
+ case FieldType.Number:
+ return NumberTypeOptionPB.deserialize(data).toObject() as NumberTypeOption;
+ case FieldType.SingleSelect:
+ return pbToSelectTypeOption(SingleSelectTypeOptionPB.deserialize(data));
+ case FieldType.MultiSelect:
+ return pbToSelectTypeOption(MultiSelectTypeOptionPB.deserialize(data));
+ case FieldType.Checkbox:
+ return pbToCheckboxTypeOption(CheckboxTypeOptionPB.deserialize(data));
+ }
+}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/filter/filter_service.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/filter/filter_service.ts
new file mode 100644
index 0000000000..f85768bb6f
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/filter/filter_service.ts
@@ -0,0 +1,73 @@
+import {
+ DatabaseEventGetAllFilters,
+ DatabaseEventUpdateDatabaseSetting,
+ DatabaseSettingChangesetPB,
+ DatabaseViewIdPB,
+ DeleteFilterPayloadPB,
+ FieldType,
+ FilterPB,
+ UpdateFilterPayloadPB,
+} from '@/services/backend/events/flowy-database2';
+import { Filter, filterDataToPB, UndeterminedFilter } from './filter_types';
+
+export async function getAllFilters(viewId: string): Promise<FilterPB[]> {
+ const payload = DatabaseViewIdPB.fromObject({ value: viewId });
+
+ const result = await DatabaseEventGetAllFilters(payload);
+
+ return result.map(value => value.items).unwrap();
+}
+
+export async function insertFilter(
+ viewId: string,
+ fieldId: string,
+ fieldType: FieldType,
+ data: UndeterminedFilter['data'],
+): Promise<void> {
+ const payload = DatabaseSettingChangesetPB.fromObject({
+ view_id: viewId,
+ update_filter: UpdateFilterPayloadPB.fromObject({
+ view_id: viewId,
+ field_id: fieldId,
+ field_type: fieldType,
+ data: filterDataToPB(data, fieldType)?.serialize(),
+ }),
+ });
+
+ const result = await DatabaseEventUpdateDatabaseSetting(payload);
+
+ return result.unwrap();
+}
+
+export async function updateFilter(viewId: string, filter: UndeterminedFilter): Promise<void> {
+ const payload = DatabaseSettingChangesetPB.fromObject({
+ view_id: viewId,
+ update_filter: UpdateFilterPayloadPB.fromObject({
+ view_id: viewId,
+ filter_id: filter.id,
+ field_id: filter.fieldId,
+ field_type: filter.fieldType,
+ data: filterDataToPB(filter.data, filter.fieldType)?.serialize(),
+ }),
+ });
+
+ const result = await DatabaseEventUpdateDatabaseSetting(payload);
+
+ return result.unwrap();
+}
+
+export async function deleteFilter(viewId: string, filter: Omit<Filter, 'data'>): Promise<void> {
+ const payload = DatabaseSettingChangesetPB.fromObject({
+ view_id: viewId,
+ delete_filter: DeleteFilterPayloadPB.fromObject({
+ view_id: viewId,
+ filter_id: filter.id,
+ field_id: filter.fieldId,
+ field_type: filter.fieldType,
+ }),
+ });
+
+ const result = await DatabaseEventUpdateDatabaseSetting(payload);
+
+ return result.unwrap();
+}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/filter/filter_types.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/filter/filter_types.ts
new file mode 100644
index 0000000000..1dcab6eef5
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/filter/filter_types.ts
@@ -0,0 +1,86 @@
+import {
+ FieldType,
+ TextFilterConditionPB,
+ SelectOptionConditionPB,
+ TextFilterPB,
+ SelectOptionFilterPB,
+ FilterPB,
+} from '@/services/backend';
+
+export interface Filter {
+ id: string;
+ fieldId: string;
+ fieldType: FieldType;
+ data: unknown;
+}
+
+export interface TextFilter extends Filter {
+ fieldType: FieldType.RichText;
+ data: TextFilterData;
+}
+
+export interface TextFilterData {
+ condition: TextFilterConditionPB;
+ content?: string;
+}
+
+export interface SelectFilter extends Filter {
+ fieldType: FieldType.SingleSelect | FieldType.MultiSelect;
+ data: SelectFilterData;
+}
+
+export interface SelectFilterData {
+ condition?: SelectOptionConditionPB;
+ optionIds?: string[];
+}
+
+export type UndeterminedFilter = TextFilter | SelectFilter;
+
+export function filterDataToPB(data: UndeterminedFilter['data'], fieldType: FieldType) {
+ switch (fieldType) {
+ case FieldType.RichText:
+ return TextFilterPB.fromObject({
+ condition: (data as TextFilterData).condition,
+ content: (data as TextFilterData).content,
+ });
+ case FieldType.SingleSelect:
+ case FieldType.MultiSelect:
+ return SelectOptionFilterPB.fromObject({
+ condition: (data as SelectFilterData).condition,
+ option_ids: (data as SelectFilterData).optionIds,
+ });
+ }
+}
+
+export function pbToTextFilterData(pb: TextFilterPB): TextFilterData {
+ return {
+ condition: pb.condition,
+ content: pb.content,
+ };
+}
+
+export function pbToSelectFilterData(pb: SelectOptionFilterPB): SelectFilterData {
+ return {
+ condition: pb.condition,
+ optionIds: pb.option_ids,
+ };
+}
+
+export function bytesToFilterData(bytes: Uint8Array, fieldType: FieldType) {
+ switch (fieldType) {
+ case FieldType.RichText:
+ return pbToTextFilterData(TextFilterPB.deserialize(bytes));
+ case FieldType.SingleSelect:
+ case FieldType.MultiSelect:
+ return pbToSelectFilterData(SelectOptionFilterPB.deserialize(bytes));
+ }
+}
+
+export function pbToFilter(pb: FilterPB): Filter {
+ return {
+ id: pb.id,
+ fieldId: pb.field_id,
+ fieldType: pb.field_type,
+ data: bytesToFilterData(pb.data, pb.field_type),
+ };
+}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/filter/index.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/filter/index.ts
new file mode 100644
index 0000000000..55e195606d
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/filter/index.ts
@@ -0,0 +1,2 @@
+export * from './filter_types';
+export * as filterService from './filter_service';
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/group/group_service.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/group/group_service.ts
new file mode 100644
index 0000000000..24f24d65ec
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/group/group_service.ts
@@ -0,0 +1,64 @@
+import {
+ DatabaseViewIdPB,
+ GroupByFieldPayloadPB,
+ MoveGroupPayloadPB,
+ UpdateGroupPB,
+} from '@/services/backend';
+import {
+ DatabaseEventGetGroups,
+ DatabaseEventMoveGroup,
+ DatabaseEventSetGroupByField,
+ DatabaseEventUpdateGroup,
+} from '@/services/backend/events/flowy-database2';
+import { Group, pbToGroup } from './group_types';
+
+export async function getGroups(viewId: string): Promise<Group[]> {
+ const payload = DatabaseViewIdPB.fromObject({ value: viewId });
+
+ const result = await DatabaseEventGetGroups(payload);
+
+ return result.map(value => value.items.map(pbToGroup)).unwrap();
+}
+
+export async function setGroupByField(viewId: string, fieldId: string): Promise<void> {
+ const payload = GroupByFieldPayloadPB.fromObject({
+ view_id: viewId,
+ field_id: fieldId,
+ });
+
+ const result = await DatabaseEventSetGroupByField(payload);
+
+ return result.unwrap();
+}
+
+export async function updateGroup(
+ viewId: string,
+ group: {
+ id: string,
+ name?: string,
+ visible?: boolean,
+ },
+): Promise<void> {
+ const payload = UpdateGroupPB.fromObject({
+ view_id: viewId,
+ group_id: group.id,
+ name: group.name,
+ visible: group.visible,
+ });
+
+ const result = await DatabaseEventUpdateGroup(payload);
+
+ return result.unwrap();
+}
+
+export async function moveGroup(viewId: string, fromGroupId: string, toGroupId: string): Promise<void> {
+ const payload = MoveGroupPayloadPB.fromObject({
+ view_id: viewId,
+ from_group_id: fromGroupId,
+ to_group_id: toGroupId,
+ });
+
+ const result = await DatabaseEventMoveGroup(payload);
+
+ return result.unwrap();
+}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/group/group_types.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/group/group_types.ts
new file mode 100644
index 0000000000..ad0c8af542
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/group/group_types.ts
@@ -0,0 +1,34 @@
+import { GroupPB, GroupSettingPB } from '@/services/backend';
+import { pbToRowMeta, RowMeta } from '../row';
+
+export interface GroupSetting {
+ id: string;
+ fieldId: string;
+}
+
+export interface Group {
+ id: string;
+ name: string;
+ isDefault: boolean;
+ isVisible: boolean;
+ fieldId: string;
+ rows: RowMeta[];
+}
+
+export function pbToGroup(pb: GroupPB): Group {
+ return {
+ id: pb.group_id,
+ name: pb.group_name,
+ isDefault: pb.is_default,
+ isVisible: pb.is_visible,
+ fieldId: pb.field_id,
+ rows: pb.rows.map(pbToRowMeta),
+ };
+}
+
+export function pbToGroupSetting(pb: GroupSettingPB): GroupSetting {
+ return {
+ id: pb.id,
+ fieldId: pb.field_id,
+ };
+}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/group/index.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/group/index.ts
new file mode 100644
index 0000000000..bb872d6677
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/group/index.ts
@@ -0,0 +1,2 @@
+export * from './group_types';
+export * as groupService from './group_service';
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/index.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/index.ts
new file mode 100644
index 0000000000..f44da5b857
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/index.ts
@@ -0,0 +1,8 @@
+export * from './cell';
+export * from './database';
+export * from './database_view';
+export * from './field';
+export * from './filter';
+export * from './group';
+export * from './row';
+export * from './sort';
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/row/index.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/row/index.ts
new file mode 100644
index 0000000000..69260223ef
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/row/index.ts
@@ -0,0 +1,3 @@
+export * from './row_types';
+export * as rowService from './row_service';
+export * as rowListeners from './row_listeners';
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/row/row_listeners.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/row/row_listeners.ts
new file mode 100644
index 0000000000..e45b03a2f3
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/row/row_listeners.ts
@@ -0,0 +1,61 @@
+import {
+ ReorderAllRowsPB,
+ ReorderSingleRowPB,
+ RowsChangePB,
+} from '@/services/backend';
+import { Database } from '../database';
+import { pbToRowMeta, RowMeta } from './row_types';
+
+const deleteRowsFromChangeset = (database: Database, changeset: RowsChangePB) => {
+ changeset.deleted_rows.forEach(rowId => {
+ const index = database.rowMetas.findIndex(row => row.id === rowId);
+
+ if (index !== -1) {
+ database.rowMetas.splice(index, 1);
+ }
+ });
+};
+
+const insertRowsFromChangeset = (database: Database, changeset: RowsChangePB) => {
+ changeset.inserted_rows.forEach(({ index, row_meta: rowMetaPB }) => {
+ database.rowMetas.splice(index, 0, pbToRowMeta(rowMetaPB));
+ });
+};
+
+const updateRowsFromChangeset = (database: Database, changeset: RowsChangePB) => {
+ changeset.updated_rows.forEach(({ row_id: rowId, row_meta: rowMetaPB }) => {
+ const found = database.rowMetas.find(rowMeta => rowMeta.id === rowId);
+
+ if (found) {
+ Object.assign(found, pbToRowMeta(rowMetaPB));
+ }
+ });
+};
+
+export const didUpdateViewRows = (database: Database, changeset: RowsChangePB) => {
+ deleteRowsFromChangeset(database, changeset);
+ insertRowsFromChangeset(database, changeset);
+ updateRowsFromChangeset(database, changeset);
+};
+
+export const didReorderRows = (database: Database, changeset: ReorderAllRowsPB) => {
+ const rowById = database.rowMetas.reduce<Record<string, RowMeta>>((prev, cur) => {
+ prev[cur.id] = cur;
+ return prev;
+ }, {});
+
+ database.rowMetas = changeset.row_orders.map(rowId => rowById[rowId]);
+};
+
+export const didReorderSingleRow = (database: Database, changeset: ReorderSingleRowPB) => {
+ const {
+ row_id: rowId,
+ new_index: newIndex,
+ } = changeset;
+
+ const oldIndex = database.rowMetas.findIndex(rowMeta => rowMeta.id === rowId);
+
+ if (oldIndex !== -1) {
+ database.rowMetas.splice(newIndex, 0, database.rowMetas.splice(oldIndex, 1)[0]);
+ }
+};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/row/row_service.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/row/row_service.ts
new file mode 100644
index 0000000000..6c6db0f5e0
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/row/row_service.ts
@@ -0,0 +1,124 @@
+import {
+ CreateRowPayloadPB,
+ MoveGroupRowPayloadPB,
+ MoveRowPayloadPB,
+ RowIdPB,
+ UpdateRowMetaChangesetPB,
+} from '@/services/backend';
+import {
+ DatabaseEventCreateRow,
+ DatabaseEventDeleteRow,
+ DatabaseEventDuplicateRow,
+ DatabaseEventGetRowMeta,
+ DatabaseEventMoveGroupRow,
+ DatabaseEventMoveRow,
+ DatabaseEventUpdateRowMeta,
+} from '@/services/backend/events/flowy-database2';
+import { pbToRowMeta, RowMeta } from './row_types';
+
+export async function createRow(viewId: string, params?: {
+ startRowId?: string;
+ groupId?: string;
+ data?: Record<string, string>;
+}): Promise<RowMeta> {
+ const payload = CreateRowPayloadPB.fromObject({
+ view_id: viewId,
+ start_row_id: params?.startRowId,
+ group_id: params?.groupId,
+ data: params?.data ? { cell_data_by_field_id: params.data } : undefined,
+ });
+
+ const result = await DatabaseEventCreateRow(payload);
+
+ return result.map(pbToRowMeta).unwrap();
+}
+
+export async function duplicateRow(viewId: string, rowId: string, groupId?: string): Promise<void> {
+ const payload = RowIdPB.fromObject({
+ view_id: viewId,
+ row_id: rowId,
+ group_id: groupId,
+ });
+
+ const result = await DatabaseEventDuplicateRow(payload);
+
+ return result.unwrap();
+}
+
+export async function deleteRow(viewId: string, rowId: string, groupId?: string): Promise<void> {
+ const payload = RowIdPB.fromObject({
+ view_id: viewId,
+ row_id: rowId,
+ group_id: groupId,
+ });
+
+ const result = await DatabaseEventDeleteRow(payload);
+
+ return result.unwrap();
+}
+
+export async function moveRow(viewId: string, fromRowId: string, toRowId: string): Promise<void> {
+ const payload = MoveRowPayloadPB.fromObject({
+ view_id: viewId,
+ from_row_id: fromRowId,
+ to_row_id: toRowId,
+ });
+
+ const result = await DatabaseEventMoveRow(payload);
+
+ return result.unwrap();
+}
+
+/**
+ * Move the row from one group to another group
+ *
+ * @param fromRowId
+ * @param toGroupId
+ * @param toRowId used to locate the moving row location.
+ * @returns
+ */
+export async function moveGroupRow(viewId: string, fromRowId: string, toGroupId: string, toRowId?: string): Promise<void> {
+ const payload = MoveGroupRowPayloadPB.fromObject({
+ view_id: viewId,
+ from_row_id: fromRowId,
+ to_group_id: toGroupId,
+ to_row_id: toRowId,
+ });
+
+ const result = await DatabaseEventMoveGroupRow(payload);
+
+ return result.unwrap();
+}
+
+
+export async function getRowMeta(viewId: string, rowId: string, groupId?: string): Promise<RowMeta> {
+ const payload = RowIdPB.fromObject({
+ view_id: viewId,
+ row_id: rowId,
+ group_id: groupId,
+ });
+
+ const result = await DatabaseEventGetRowMeta(payload);
+
+ return result.map(pbToRowMeta).unwrap();
+}
+
+export async function updateRowMeta(
+ viewId: string,
+ rowId: string,
+ meta: {
+ iconUrl?: string;
+ coverUrl?: string;
+ },
+): Promise<void> {
+ const payload = UpdateRowMetaChangesetPB.fromObject({
+ view_id: viewId,
+ id: rowId,
+ icon_url: meta.iconUrl,
+ cover_url: meta.coverUrl,
+ });
+
+ const result = await DatabaseEventUpdateRowMeta(payload);
+
+ return result.unwrap();
+}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/row/row_types.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/row/row_types.ts
new file mode 100644
index 0000000000..ab1f3bfc3b
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/row/row_types.ts
@@ -0,0 +1,28 @@
+import { RowMetaPB } from '@/services/backend';
+
+export interface RowMeta {
+ id: string;
+ documentId?: string;
+ icon?: string;
+ cover?: string;
+}
+
+export function pbToRowMeta(pb: RowMetaPB): RowMeta {
+ const rowMeta: RowMeta = {
+ id: pb.id,
+ };
+
+ if (pb.document_id) {
+ rowMeta.documentId = pb.document_id;
+ }
+
+ if (pb.icon) {
+ rowMeta.icon = pb.icon;
+ }
+
+ if (pb.cover) {
+ rowMeta.cover = pb.cover;
+ }
+
+ return rowMeta;
+}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/sort/index.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/sort/index.ts
new file mode 100644
index 0000000000..6c7d4bd60a
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/sort/index.ts
@@ -0,0 +1,3 @@
+export * from './sort_types';
+export * as sortService from './sort_service';
+export * as sortListeners from './sort_listeners';
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/sort/sort_listeners.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/sort/sort_listeners.ts
new file mode 100644
index 0000000000..377dfec2f5
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/sort/sort_listeners.ts
@@ -0,0 +1,35 @@
+import { SortChangesetNotificationPB } from '@/services/backend';
+import { Database } from '../database';
+import { pbToSort } from './sort_types';
+
+const deleteSortsFromChange = (database: Database, changeset: SortChangesetNotificationPB) => {
+ const deleteIds = changeset.delete_sorts.map(sort => sort.id);
+
+ if (deleteIds.length) {
+ database.sorts = database.sorts.filter(sort => !deleteIds.includes(sort.id));
+ }
+};
+
+const insertSortsFromChange = (database: Database, changeset: SortChangesetNotificationPB) => {
+ changeset.insert_sorts.forEach(sortPB => {
+ database.sorts.push(pbToSort(sortPB));
+ });
+};
+
+const updateSortsFromChange = (database: Database, changeset: SortChangesetNotificationPB) => {
+ changeset.update_sorts.forEach(sortPB => {
+ const found = database.sorts.find(sort => sort.id === sortPB.id);
+
+ if (found) {
+ const newSort = pbToSort(sortPB);
+
+ Object.assign(found, newSort);
+ }
+ });
+};
+
+export const didUpdateSort = (database: Database, changeset: SortChangesetNotificationPB) => {
+ deleteSortsFromChange(database, changeset);
+ insertSortsFromChange(database, changeset);
+ updateSortsFromChange(database, changeset);
+};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/sort/sort_service.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/sort/sort_service.ts
new file mode 100644
index 0000000000..be444a545e
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/sort/sort_service.ts
@@ -0,0 +1,77 @@
+import {
+ DatabaseViewIdPB,
+ DatabaseSettingChangesetPB,
+} from '@/services/backend';
+import {
+ DatabaseEventDeleteAllSorts,
+ DatabaseEventGetAllSorts, DatabaseEventUpdateDatabaseSetting,
+} from '@/services/backend/events/flowy-database2';
+import { pbToSort, Sort } from './sort_types';
+
+export async function getAllSorts(viewId: string): Promise<Sort[]> {
+ const payload = DatabaseViewIdPB.fromObject({
+ value: viewId,
+ });
+
+ const result = await DatabaseEventGetAllSorts(payload);
+
+ return result.map(value => value.items.map(pbToSort)).unwrap();
+}
+
+export async function insertSort(viewId: string, sort: Omit<Sort, 'id'>): Promise<void> {
+ const payload = DatabaseSettingChangesetPB.fromObject({
+ view_id: viewId,
+ update_sort: {
+ view_id: viewId,
+ field_id: sort.fieldId,
+ field_type: sort.fieldType,
+ condition: sort.condition,
+ },
+ });
+
+ const result = await DatabaseEventUpdateDatabaseSetting(payload);
+
+ return result.unwrap();
+}
+
+export async function updateSort(viewId: string, sort: Sort): Promise<void> {
+ const payload = DatabaseSettingChangesetPB.fromObject({
+ view_id: viewId,
+ update_sort: {
+ view_id: viewId,
+ sort_id: sort.id,
+ field_id: sort.fieldId,
+ field_type: sort.fieldType,
+ condition: sort.condition,
+ },
+ });
+
+ const result = await DatabaseEventUpdateDatabaseSetting(payload);
+
+ return result.unwrap();
+}
+
+export async function deleteSort(viewId: string, sort: Sort): Promise<void> {
+ const payload = DatabaseSettingChangesetPB.fromObject({
+ view_id: viewId,
+ delete_sort: {
+ view_id: viewId,
+ sort_id: sort.id,
+ field_id: sort.fieldId,
+ field_type: sort.fieldType,
+ },
+ });
+
+ const result = await DatabaseEventUpdateDatabaseSetting(payload);
+
+ return result.unwrap();
+}
+
+export async function deleteAllSorts(viewId: string): Promise<void> {
+ const payload = DatabaseViewIdPB.fromObject({
+ value: viewId,
+ });
+ const result = await DatabaseEventDeleteAllSorts(payload);
+
+ return result.unwrap();
+}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/application/sort/sort_types.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/sort/sort_types.ts
new file mode 100644
index 0000000000..3de8b1d45e
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/application/sort/sort_types.ts
@@ -0,0 +1,17 @@
+import { FieldType, SortConditionPB, SortPB } from '@/services/backend';
+
+export interface Sort {
+ id: string;
+ fieldId: string;
+ fieldType: FieldType;
+ condition: SortConditionPB;
+}
+
+export function pbToSort(pb: SortPB): Sort {
+ return {
+ id: pb.id,
+ fieldId: pb.field_id,
+ fieldType: pb.field_type,
+ condition: pb.condition,
+ };
+}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/board/Board.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/board/Board.tsx
new file mode 100644
index 0000000000..790f841701
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/board/Board.tsx
@@ -0,0 +1,5 @@
+import { FC } from 'react';
+
+export const Board: FC = () => {
+ return null;
+};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/board/index.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/board/index.ts
new file mode 100644
index 0000000000..9294d869ce
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/board/index.ts
@@ -0,0 +1 @@
+export * from './Board';
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/calendar/Calendar.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/calendar/Calendar.tsx
new file mode 100644
index 0000000000..b8473fda25
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/calendar/Calendar.tsx
@@ -0,0 +1,5 @@
+import { FC } from 'react';
+
+export const Calendar: FC = () => {
+ return null;
+};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/calendar/index.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/calendar/index.ts
new file mode 100644
index 0000000000..a723380592
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/calendar/index.ts
@@ -0,0 +1 @@
+export * from './Calendar';
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/Cell.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/Cell.hooks.ts
new file mode 100644
index 0000000000..bb390db0e7
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/Cell.hooks.ts
@@ -0,0 +1,24 @@
+import { useCallback, useEffect, useState } from 'react';
+import { DatabaseNotification, FieldType } from '@/services/backend';
+import { useNotification, useViewId } from '$app/hooks';
+import { cellService, Cell } from '../../application';
+
+export const useCell = (rowId: string, fieldId: string, fieldType: FieldType) => {
+ const viewId = useViewId();
+ const [cell, setCell] = useState<Cell | null>(null);
+
+ const fetchCell = useCallback(() => {
+ void cellService.getCell(viewId, rowId, fieldId, fieldType)
+ .then(data => {
+ setCell(data);
+ });
+ }, [viewId, rowId, fieldId, fieldType]);
+
+ useEffect(() => {
+ void fetchCell();
+ }, [fetchCell]);
+
+ useNotification(DatabaseNotification.DidUpdateCell, fetchCell, { id: `${rowId}:${fieldId}` });
+
+ return cell;
+};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/Cell.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/Cell.tsx
new file mode 100644
index 0000000000..72e596d7f4
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/Cell.tsx
@@ -0,0 +1,42 @@
+import { FC } from 'react';
+import { FieldType } from '@/services/backend';
+
+import { Cell as CellType, Field } from '../../application';
+import { useCell } from './Cell.hooks';
+import { TextCell } from './TextCell';
+import { SelectCell } from './SelectCell';
+import { CheckboxCell } from './CheckboxCell';
+
+export interface CellProps {
+ rowId: string;
+ field: Field;
+}
+
+const getCellComponent = (fieldType: FieldType) => {
+ switch (fieldType) {
+ case FieldType.RichText:
+ return TextCell as FC<{ field: Field, cell: CellType }>;
+ case FieldType.SingleSelect:
+ case FieldType.MultiSelect:
+ return SelectCell as FC<{ field: Field, cell: CellType }>;
+ case FieldType.Checkbox:
+ return CheckboxCell as FC<{ field: Field, cell: CellType }>;
+ default:
+ return null;
+ }
+};
+
+export const Cell: FC<CellProps> = ({
+ rowId,
+ field,
+}) => {
+ const cell = useCell(rowId, field.id, field.type);
+
+ const Component = getCellComponent(field.type);
+
+ if (!cell || !Component) {
+ return null;
+ }
+
+ return <Component field={field} cell={cell} />;
+};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/CheckboxCell.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/CheckboxCell.tsx
new file mode 100644
index 0000000000..c3120b61ed
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/CheckboxCell.tsx
@@ -0,0 +1,35 @@
+import { Checkbox } from '@mui/material';
+import { FC, useCallback } from 'react';
+import { ReactComponent as CheckboxCheckSvg } from '$app/assets/database/checkbox-check.svg';
+import { ReactComponent as CheckboxUncheckSvg } from '$app/assets/database/checkbox-uncheck.svg';
+import { useViewId } from '$app/hooks';
+import { cellService, CheckboxCell as CheckboxCellType, Field } from '../../application';
+
+export const CheckboxCell: FC<{
+ field: Field,
+ cell: CheckboxCellType,
+}> = ({ field, cell }) => {
+ const viewId = useViewId();
+ const checked = cell.data === 'Yes';
+
+ const handleClick = useCallback(() => {
+ void cellService.updateCell(
+ viewId,
+ cell.rowId,
+ field.id,
+ !checked ? 'Yes' : 'No',
+ );
+ }, [viewId, cell.rowId, field.id, checked ]);
+
+ return (
+ <div className="flex items-center w-full px-2 cursor-pointer" onClick={handleClick}>
+ <Checkbox
+ disableRipple
+ style={{ padding: 0 }}
+ checked={checked}
+ icon={<CheckboxUncheckSvg />}
+ checkedIcon={<CheckboxCheckSvg />}
+ />
+ </div>
+ );
+};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridSelectCell/CreateOption.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/SelectCell/CreateOption.tsx
similarity index 100%
rename from frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridSelectCell/CreateOption.tsx
rename to frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/SelectCell/CreateOption.tsx
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridSelectCell/GridSelectCell.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/SelectCell/SelectCell.tsx
similarity index 79%
rename from frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridSelectCell/GridSelectCell.tsx
rename to frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/SelectCell/SelectCell.tsx
index 1e1eae4390..d7622e8590 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridSelectCell/GridSelectCell.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/SelectCell/SelectCell.tsx
@@ -10,9 +10,8 @@ import {
MenuItem,
} from '@mui/material';
import { FieldType } from '@/services/backend';
-import { Database } from '$app/interfaces/database';
-import * as service from '../../../database_bd_svc';
-import { useViewId } from '../../../database.hooks';
+import { useViewId } from '$app/hooks';
+import { cellService, SelectField, SelectCell as SelectCellType } from '../../../application';
import { Tag } from './Tag';
import { CreateOption } from './CreateOption';
import { SelectOptionItem } from './SelectOptionItem';
@@ -31,14 +30,14 @@ const menuProps: Partial<MenuProps> = {
},
};
-export const GridSelectCell: FC<{
- rowId: string;
- field: Database.Field;
- cell: Database.SelectCell | null;
-}> = ({ rowId, field, cell }) => {
+export const SelectCell: FC<{
+ field: SelectField;
+ cell: SelectCellType;
+}> = ({ field, cell }) => {
+ const rowId = cell.rowId;
const viewId = useViewId();
- const options = useMemo(() => cell?.data?.options ?? [], [cell?.data.options]);
- const selectedIds = useMemo(() => cell?.data.selectOptions?.map(({ id }) => id) ?? [], [cell?.data.selectOptions]);
+ const options = useMemo(() => field.typeOption.options ?? [], [field.typeOption.options]);
+ const selectedIds = useMemo(() => cell.data.selectedOptionIds ?? [], [cell.data.selectedOptionIds]);
const [newOptionName, setNewOptionName] = useState('');
const filteredOptions = useMemo(() => options.filter(option => {
return option.name.toLowerCase().includes(newOptionName.toLowerCase());
@@ -60,10 +59,10 @@ export const GridSelectCell: FC<{
const { target: { value } } = event;
const current = Array.isArray(value) ? value : [value];
- const prev = cell?.data.selectOptions?.map(({ id }) => id);
+ const prev = cell.data.selectedOptionIds;
const deleteOptionIds = prev?.filter(id => current.find(cur => cur === id) === undefined);
- void service.updateSelectOptionCell(viewId, rowId, field.id, {
+ void cellService.updateSelectCell(viewId, rowId, field.id, {
insertOptionIds: current,
deleteOptionIds,
});
@@ -73,14 +72,14 @@ export const GridSelectCell: FC<{
const exist = options.find(option => option.name.toLowerCase() === newOptionName.toLowerCase());
if (exist) {
- return service.updateSelectOptionCell(viewId, rowId, field.id, {
+ return cellService.updateSelectCell(viewId, rowId, field.id, {
insertOptionIds: [exist.id],
});
}
- const option = await service.createSelectOption(viewId, field.id, newOptionName);
+ // const option = await cellService.createSelectOption(viewId, field.id, newOptionName);
- await service.insertOrUpdateSelectOption(viewId, field.id, [option], rowId);
+ // await cellService.insertOrUpdateSelectOption(viewId, field.id, [option], rowId);
};
const searchInput = (
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridSelectCell/SelectOptionItem.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/SelectCell/SelectOptionItem.tsx
similarity index 93%
rename from frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridSelectCell/SelectOptionItem.tsx
rename to frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/SelectCell/SelectOptionItem.tsx
index 7472779df2..f320731af0 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridSelectCell/SelectOptionItem.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/SelectCell/SelectOptionItem.tsx
@@ -1,12 +1,12 @@
import { FC, MouseEventHandler, useCallback, useRef, useState } from 'react';
import { IconButton } from '@mui/material';
-import { Database } from '$app/interfaces/database';
import { ReactComponent as DetailsSvg } from '$app/assets/details.svg';
+import { SelectOption } from '../../../application';
import { SelectOptionMenu } from './SelectOptionMenu';
import { Tag } from './Tag';
export interface SelectOptionItemProps {
- option: Database.SelectOption;
+ option: SelectOption;
}
export const SelectOptionItem: FC<SelectOptionItemProps> = ({
@@ -46,4 +46,4 @@ export const SelectOptionItem: FC<SelectOptionItemProps> = ({
)}
</>
);
-};
\ No newline at end of file
+};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridSelectCell/SelectOptionMenu.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/SelectCell/SelectOptionMenu.tsx
similarity index 90%
rename from frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridSelectCell/SelectOptionMenu.tsx
rename to frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/SelectCell/SelectOptionMenu.tsx
index 01cc2101f0..310881017a 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridSelectCell/SelectOptionMenu.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/SelectCell/SelectOptionMenu.tsx
@@ -1,14 +1,21 @@
import { FC } from 'react';
import { t } from 'i18next';
-import { Divider, ListSubheader, Menu, MenuItem, MenuProps, OutlinedInput } from '@mui/material'
+import {
+ Divider,
+ ListSubheader,
+ Menu,
+ MenuItem,
+ MenuProps,
+ OutlinedInput,
+} from '@mui/material';
import { SelectOptionColorPB } from '@/services/backend';
import { ReactComponent as DeleteSvg } from '$app/assets/delete.svg';
-import { Database } from '$app/interfaces/database';
-import { SelectOptionColorMap, SelectOptionColorTextMap } from './constants';
import { ReactComponent as SelectCheckSvg } from '$app/assets/database/select-check.svg';
+import { SelectOption } from '../../../application';
+import { SelectOptionColorMap, SelectOptionColorTextMap } from './constants';
interface SelectOptionMenuProps {
- option: Database.SelectOption;
+ option: SelectOption;
open: boolean;
MenuProps?: Partial<MenuProps>;
}
@@ -67,5 +74,5 @@ export const SelectOptionMenu: FC<SelectOptionMenuProps> = ({
</MenuItem>
))}
</Menu>
- )
-}
\ No newline at end of file
+ );
+};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridSelectCell/Tag.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/SelectCell/Tag.tsx
similarity index 100%
rename from frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridSelectCell/Tag.tsx
rename to frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/SelectCell/Tag.tsx
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridSelectCell/constants.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/SelectCell/constants.ts
similarity index 94%
rename from frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridSelectCell/constants.ts
rename to frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/SelectCell/constants.ts
index c1a4f7a739..58a42f7dad 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridSelectCell/constants.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/SelectCell/constants.ts
@@ -1,4 +1,4 @@
-import { SelectOptionColorPB } from "@/services/backend";
+import { SelectOptionColorPB } from '@/services/backend';
export const SelectOptionColorMap = {
[SelectOptionColorPB.Purple]: 'bg-tint-purple',
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/SelectCell/index.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/SelectCell/index.ts
new file mode 100644
index 0000000000..745d3fb1a2
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/SelectCell/index.ts
@@ -0,0 +1 @@
+export * from './SelectCell';
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridTextCell.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/TextCell.tsx
similarity index 68%
rename from frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridTextCell.tsx
rename to frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/TextCell.tsx
index 3ff3902582..dcd32e880d 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridTextCell.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/TextCell.tsx
@@ -1,41 +1,39 @@
import { Popover, TextareaAutosize } from '@mui/material';
-import { FC, FormEventHandler, useCallback, useEffect, useRef, useState } from 'react';
-import { Database } from '$app/interfaces/database';
-import * as service from '$app/components/database/database_bd_svc';
-import { useViewId } from '../../database.hooks';
+import { FC, FormEventHandler, useCallback, useLayoutEffect, useRef, useState } from 'react';
+import { useViewId } from '$app/hooks';
+import { cellService, Field, TextCell as TextCellType } from '../../application';
import { CellText } from '../../_shared';
-export const GridTextCell: FC<{
- rowId: string;
- field: Database.Field,
- cell: Database.TextCell | null;
-}> = ({ rowId, field, cell }) => {
+export const TextCell: FC<{
+ field: Field,
+ cell: TextCellType;
+}> = ({ field, cell }) => {
const viewId = useViewId();
+ const cellRef = useRef<HTMLDivElement>(null);
const [ editing, setEditing ] = useState(false);
const [ text, setText ] = useState('');
const [ width, setWidth ] = useState<number | undefined>(undefined);
- const cellRef = useRef<HTMLDivElement>(null);
const handleClose = () => {
if (editing) {
- if (text !== cell?.data) {
- void service.updateCell(viewId, rowId, field.id, text);
+ if (text !== cell.data) {
+ void cellService.updateCell(viewId, cell.rowId, field.id, text);
}
setEditing(false);
}
};
- const handleDoubleClick = useCallback(() => {
- setText(cell?.data ?? '');
+ const handleClick = useCallback(() => {
+ setText(cell.data);
setEditing(true);
- }, [cell?.data]);
+ }, [cell.data]);
const handleInput = useCallback<FormEventHandler<HTMLTextAreaElement>>((event) => {
setText((event.target as HTMLTextAreaElement).value);
}, []);
- useEffect(() => {
+ useLayoutEffect(() => {
if (cellRef.current) {
setWidth(cellRef.current.clientWidth);
}
@@ -46,9 +44,9 @@ export const GridTextCell: FC<{
<CellText
ref={cellRef}
className="w-full"
- onDoubleClick={handleDoubleClick}
+ onClick={handleClick}
>
- {cell?.data}
+ {cell.data}
</CellText>
{editing && (
<Popover
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/index.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/index.ts
new file mode 100644
index 0000000000..2440976340
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/cell/index.ts
@@ -0,0 +1 @@
+export * from './Cell';
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/components/database_settings/DatabaseSettings.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/database_settings/DatabaseSettings.tsx
new file mode 100644
index 0000000000..d6d8d0e854
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/database_settings/DatabaseSettings.tsx
@@ -0,0 +1,13 @@
+import { Sort } from '../../application';
+import { useDatabase } from '../../Database.hooks';
+import { Sorts } from '../sort';
+
+export const DatabaseSettings = () => {
+ const { sorts } = useDatabase();
+
+ return (
+ <div className="flex items-center border-t">
+ <Sorts sorts={sorts as Sort[]} />
+ </div>
+ );
+};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/components/database_settings/index.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/database_settings/index.ts
new file mode 100644
index 0000000000..ebac0b2a51
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/database_settings/index.ts
@@ -0,0 +1 @@
+export * from './DatabaseSettings';
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/components/field/Field.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/field/Field.tsx
new file mode 100644
index 0000000000..f96d07e3f9
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/field/Field.tsx
@@ -0,0 +1,20 @@
+import { FC } from 'react';
+import { Field as FieldType } from '../../application';
+import { FieldTypeSvg } from './FieldTypeSvg';
+
+export interface FieldProps {
+ field: FieldType;
+}
+
+export const Field: FC<FieldProps> = ({
+ field,
+}) => {
+ return (
+ <div className="flex items-center px-2 w-full">
+ <FieldTypeSvg className="text-base mr-1" type={field.type} />
+ <span className="flex-1 text-left text-xs truncate">
+ {field.name}
+ </span>
+ </div>
+ );
+};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/components/field/FieldSelect.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/field/FieldSelect.tsx
new file mode 100644
index 0000000000..7ad17a5a21
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/field/FieldSelect.tsx
@@ -0,0 +1,32 @@
+import { MenuItem, Select, SelectChangeEvent, SelectProps } from '@mui/material';
+import { FC, useCallback } from 'react';
+import { Field as FieldType } from '../../application';
+import { useDatabase } from '../../Database.hooks';
+import { Field } from './Field';
+
+export interface FieldSelectProps extends Omit<SelectProps, 'onChange'> {
+ onChange?: (event: SelectChangeEvent<unknown>, field: FieldType | undefined) => void;
+}
+
+export const FieldSelect: FC<FieldSelectProps> = ({
+ onChange,
+ ...props
+}) => {
+ const { fields } = useDatabase();
+
+ const handleChange = useCallback((event: SelectChangeEvent<unknown>) => {
+ const selectedId = event.target.value;
+
+ onChange?.(event, fields.find(field => field.id === selectedId));
+ }, [onChange, fields]);
+
+ return (
+ <Select onChange={handleChange} {...props}>
+ {fields.map(field => (
+ <MenuItem key={field.id} value={field.id}>
+ <Field field={field} />
+ </MenuItem>
+ ))}
+ </Select>
+ );
+};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/components/field/FieldTypeSvg.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/field/FieldTypeSvg.tsx
new file mode 100644
index 0000000000..d1d42646e7
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/field/FieldTypeSvg.tsx
@@ -0,0 +1,30 @@
+import { FC, memo } from 'react';
+import { FieldType } from '@/services/backend';
+import { ReactComponent as TextSvg } from '$app/assets/database/field-type-text.svg';
+import { ReactComponent as NumberSvg } from '$app/assets/database/field-type-number.svg';
+import { ReactComponent as DateSvg } from '$app/assets/database/field-type-date.svg';
+import { ReactComponent as SingleSelectSvg } from '$app/assets/database/field-type-single-select.svg';
+import { ReactComponent as MultiSelectSvg } from '$app/assets/database/field-type-multi-select.svg';
+import { ReactComponent as ChecklistSvg } from '$app/assets/database/field-type-checklist.svg';
+import { ReactComponent as CheckboxSvg } from '$app/assets/database/field-type-checkbox.svg';
+import { ReactComponent as URLSvg } from '$app/assets/database/field-type-url.svg';
+import { ReactComponent as LastEditedTimeSvg } from '$app/assets/database/field-type-last-edited-time.svg';
+
+export const FieldTypeSvgMap: Record<FieldType, FC<React.SVGProps<SVGSVGElement>>> = {
+ [FieldType.RichText]: TextSvg,
+ [FieldType.Number]: NumberSvg,
+ [FieldType.DateTime]: DateSvg,
+ [FieldType.SingleSelect]: SingleSelectSvg,
+ [FieldType.MultiSelect]: MultiSelectSvg,
+ [FieldType.Checkbox]: CheckboxSvg,
+ [FieldType.URL]: URLSvg,
+ [FieldType.Checklist]: ChecklistSvg,
+ [FieldType.LastEditedTime]: LastEditedTimeSvg,
+ [FieldType.CreatedTime]: LastEditedTimeSvg,
+};
+
+export const FieldTypeSvg: FC<{ type: FieldType, className?: string }> = memo(({ type, ...props }) => {
+ const Svg = FieldTypeSvgMap[type];
+
+ return <Svg {...props} />;
+});
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/components/field/FieldTypeText.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/field/FieldTypeText.tsx
new file mode 100644
index 0000000000..c688e78de7
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/field/FieldTypeText.tsx
@@ -0,0 +1,19 @@
+import { t } from 'i18next';
+import { FieldType } from '@/services/backend';
+
+export const FieldTypeTextMap = {
+ [FieldType.RichText]: 'textFieldName',
+ [FieldType.Number]: 'numberFieldName',
+ [FieldType.DateTime]: 'dateFieldName',
+ [FieldType.SingleSelect]: 'singleSelectFieldName',
+ [FieldType.MultiSelect]: 'multiSelectFieldName',
+ [FieldType.Checkbox]: 'checkboxFieldName',
+ [FieldType.URL]: 'urlFieldName',
+ [FieldType.Checklist]: 'checklistFieldName',
+ [FieldType.LastEditedTime]: 'updatedAtFieldName',
+ [FieldType.CreatedTime]: 'createdAtFieldName',
+} as const;
+
+export const FieldTypeText = (type: FieldType) => {
+ return t(`grid.field.${FieldTypeTextMap[type]}`);
+};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/components/field/FieldsMenu.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/field/FieldsMenu.tsx
new file mode 100644
index 0000000000..a35b0cf087
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/field/FieldsMenu.tsx
@@ -0,0 +1,30 @@
+import { Menu, MenuItem, MenuProps } from '@mui/material';
+import { FC, MouseEvent } from 'react';
+import { Field as FieldType } from '../../application';
+import { useDatabase } from '../../Database.hooks';
+import { Field } from './Field';
+
+export interface FieldsMenuProps extends MenuProps {
+ onMenuItemClick?: (event: MouseEvent<HTMLLIElement>, field: FieldType) => void;
+}
+
+export const FieldsMenu: FC<FieldsMenuProps> = ({ onMenuItemClick, ...props }) => {
+ const { fields } = useDatabase();
+
+ return (
+ <Menu {...props}>
+ {fields.map((field) => (
+ <MenuItem
+ key={field.id}
+ value={field.id}
+ onClick={(event) => {
+ onMenuItemClick?.(event, field);
+ props.onClose?.({}, 'backdropClick');
+ }}
+ >
+ <Field field={field} />
+ </MenuItem>
+ ))}
+ </Menu>
+ );
+};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/components/field/index.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/field/index.ts
new file mode 100644
index 0000000000..64f4ed0906
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/field/index.ts
@@ -0,0 +1,3 @@
+export * from './Field';
+export * from './FieldSelect';
+export * from './FieldsMenu';
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/components/index.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/index.ts
new file mode 100644
index 0000000000..7da8d0eab4
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/index.ts
@@ -0,0 +1,2 @@
+export * from './tab_bar';
+export * from './cell';
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/components/sort/SortConditionSelect.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/sort/SortConditionSelect.tsx
new file mode 100644
index 0000000000..3618bacb55
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/sort/SortConditionSelect.tsx
@@ -0,0 +1,17 @@
+import { t } from 'i18next';
+import { FC } from 'react';
+import { MenuItem, Select, SelectProps } from '@mui/material';
+import { SortConditionPB } from '@/services/backend';
+
+export const SortConditionSelect: FC<SelectProps<SortConditionPB>> = (props) => {
+ return (
+ <Select {...props}>
+ <MenuItem value={SortConditionPB.Ascending}>
+ {t('grid.sort.ascending')}
+ </MenuItem>
+ <MenuItem value={SortConditionPB.Descending}>
+ {t('grid.sort.descending')}
+ </MenuItem>
+ </Select>
+ );
+};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/components/sort/SortItem.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/sort/SortItem.tsx
new file mode 100644
index 0000000000..c50179332a
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/sort/SortItem.tsx
@@ -0,0 +1,63 @@
+import { IconButton, SelectChangeEvent, Stack } from '@mui/material';
+import { FC, useCallback } from 'react';
+import { ReactComponent as CloseSvg } from '$app/assets/close.svg';
+import { Field, Sort, sortService } from '../../application';
+import { FieldSelect } from '../field';
+import { SortConditionSelect } from './SortConditionSelect';
+import { useViewId } from '@/appflowy_app/hooks';
+import { SortConditionPB } from '@/services/backend';
+
+export interface SortItemProps {
+ className?: string;
+ sort: Sort,
+}
+
+export const SortItem: FC<SortItemProps> = ({
+ className,
+ sort,
+}) => {
+ const viewId = useViewId();
+
+ const handleFieldChange = useCallback((event: SelectChangeEvent<unknown>, field: Field | undefined) => {
+ if (field) {
+ void sortService.updateSort(viewId, {
+ ...sort,
+ fieldId: field.id,
+ fieldType: field.type,
+ });
+ }
+ }, [viewId, sort]);
+
+ const handleConditonChange = useCallback((event: SelectChangeEvent<SortConditionPB>) => {
+ void sortService.updateSort(viewId, {
+ ...sort,
+ condition: event.target.value as SortConditionPB,
+ });
+ }, [viewId, sort]);
+
+ const handleClick = useCallback(() => {
+ void sortService.deleteSort(viewId, sort);
+ }, [viewId, sort]);
+
+ return (
+ <Stack
+ className={className}
+ direction="row"
+ spacing={2}
+ >
+ <FieldSelect
+ size="small"
+ value={sort.fieldId}
+ onChange={handleFieldChange}
+ />
+ <SortConditionSelect
+ size="small"
+ value={sort.condition}
+ onChange={handleConditonChange}
+ />
+ <IconButton onClick={handleClick}>
+ <CloseSvg />
+ </IconButton>
+ </Stack>
+ );
+};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/components/sort/SortMenu.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/sort/SortMenu.tsx
new file mode 100644
index 0000000000..b52377ce52
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/sort/SortMenu.tsx
@@ -0,0 +1,59 @@
+import { Menu, MenuItem, MenuProps } from '@mui/material';
+import { FC, MouseEventHandler, useCallback, useState, MouseEvent } from 'react';
+import { useViewId } from '$app/hooks';
+import { Field, sortService } from '../../application';
+import { useDatabase } from '../../Database.hooks';
+import { FieldsMenu } from '../field';
+import { SortItem } from './SortItem';
+import { SortConditionPB } from '@/services/backend';
+
+export const SortMenu: FC<MenuProps> = (props) => {
+ const { onClose } = props;
+
+ const viewId = useViewId();
+ const { sorts } = useDatabase();
+ const [ anchorEl, setAnchorEl ] = useState<HTMLElement | null>(null);
+
+ const handleClick = useCallback<MouseEventHandler<HTMLElement>>((event) => {
+ setAnchorEl(event.currentTarget);
+ }, []);
+
+ const handleClose = useCallback(() => {
+ setAnchorEl(null);
+ }, []);
+
+ const deleteAllSorts = useCallback(() => {
+ void sortService.deleteAllSorts(viewId);
+ onClose?.({}, 'backdropClick');
+ }, [viewId, onClose]);
+
+ const addSort = useCallback((event: MouseEvent, field: Field) => {
+ void sortService.insertSort(viewId, {
+ fieldId: field.id,
+ fieldType: field.type,
+ condition: SortConditionPB.Ascending,
+ });
+ }, [viewId]);
+
+ return (
+ <>
+ <Menu {...props}>
+ {sorts.map(sort => (
+ <SortItem key={sort.id} className="mx-2" sort={sort} />
+ ))}
+ <MenuItem onClick={handleClick}>
+ Add sort
+ </MenuItem>
+ <MenuItem onClick={deleteAllSorts}>
+ Delete sort
+ </MenuItem>
+ </Menu>
+ <FieldsMenu
+ open={anchorEl !== null}
+ anchorEl={anchorEl}
+ onClose={handleClose}
+ onMenuItemClick={addSort}
+ />
+ </>
+ );
+};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/components/sort/Sorts.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/sort/Sorts.tsx
new file mode 100644
index 0000000000..4651d21b5f
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/sort/Sorts.tsx
@@ -0,0 +1,37 @@
+import { Chip } from '@mui/material';
+import { FC, MouseEventHandler, useCallback, useState } from 'react';
+import { Sort } from '../../application';
+import { SortMenu } from './SortMenu';
+
+export interface SortsProps {
+ sorts: Readonly<Sort>[];
+}
+
+export const Sorts: FC<SortsProps> = ({
+ sorts,
+}) => {
+ const [ anchorEl, setAnchorEl ] = useState<HTMLElement | null>(null);
+ const handleClick = useCallback<MouseEventHandler<HTMLElement>>((event) => {
+ setAnchorEl(event.currentTarget);
+ }, []);
+
+ const label = sorts.length === 1
+ ? (<div>1 sort</div>)
+ : (<div>{sorts.length} sorts</div>);
+
+ return (
+ <>
+ <Chip
+ clickable
+ variant="outlined"
+ label={label}
+ onClick={handleClick}
+ />
+ <SortMenu
+ open={anchorEl !== null}
+ anchorEl={anchorEl}
+ onClose={() => setAnchorEl(null)}
+ />
+ </>
+ );
+};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/components/sort/index.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/sort/index.ts
new file mode 100644
index 0000000000..e64dba3a6e
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/sort/index.ts
@@ -0,0 +1,2 @@
+export * from './SortMenu';
+export * from './Sorts';
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/components/tab_bar/DatabaseTabBar.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/tab_bar/DatabaseTabBar.tsx
new file mode 100644
index 0000000000..1cfacbb5ad
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/tab_bar/DatabaseTabBar.tsx
@@ -0,0 +1,64 @@
+import { FC, MouseEventHandler, useCallback, useState } from 'react';
+import { t } from 'i18next';
+import { IconButton, Stack } from '@mui/material';
+import { ReactComponent as AddSvg } from '$app/assets/add.svg';
+import { DatabaseView } from '../../application';
+import { useSelectDatabaseView } from '../../Database.hooks';
+import { ViewTabs, ViewTab } from './ViewTabs';
+import { TextButton } from './TextButton';
+import { SortMenu } from '../sort';
+
+export interface DatabaseTabBarProps {
+ views: DatabaseView[];
+}
+
+export const DatabaseTabBar: FC<DatabaseTabBarProps> = ({
+ views,
+}) => {
+ const [selectedViewId, selectViewId] = useSelectDatabaseView();
+ const [sortAnchorEl, setSortAnchorEl] = useState<null | HTMLElement>(null);
+ const open = Boolean(sortAnchorEl);
+
+ const handleChange = (event: React.SyntheticEvent, newValue: string) => {
+ selectViewId(newValue);
+ };
+
+ const handleClick = useCallback<MouseEventHandler<HTMLElement>>((event) => {
+ setSortAnchorEl(event.currentTarget);
+ }, []);
+
+ const handleClose = () => {
+ setSortAnchorEl(null);
+ };
+
+ return (
+ <div className="flex items-center -mb-px">
+ <div className='flex flex-1 items-center'>
+ <ViewTabs value={selectedViewId} onChange={handleChange}>
+ {views.map(view => (
+ <ViewTab
+ key={view.id}
+ icon={undefined}
+ iconPosition="start"
+ color="inherit"
+ label={view.name}
+ value={view.id}
+ />
+ ))}
+ </ViewTabs>
+ <IconButton size="small">
+ <AddSvg />
+ </IconButton>
+ </div>
+ <Stack className="text-neutral-500" direction="row" spacing="2px">
+ <TextButton color="inherit">
+ {t('grid.settings.filter')}
+ </TextButton>
+ <TextButton color="inherit" onClick={handleClick}>
+ {t('grid.settings.sort')}
+ </TextButton>
+ <SortMenu open={open} anchorEl={sortAnchorEl} onClose={handleClose} />
+ </Stack>
+ </div>
+ );
+};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/components/tab_bar/TextButton.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/tab_bar/TextButton.tsx
new file mode 100644
index 0000000000..60dfaa2e53
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/tab_bar/TextButton.tsx
@@ -0,0 +1,9 @@
+import { Button, ButtonProps, styled } from '@mui/material';
+
+export const TextButton = styled(Button)<ButtonProps>(() => ({
+ padding: '2px 6px',
+ fontSize: '0.75rem',
+ lineHeight: '1rem',
+ fontWeight: 400,
+ minWidth: 'unset',
+}));
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/components/tab_bar/ViewTabs.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/tab_bar/ViewTabs.tsx
new file mode 100644
index 0000000000..4b1e3aea55
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/tab_bar/ViewTabs.tsx
@@ -0,0 +1,21 @@
+import { styled, Tab, TabProps, Tabs } from '@mui/material';
+
+export const ViewTabs = styled(Tabs)({
+ minHeight: '28px',
+
+ '& .MuiTabs-scroller': {
+ paddingBottom: '2px',
+ }
+});
+
+export const ViewTab = styled((props: TabProps) => <Tab disableRipple {...props} />)({
+ padding: '6px 12px',
+ minHeight: '28px',
+ fontSize: '12px',
+ lineHeight: '16px',
+ minWidth: 'unset',
+
+ '&.Mui-selected': {
+ color: 'inherit',
+ },
+});
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/components/tab_bar/index.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/tab_bar/index.ts
new file mode 100644
index 0000000000..fc0c62963e
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/components/tab_bar/index.ts
@@ -0,0 +1 @@
+export * from './DatabaseTabBar';
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/database.context.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/database.context.ts
deleted file mode 100644
index 7ce61fd06d..0000000000
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/database.context.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-import { RefObject, createContext, createRef } from 'react';
-import { proxy } from 'valtio';
-import { Database } from '$app/interfaces/database';
-import { DatabaseLayoutPB } from '@/services/backend';
-
-export const VerticalScrollElementRefContext = createContext<RefObject<Element>>(createRef());
-export const DatabaseContext = createContext<Database>(proxy({
- id: '',
- viewId: '',
- name: '',
- fields: [],
- rows: [],
- layoutType: DatabaseLayoutPB.Grid,
- layoutSetting: {},
- isLinked: false,
-}));
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/database.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/database.hooks.ts
deleted file mode 100644
index 78c1f7d8c3..0000000000
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/database.hooks.ts
+++ /dev/null
@@ -1,138 +0,0 @@
-import { useContext, useEffect, useMemo } from 'react';
-import { proxy, useSnapshot } from 'valtio';
-import { useParams } from 'react-router-dom';
-import { DatabaseLayoutPB, DatabaseNotification } from '@/services/backend';
-import { type Database, fieldPbToField } from '$app/interfaces/database';
-import { subscribeNotifications } from '$app/hooks';
-import { DatabaseContext } from './database.context';
-import * as service from './database_bd_svc';
-
-export const useDatabase = () => useSnapshot(useContext(DatabaseContext));
-export const useViewId = () => useParams().id!;
-
-const fetchDatabase = async (viewId: string) => {
- const [
- databasePb,
- settingPb,
- ] = await Promise.all([
- service.getDatabase(viewId),
- service.getDatabaseSetting(viewId),
- ]);
-
- const fieldsPb = await service.getFields(viewId, databasePb.fields.map(field => field.field_id));
-
- const database: Database = {
- id: databasePb.id,
- viewId: viewId,
- name: '',
- layoutType: databasePb.layout_type,
- layoutSetting: {},
- isLinked: databasePb.is_linked,
- fields: fieldsPb.map(fieldPbToField),
- rows: databasePb.rows.map(row => ({
- id: row.id,
- documentId: row.document_id,
- icon: row.icon,
- cover: row.cover,
- })),
- };
-
- if (settingPb.layout_type === DatabaseLayoutPB.Grid) {
- const layoutSetting: Database.GridLayoutSetting = {};
-
- if (settingPb.has_filters) {
- layoutSetting.filters = settingPb.filters.items.map(filter => ({
- id: filter.id,
- fieldId: filter.field_id,
- fieldType: filter.field_type,
- data: filter.data,
- }));
- }
-
- if (settingPb.has_sorts) {
- layoutSetting.sorts = settingPb.sorts.items.map(sort => ({
- id: sort.id,
- fieldId: sort.field_id,
- fieldType: sort.field_type,
- condition: sort.condition,
- }));
- }
-
- if (settingPb.has_group_settings) {
- layoutSetting.groups = settingPb.group_settings.items.map(group => ({
- id: group.id,
- fieldId: group.field_id,
- }));
- }
-
- database.layoutSetting = layoutSetting;
- }
-
- return database;
-};
-
-export const useConnectDatabase = (viewId: string) => {
- const database = useMemo(() => {
- const proxyDatabase = proxy<Database>({
- id: '',
- viewId,
- name: '',
- isLinked: false,
- layoutType: DatabaseLayoutPB.Grid,
- layoutSetting: {},
- rows: [],
- fields: [],
- });
-
- void fetchDatabase(viewId).then(value => Object.assign(proxyDatabase, value));
-
- return proxyDatabase;
- }, [viewId]);
-
- useEffect(() => {
- const unsubscribePromise = subscribeNotifications({
- [DatabaseNotification.DidUpdateFields]: async (result) => {
- if (result.err) {
- return;
- }
-
- const { fields: fieldIds } = await service.getDatabase(viewId);
- const newFieldsPb = await service.getFields(viewId, fieldIds.map(field => field.field_id));
-
- database.fields = newFieldsPb.map(fieldPbToField);
- },
- [DatabaseNotification.DidUpdateViewRows]:async (result) => {
- if (result.err) {
- return;
- }
-
- const {
- deleted_rows: deletedRowIds,
- inserted_rows: insertedRows,
- // TODO: updated_rows: updatedRows,
- } = result.val;
-
- deletedRowIds.forEach(rowId => {
- const index = database.rows.findIndex(row => row.id === rowId);
-
- if (index !== -1) {
- database.rows.splice(index, 1);
- }
- });
-
- insertedRows.forEach(({ index, row_meta: rowMeta }) => {
- database.rows.splice(index, 0, {
- id: rowMeta.id,
- documentId: rowMeta.document_id,
- cover: rowMeta.cover,
- icon: rowMeta.icon,
- });
- });
- }
- }, { id: viewId });
-
- return () => void unsubscribePromise.then(unsubscribe => unsubscribe());
- }, [viewId, database]);
-
- return database;
-};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/database_bd_svc.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/database_bd_svc.ts
deleted file mode 100644
index 518a4f493d..0000000000
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/database_bd_svc.ts
+++ /dev/null
@@ -1,698 +0,0 @@
-import { Database } from '$app/interfaces/database';
-import {
- DatabaseDescriptionPB,
- DatabasePB,
- DatabaseViewIdPB,
- DatabaseViewSettingPB,
- DatabaseLayoutPB,
- CreateDatabaseViewPayloadPB,
- DatabaseLayoutMetaPB,
- LayoutSettingChangesetPB,
- GroupPB,
- DatabaseGroupIdPB,
- GroupByFieldPayloadPB,
- UpdateGroupPB,
- MoveGroupPayloadPB,
- FieldPB,
- GetFieldPayloadPB,
- RepeatedFieldIdPB,
- DuplicateFieldPayloadPB,
- FieldChangesetPB,
- FieldType,
- UpdateFieldTypePayloadPB,
- MoveFieldPayloadPB,
- DeleteFieldPayloadPB,
- TypeOptionPB,
- TypeOptionPathPB,
- CreateFieldPayloadPB,
- TypeOptionChangesetPB,
- SelectOptionPB,
- CreateSelectOptionPayloadPB,
- RepeatedSelectOptionPayload,
- RowIdPB,
- RowMetaPB,
- CreateRowPayloadPB,
- MoveGroupRowPayloadPB,
- UpdateRowMetaChangesetPB,
- CellPB,
- CellIdPB,
- CellChangesetPB,
- SelectOptionCellDataPB,
- SelectOptionCellChangesetPB,
- ChecklistCellDataPB,
- ChecklistCellDataChangesetPB,
- DateChangesetPB,
- DatabaseLayoutSettingPB,
- RowPB,
- DatabaseExportDataPB,
- DatabaseSnapshotPB,
- FilterPB,
- SortPB,
- MoveRowPayloadPB,
-} from '@/services/backend';
-import {
- DatabaseEventGetDatabases,
- DatabaseEventGetDatabase,
- DatabaseEventGetDatabaseSetting,
- DatabaseEventCreateDatabaseView,
- DatabaseEventGetLayoutSetting,
- DatabaseEventSetLayoutSetting,
- DatabaseEventGetGroups,
- DatabaseEventGetGroup,
- DatabaseEventSetGroupByField,
- DatabaseEventUpdateGroup,
- DatabaseEventMoveGroup,
- DatabaseEventGetFields,
- DatabaseEventGetPrimaryField,
- DatabaseEventDuplicateField,
- DatabaseEventUpdateField,
- DatabaseEventUpdateFieldType,
- DatabaseEventMoveField,
- DatabaseEventDeleteField,
- DatabaseEventGetTypeOption,
- DatabaseEventCreateTypeOption,
- DatabaseEventUpdateFieldTypeOption,
- DatabaseEventCreateSelectOption,
- DatabaseEventInsertOrUpdateSelectOption,
- DatabaseEventDeleteSelectOption,
- DatabaseEventGetRow,
- DatabaseEventCreateRow,
- DatabaseEventDuplicateRow,
- DatabaseEventDeleteRow,
- DatabaseEventMoveGroupRow,
- DatabaseEventGetRowMeta,
- DatabaseEventUpdateRowMeta,
- DatabaseEventGetCell,
- DatabaseEventUpdateCell,
- DatabaseEventGetSelectOptionCellData,
- DatabaseEventUpdateSelectOptionCell,
- DatabaseEventUpdateChecklistCell,
- DatabaseEventUpdateDateCell,
- DatabaseEventExportCSV,
- DatabaseEventGetDatabaseSnapshots,
- DatabaseEventGetAllFilters,
- DatabaseEventGetAllSorts,
- DatabaseEventMoveRow,
-} from "@/services/backend/events/flowy-database2";
-
-export async function getDatabases(): Promise<DatabaseDescriptionPB[]> {
- const result = await DatabaseEventGetDatabases();
-
- return result.map(value => value.items).unwrap();
-}
-
-export async function getDatabase(viewId: string): Promise<DatabasePB> {
- const payload = DatabaseViewIdPB.fromObject({
- value: viewId,
- });
-
- const result = await DatabaseEventGetDatabase(payload);
-
- return result.unwrap();
-}
-
-export async function getDatabaseSetting(viewId: string): Promise<DatabaseViewSettingPB> {
- const payload = DatabaseViewIdPB.fromObject({
- value: viewId,
- });
-
- const result = await DatabaseEventGetDatabaseSetting(payload);
-
- return result.unwrap();
-}
-
-export async function createDatabaseView(
- viewId: string,
- data?: {
- name?: string;
- layout?: DatabaseLayoutPB;
- },
-): Promise<void> {
- const payload = CreateDatabaseViewPayloadPB.fromObject({
- view_id: viewId,
- name: data?.name,
- layout_type: data?.layout,
- });
-
- const result = await DatabaseEventCreateDatabaseView(payload);
-
- return result.unwrap();
-}
-
-export async function getLayoutSetting(viewId: string, layout: DatabaseLayoutPB): Promise<DatabaseLayoutSettingPB> {
- const payload = DatabaseLayoutMetaPB.fromObject({
- view_id: viewId,
- layout: layout,
- });
-
- const result = await DatabaseEventGetLayoutSetting(payload);
-
- return result.unwrap();
-}
-
-export async function setLayoutSetting(viewId: string, setting: {
- layoutType?: DatabaseLayoutPB;
- calendar?: Database.CalendarLayoutSetting;
-}): Promise<void> {
- const payload = LayoutSettingChangesetPB.fromObject({
- view_id: viewId,
- layout_type: setting.layoutType,
- calendar: setting.calendar ? {
- field_id: setting.calendar.fieldId,
- layout_ty: setting.calendar.layoutTy,
- first_day_of_week: setting.calendar.firstDayOfWeek,
- show_weekends: setting.calendar.showWeekends,
- show_week_numbers: setting.calendar.showWeekNumbers,
- } : undefined,
- });
-
- const result = await DatabaseEventSetLayoutSetting(payload);
-
- return result.unwrap();
-}
-
-export async function getGroups(viewId: string): Promise<GroupPB[]> {
- const payload = DatabaseViewIdPB.fromObject({
- value: viewId,
- });
-
- const result = await DatabaseEventGetGroups(payload);
-
- return result.map(value => value.items).unwrap();
-}
-
-export async function getGroup(viewId: string, groupId: string): Promise<GroupPB> {
- const payload = DatabaseGroupIdPB.fromObject({
- view_id: viewId,
- group_id: groupId,
- });
-
- const result = await DatabaseEventGetGroup(payload);
-
- return result.unwrap();
-}
-
-export async function setGroupByField(viewId: string, fieldId: string): Promise<void> {
- const payload = GroupByFieldPayloadPB.fromObject({
- view_id: viewId,
- field_id: fieldId,
- });
-
- const result = await DatabaseEventSetGroupByField(payload);
-
- return result.unwrap();
-}
-
-export async function updateGroup(
- viewId: string,
- groupId: string,
- data: {
- name?: string;
- visible?: boolean;
- },
-): Promise<void> {
- const payload = UpdateGroupPB.fromObject({
- view_id: viewId,
- group_id: groupId,
- name: data.name,
- visible: data.visible,
- });
-
- const result = await DatabaseEventUpdateGroup(payload);
-
- return result.unwrap();
-}
-
-export async function moveGroup(viewId: string, fromGroupId: string, toGroupId: string): Promise<void> {
- const payload = MoveGroupPayloadPB.fromObject({
- view_id: viewId,
- from_group_id: fromGroupId,
- to_group_id: toGroupId,
- });
-
- const result = await DatabaseEventMoveGroup(payload);
-
- return result.unwrap();
-}
-
-
-export async function getFilters(viewId: string): Promise<FilterPB[]> {
- const payload = DatabaseViewIdPB.fromObject({
- value: viewId,
- });
-
- const result = await DatabaseEventGetAllFilters(payload);
-
- return result.map(value => value.items).unwrap();
-}
-
-
-export async function getSorts(viewId: string): Promise<SortPB[]> {
- const payload = DatabaseViewIdPB.fromObject({
- value: viewId,
- });
-
- const result = await DatabaseEventGetAllSorts(payload);
-
- return result.map(value => value.items).unwrap();
-}
-
-
-export async function getFields(viewId: string, fieldIds?: string[]): Promise<FieldPB[]> {
- const payload = GetFieldPayloadPB.fromObject({
- view_id: viewId,
- field_ids: fieldIds ? RepeatedFieldIdPB.fromObject({
- items: fieldIds.map(fieldId => ({ field_id: fieldId })),
- }) : undefined,
- });
-
- const result = await DatabaseEventGetFields(payload);
-
- return result.map((value) => value.items).unwrap();
-}
-
-export async function getPrimaryField(viewId: string): Promise<FieldPB> {
- const payload = DatabaseViewIdPB.fromObject({
- value: viewId,
- });
-
- const result = await DatabaseEventGetPrimaryField(payload);
-
- return result.unwrap();
-}
-
-export async function duplicateField(viewId: string, fieldId: string): Promise<void> {
- const payload = DuplicateFieldPayloadPB.fromObject({
- view_id: viewId,
- field_id: fieldId,
- });
-
- const result = await DatabaseEventDuplicateField(payload);
-
- return result.unwrap();
-}
-
-export async function updateField(viewId: string, fieldId: string, data: {
- name?: string;
- desc?: string;
- frozen?: boolean;
- visibility?: boolean;
- width?: number;
-}): Promise<void> {
- const payload = FieldChangesetPB.fromObject({
- view_id: viewId,
- field_id: fieldId,
- ...data,
- });
-
- const result = await DatabaseEventUpdateField(payload);
-
- return result.unwrap();
-}
-
-export async function updateFieldType(viewId: string, fieldId: string, fieldType: FieldType): Promise<void> {
- const payload = UpdateFieldTypePayloadPB.fromObject({
- view_id: viewId,
- field_id: fieldId,
- field_type: fieldType,
- });
-
- const result = await DatabaseEventUpdateFieldType(payload);
-
- return result.unwrap();
-}
-
-export async function moveField(viewId: string, fieldId: string, fromIndex: number, toIndex: number): Promise<void> {
- const payload = MoveFieldPayloadPB.fromObject({
- view_id: viewId,
- field_id: fieldId,
- from_index: fromIndex,
- to_index: toIndex,
- });
-
- const result = await DatabaseEventMoveField(payload);
-
- return result.unwrap();
-}
-
-export async function deleteField(viewId: string, fieldId: string): Promise<void> {
- const payload = DeleteFieldPayloadPB.fromObject({
- view_id: viewId,
- field_id: fieldId,
- });
-
- const result = await DatabaseEventDeleteField(payload);
-
- return result.unwrap();
-}
-
-
-export async function getFieldTypeOption(viewId: string, fieldId: string, fieldType?: FieldType): Promise<TypeOptionPB> {
- const payload = TypeOptionPathPB.fromObject({
- view_id: viewId,
- field_id: fieldId,
- field_type: fieldType,
- });
-
- const result = await DatabaseEventGetTypeOption(payload);
-
- return result.unwrap();
-}
-
-/**
- * TODO data type need to clarify
- */
-export async function createFieldTypeOption(viewId: string, fieldType: FieldType, data?: Uint8Array): Promise<TypeOptionPB> {
- const payload = CreateFieldPayloadPB.fromObject({
- view_id: viewId,
- field_type: fieldType,
- type_option_data: data,
- });
-
- const result = await DatabaseEventCreateTypeOption(payload);
-
- return result.unwrap();
-}
-
-/**
- * TODO data type need to clarify
- */
-export async function updateFieldTypeOption(viewId: string, fieldId: string, data: Uint8Array): Promise<void> {
- const payload = TypeOptionChangesetPB.fromObject({
- view_id: viewId,
- field_id: fieldId,
- type_option_data: data,
- });
-
- const result = await DatabaseEventUpdateFieldTypeOption(payload);
-
- return result.unwrap();
-}
-
-export async function createSelectOption(viewId: string, fieldId: string, optionName: string): Promise<SelectOptionPB> {
- const payload = CreateSelectOptionPayloadPB.fromObject({
- view_id: viewId,
- field_id: fieldId,
- option_name: optionName,
- });
-
- const result = await DatabaseEventCreateSelectOption(payload);
-
- return result.unwrap();
-}
-
-/**
- * @param [rowId] If pass the rowId, the cell will select this option after insert or update.
- */
-export async function insertOrUpdateSelectOption(
- viewId: string,
- fieldId: string,
- items: Partial<Database.SelectOption>[],
- rowId?: string,
-): Promise<void> {
- const payload = RepeatedSelectOptionPayload.fromObject({
- view_id: viewId,
- field_id: fieldId,
- row_id: rowId,
- items: items,
- });
-
- const result = await DatabaseEventInsertOrUpdateSelectOption(payload);
-
- return result.unwrap();
-}
-
-export async function deleteSelectOption(
- viewId: string,
- fieldId: string,
- items: Partial<Database.SelectOption>[],
- rowId?: string,
-): Promise<void> {
- const payload = RepeatedSelectOptionPayload.fromObject({
- view_id: viewId,
- field_id: fieldId,
- row_id: rowId,
- items: items,
- });
-
- const result = await DatabaseEventDeleteSelectOption(payload);
-
- return result.unwrap();
-}
-
-
-export async function getRow(viewId: string, rowId: string, groupId?: string): Promise<RowPB | undefined> {
- const payload = RowIdPB.fromObject({
- view_id: viewId,
- row_id: rowId,
- group_id: groupId,
- });
-
- const result = await DatabaseEventGetRow(payload);
-
- return result.map(value => value.row).unwrap();
-}
-
-export async function createRow(viewId: string, params?: {
- startRowId?: string;
- groupId?: string;
- data?: Record<string, string>;
-}): Promise<RowMetaPB> {
- const payload = CreateRowPayloadPB.fromObject({
- view_id: viewId,
- start_row_id: params?.startRowId,
- group_id: params?.groupId,
- data: params?.data ? { cell_data_by_field_id: params.data } : undefined,
- });
-
- const result = await DatabaseEventCreateRow(payload);
-
- return result.unwrap();
-}
-
-export async function duplicateRow(viewId: string, rowId: string, groupId?: string): Promise<void> {
- const payload = RowIdPB.fromObject({
- view_id: viewId,
- row_id: rowId,
- group_id: groupId,
- });
-
- const result = await DatabaseEventDuplicateRow(payload);
-
- return result.unwrap();
-}
-
-export async function deleteRow(viewId: string, rowId: string, groupId?: string): Promise<void> {
- const payload = RowIdPB.fromObject({
- view_id: viewId,
- row_id: rowId,
- group_id: groupId,
- });
-
- const result = await DatabaseEventDeleteRow(payload);
-
- return result.unwrap();
-}
-
-export async function moveRow(viewId: string, fromRowId: string, toRowId: string): Promise<void> {
- const payload = MoveRowPayloadPB.fromObject({
- view_id: viewId,
- from_row_id: fromRowId,
- to_row_id: toRowId,
- });
-
- const result = await DatabaseEventMoveRow(payload);
-
- return result.unwrap();
-}
-
-/**
- * Move the row from one group to another group
- *
- * @param fromRowId
- * @param toGroupId
- * @param toRowId used to locate the moving row location.
- * @returns
- */
-export async function moveGroupRow(viewId: string, fromRowId: string, toGroupId: string, toRowId?: string): Promise<void> {
- const payload = MoveGroupRowPayloadPB.fromObject({
- view_id: viewId,
- from_row_id: fromRowId,
- to_group_id: toGroupId,
- to_row_id: toRowId,
- });
-
- const result = await DatabaseEventMoveGroupRow(payload);
-
- return result.unwrap();
-}
-
-
-export async function getRowMeta(viewId: string, rowId: string, groupId?: string): Promise<RowMetaPB> {
- const payload = RowIdPB.fromObject({
- view_id: viewId,
- row_id: rowId,
- group_id: groupId,
- });
-
- const result = await DatabaseEventGetRowMeta(payload);
-
- return result.unwrap();
-}
-
-export async function updateRowMeta(
- viewId: string,
- rowId: string,
- meta: {
- iconUrl?: string;
- coverUrl?: string;
- },
-): Promise<void> {
- const payload = UpdateRowMetaChangesetPB.fromObject({
- view_id: viewId,
- id: rowId,
- icon_url: meta.iconUrl,
- cover_url: meta.coverUrl,
- });
-
- const result = await DatabaseEventUpdateRowMeta(payload);
-
- return result.unwrap();
-}
-
-
-export async function getCell(viewId: string, rowId: string, fieldId: string): Promise<CellPB> {
- const payload = CellIdPB.fromObject({
- view_id: viewId,
- row_id: rowId,
- field_id: fieldId,
- });
-
- const result = await DatabaseEventGetCell(payload);
-
- return result.unwrap();
-}
-
-export async function updateCell(viewId: string, rowId: string, fieldId: string, changeset: string): Promise<void> {
- const payload = CellChangesetPB.fromObject({
- view_id: viewId,
- row_id: rowId,
- field_id: fieldId,
- cell_changeset: changeset,
- });
-
- const result = await DatabaseEventUpdateCell(payload);
-
- return result.unwrap();
-}
-
-export async function getSelectOptionCell(viewId: string, rowId: string, fieldId: string): Promise<SelectOptionCellDataPB> {
- const payload = CellIdPB.fromObject({
- view_id: viewId,
- row_id: rowId,
- field_id: fieldId,
- });
-
- const result = await DatabaseEventGetSelectOptionCellData(payload);
-
- return result.unwrap();
-}
-
-export async function updateSelectOptionCell(
- viewId: string,
- rowId: string,
- fieldId: string,
- data: {
- insertOptionIds?: string[];
- deleteOptionIds?: string[];
- },
-): Promise<void> {
- const payload = SelectOptionCellChangesetPB.fromObject({
- cell_identifier: {
- view_id: viewId,
- row_id: rowId,
- field_id: fieldId,
- },
- insert_option_ids: data.insertOptionIds,
- delete_option_ids: data.deleteOptionIds,
- });
-
- const result = await DatabaseEventUpdateSelectOptionCell(payload);
-
- return result.unwrap();
-}
-
-export async function updateChecklistCell(
- viewId: string,
- rowId: string,
- fieldId: string,
- data: {
- insertOptions?: string[];
- selectedOptionIds?: string[];
- deleteOptionIds?: string[];
- updateOptions?: Partial<Database.SelectOption>[];
- },
-): Promise<void> {
- const payload = ChecklistCellDataChangesetPB.fromObject({
- view_id: viewId,
- row_id: rowId,
- field_id: fieldId,
- insert_options: data.insertOptions,
- selected_option_ids: data.selectedOptionIds,
- delete_option_ids: data.deleteOptionIds,
- update_options: data.updateOptions,
- });
-
- const result = await DatabaseEventUpdateChecklistCell(payload);
-
- return result.unwrap();
-}
-
-export async function updateDateCell(
- viewId: string,
- rowId: string,
- fieldId: string,
- data: {
- date?: number;
- time?: string;
- includeTime?: boolean;
- clearFlag?: boolean;
- },
-): Promise<void> {
- const payload = DateChangesetPB.fromObject({
- cell_id: {
- view_id: viewId,
- row_id: rowId,
- field_id: fieldId,
- },
- date: data.date,
- time: data.time,
- include_time: data.includeTime,
- clear_flag: data.clearFlag,
- });
-
- const result = await DatabaseEventUpdateDateCell(payload);
-
- return result.unwrap();
-}
-
-
-export async function exportCSV(viewId: string): Promise<DatabaseExportDataPB> {
- const payload = DatabaseViewIdPB.fromObject({
- value: viewId,
- });
-
- const result = await DatabaseEventExportCSV(payload);
-
- return result.unwrap();
-}
-
-export async function getDatabaseSnapshots(viewId: string): Promise<DatabaseSnapshotPB[]> {
- const payload = DatabaseViewIdPB.fromObject({
- value: viewId,
- });
-
- const result = await DatabaseEventGetDatabaseSnapshots(payload);
-
- return result.map(value => value.items).unwrap();
-}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/Grid/Grid.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/Grid/Grid.tsx
index 5ac96c4109..4bb1dea823 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/Grid/Grid.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/Grid/Grid.tsx
@@ -1,12 +1,8 @@
import { FC } from 'react';
-import { GridToolbar } from '../GridToolbar';
-import { GridTable } from '../GridTable/GridTable';
+import { GridTable } from '../GridTable';
export const Grid: FC = () => {
return (
- <>
- <GridToolbar />
- <GridTable />
- </>
+ <GridTable />
);
-};
\ No newline at end of file
+};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridCell.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridCell.hooks.ts
deleted file mode 100644
index 9c9591f14e..0000000000
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridCell.hooks.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-import { useCallback, useEffect, useState } from 'react';
-import { Result } from 'ts-results';
-import { DatabaseNotification, FieldType, FlowyError } from '@/services/backend';
-import { Database, cellPbToCell } from '$app/interfaces/database';
-import * as service from '$app/components/database/database_bd_svc';
-import { useNotification } from '$app/hooks';
-import { useViewId } from '../../database.hooks';
-
-export const useCell = (rowId: string, fieldId: string, fieldType: FieldType) => {
- const viewId = useViewId();
- const [cell, setCell] = useState<Database.Cell | null>(null);
-
- const fetchCell = useCallback(() => {
- void service.getCell(viewId, rowId, fieldId).then(data => {
- setCell(cellPbToCell(data, fieldType));
- });
- }, [viewId, rowId, fieldId, fieldType]);
-
- useEffect(() => {
- void fetchCell();
- }, [fetchCell]);
-
- const didUpdateCell = useCallback((result: Result<void, FlowyError>) => {
- if (result.err) {
- return;
- }
-
- void fetchCell();
- }, [fetchCell]);
-
- useNotification(DatabaseNotification.DidUpdateCell, didUpdateCell, { id: `${rowId}:${fieldId}` });
-
- return cell;
-};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridCell.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridCell.tsx
index 08e002590d..d8a4727674 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridCell.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridCell.tsx
@@ -1,38 +1,6 @@
-import { FC, useMemo } from 'react';
-import { Database } from '$app/interfaces/database';
-import { FieldType } from '@/services/backend';
+import { FC } from 'react';
+import { Cell, CellProps } from '../../components';
-import { GridTextCell } from './GridTextCell';
-import { GridNotSupportedCell } from './GridNotSupportedCell';
-import { GridSelectCell } from './GridSelectCell';
-import { useCell } from './GridCell.hooks';
-import { GridCheckboxCell } from './GridCheckboxCell';
-
-interface GridCellProps {
- rowId: string;
- field: Database.Field;
-}
-
-export const GridCell: FC<GridCellProps> = ({
- rowId,
- field,
-}) => {
- const cell = useCell(rowId, field.id, field.type);
-
- const RenderCell = useMemo(() => {
- switch (field.type) {
- case FieldType.RichText:
- return GridTextCell;
- case FieldType.SingleSelect:
- case FieldType.MultiSelect:
- return GridSelectCell;
- case FieldType.Checkbox:
- return GridCheckboxCell;
- default:
- return GridNotSupportedCell;
- }
- }, [field.type]);
-
- // TODO: find a better way to check cell type.
- return <RenderCell rowId={rowId} field={field} cell={cell as any} />;
+export const GridCell: FC<CellProps> = (props) => {
+ return <Cell {...props} />;
};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridCheckboxCell.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridCheckboxCell.tsx
deleted file mode 100644
index 75a177825e..0000000000
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridCheckboxCell.tsx
+++ /dev/null
@@ -1,31 +0,0 @@
-import { Database } from '$app/interfaces/database';
-import { Checkbox } from '@mui/material';
-import { FC, useCallback } from 'react';
-import { ReactComponent as CheckboxCheckSvg } from '$app/assets/database/checkbox-check.svg';
-import { ReactComponent as CheckboxUncheckSvg } from '$app/assets/database/checkbox-uncheck.svg';
-import * as service from '$app/components/database/database_bd_svc';
-import { useViewId } from '../../database.hooks';
-
-export const GridCheckboxCell: FC<{
- rowId: string;
- cell: Database.CheckboxCell | null,
- field: Database.Field,
-}> = ({ rowId, field, cell }) => {
- const viewId = useViewId();
- const handleChange = useCallback((event: React.ChangeEvent<HTMLInputElement>, checked: boolean) => {
- void service.updateCell(viewId, rowId, field.id, checked ? 'Yes' : 'No');
- }, [viewId, rowId, field.id ]);
-
- return (
- <div className="flex items-center px-2">
- <Checkbox
- disableRipple
- style={{ padding: 0 }}
- checked={cell?.data === 'Yes'}
- icon={<CheckboxUncheckSvg />}
- checkedIcon={<CheckboxCheckSvg />}
- onChange={handleChange}
- />
- </div>
- );
-};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridNotSupportedCell.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridNotSupportedCell.tsx
deleted file mode 100644
index f846a4862f..0000000000
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridNotSupportedCell.tsx
+++ /dev/null
@@ -1,5 +0,0 @@
-import { FC } from 'react';
-
-export const GridNotSupportedCell: FC = () => {
- return null
-};
\ No newline at end of file
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridSelectCell/index.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridSelectCell/index.ts
deleted file mode 100644
index 906ebf8552..0000000000
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/GridSelectCell/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from './GridSelectCell';
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/index.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/index.ts
index 6a6bbcc986..2b6d663ef5 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/index.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridCell/index.ts
@@ -1 +1 @@
-export * from './GridCell';
\ No newline at end of file
+export * from './GridCell';
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridField/FieldTypeSvg.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridField/FieldTypeSvg.tsx
index 50968358de..df5615b998 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridField/FieldTypeSvg.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridField/FieldTypeSvg.tsx
@@ -10,7 +10,7 @@ import { ReactComponent as CheckboxSvg } from '$app/assets/database/field-type-c
import { ReactComponent as URLSvg } from '$app/assets/database/field-type-url.svg';
import { ReactComponent as LastEditedTimeSvg } from '$app/assets/database/field-type-last-edited-time.svg';
-export const FieldTypeSvgMap: Record<FieldType, FC<any>> = {
+export const FieldTypeSvgMap: Record<FieldType, FC<{ className?: string }>> = {
[FieldType.RichText]: TextSvg,
[FieldType.Number]: NumberSvg,
[FieldType.DateTime]: DateSvg,
@@ -23,8 +23,8 @@ export const FieldTypeSvgMap: Record<FieldType, FC<any>> = {
[FieldType.CreatedTime]: LastEditedTimeSvg,
};
-export const FieldTypeSvg: FC<{ type: FieldType, className?: string }> = ({ type, ...props }) => {
+export const FieldTypeSvg: FC<{ type: FieldType; className?: string }> = ({ type, ...props }) => {
const Svg = FieldTypeSvgMap[type];
return <Svg {...props} />;
-}
\ No newline at end of file
+};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridField/GridField.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridField/GridField.tsx
index a7ecf227f7..bef24ebe22 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridField/GridField.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridField/GridField.tsx
@@ -1,15 +1,15 @@
import { Button, Tooltip } from '@mui/material';
import { DragEventHandler, FC, useCallback, useMemo, useState } from 'react';
-import { Database } from '$app/interfaces/database';
import { throttle } from '$app/utils/tool';
+import { useViewId } from '$app/hooks';
import { DragItem, DropPosition, DragType, useDraggable, useDroppable, ScrollDirection } from '../../_shared';
-import * as service from '../../database_bd_svc';
-import { useDatabase, useViewId } from '../../database.hooks';
+import { fieldService, Field } from '../../application';
+import { useDatabase } from '../../Database.hooks';
import { FieldTypeSvg } from './FieldTypeSvg';
import { GridFieldMenu } from './GridFieldMenu';
export interface GridFieldProps {
- field: Database.Field;
+ field: Field;
}
export const GridField: FC<GridFieldProps> = ({ field }) => {
@@ -69,7 +69,7 @@ export const GridField: FC<GridFieldProps> = ({ field }) => {
}, [previewRef]);
const onDrop = useCallback(({ data }: DragItem) => {
- const dragField = data.field as Database.Field;
+ const dragField = data.field as Field;
const fromIndex = fields.findIndex(item => item.id === dragField.id);
const dropIndex = fields.findIndex(item => item.id === field.id);
const toIndex = dropIndex + dropPosition + (fromIndex < dropIndex ? -1 : 0);
@@ -78,7 +78,7 @@ export const GridField: FC<GridFieldProps> = ({ field }) => {
return;
}
- void service.moveField(viewId, dragField.id, fromIndex, toIndex);
+ void fieldService.moveField(viewId, dragField.id, fromIndex, toIndex);
}, [viewId, field, fields, dropPosition]);
const {
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridField/GridFieldMenu.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridField/GridFieldMenu.tsx
index 77ef340452..1d7202fc3b 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridField/GridFieldMenu.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridField/GridFieldMenu.tsx
@@ -1,16 +1,15 @@
import { Divider, Menu, MenuItem, MenuProps, OutlinedInput } from '@mui/material';
import { ChangeEventHandler, FC, useCallback, useState } from 'react';
import { ReactComponent as MoreSvg } from '$app/assets/more.svg';
-import { Database } from '$app/interfaces/database';
-import * as service from '$app/components/database/database_bd_svc';
-import { useViewId } from '../../database.hooks';
+import { useViewId } from '$app/hooks';
+import { Field, fieldService } from '../../application';
import { FieldTypeSvg } from './FieldTypeSvg';
import { FieldTypeText } from './FieldTypeText';
import { GridFieldMenuActions } from './GridFieldMenuActions';
export interface GridFieldMenuProps {
- field: Database.Field;
+ field: Field;
anchorEl: MenuProps['anchorEl'];
open: boolean;
onClose: MenuProps['onClose'];
@@ -32,7 +31,7 @@ export const GridFieldMenu: FC<GridFieldMenuProps> = ({
const handleBlur = useCallback(async () => {
if (inputtingName !== field.name) {
try {
- await service.updateField(viewId, field.id, {
+ await fieldService.updateField(viewId, field.id, {
name: inputtingName,
});
} catch (e) {
@@ -74,4 +73,4 @@ export const GridFieldMenu: FC<GridFieldMenuProps> = ({
<GridFieldMenuActions />
</Menu>
);
-};
\ No newline at end of file
+};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridRow/GridCellRow.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridRow/GridCellRow/GridCellRow.tsx
similarity index 87%
rename from frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridRow/GridCellRow.tsx
rename to frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridRow/GridCellRow/GridCellRow.tsx
index 037d38074e..5b4ee6fd23 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridRow/GridCellRow.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridRow/GridCellRow/GridCellRow.tsx
@@ -2,22 +2,22 @@ import { Virtualizer } from '@tanstack/react-virtual';
import { IconButton, Tooltip } from '@mui/material';
import { t } from 'i18next';
import { DragEventHandler, FC, useCallback, useMemo, useState } from 'react';
-import { Database } from '$app/interfaces/database';
import { ReactComponent as DragSvg } from '$app/assets/drag.svg';
import { throttle } from '$app/utils/tool';
-import { useDatabase, useViewId } from '../../database.hooks';
-import * as service from '../../database_bd_svc';
-import { DragItem, DragType, DropPosition, VirtualizedList, useDraggable, useDroppable, ScrollDirection } from '../../_shared';
-import { GridCell } from '../GridCell';
+import { useViewId } from '$app/hooks';
+import { useDatabase } from '../../../Database.hooks';
+import { rowService, RowMeta } from '../../../application';
+import { DragItem, DragType, DropPosition, VirtualizedList, useDraggable, useDroppable, ScrollDirection } from '../../../_shared';
+import { GridCell } from '../../GridCell';
import { GridCellRowActions } from './GridCellRowActions';
export interface GridCellRowProps {
- row: Database.Row;
+ rowMeta: RowMeta;
virtualizer: Virtualizer<Element, Element>;
}
export const GridCellRow: FC<GridCellRowProps> = ({
- row,
+ rowMeta,
virtualizer,
}) => {
const viewId = useViewId();
@@ -44,8 +44,8 @@ export const GridCellRow: FC<GridCellRowProps> = ({
}, []);
const dragData = useMemo(() => ({
- row,
- }), [row]);
+ rowMeta,
+ }), [rowMeta]);
const {
isDragging,
@@ -77,8 +77,8 @@ export const GridCellRow: FC<GridCellRowProps> = ({
}, [previewRef]);
const onDrop = useCallback(({ data }: DragItem) => {
- void service.moveRow(viewId, (data.row as Database.Row).id, row.id);
- }, [viewId, row.id]);
+ void rowService.moveRow(viewId, (data.rowMeta as RowMeta).id, rowMeta.id);
+ }, [viewId, rowMeta.id]);
const {
isOver,
@@ -99,7 +99,7 @@ export const GridCellRow: FC<GridCellRowProps> = ({
>
<GridCellRowActions
className={hover ? 'visible' : 'invisible'}
- rowId={row.id}
+ rowId={rowMeta.id}
>
<Tooltip
placement="top"
@@ -127,7 +127,7 @@ export const GridCellRow: FC<GridCellRowProps> = ({
virtualizer={virtualizer}
renderItem={index => (
<GridCell
- rowId={row.id}
+ rowId={rowMeta.id}
field={fields[index]}
/>
)}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridRow/GridCellRowActions.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridRow/GridCellRow/GridCellRowActions.tsx
similarity index 84%
rename from frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridRow/GridCellRowActions.tsx
rename to frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridRow/GridCellRow/GridCellRowActions.tsx
index 65de7de4b2..a9b71fb30d 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridRow/GridCellRowActions.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridRow/GridCellRow/GridCellRowActions.tsx
@@ -1,9 +1,9 @@
import { IconButton, Tooltip } from '@mui/material';
import { FC, PropsWithChildren, useCallback } from 'react';
-import { ReactComponent as AddSvg } from '$app/assets/add.svg';
-import * as service from '$app/components/database/database_bd_svc';
-import { useViewId } from '../../database.hooks';
import { t } from 'i18next';
+import { ReactComponent as AddSvg } from '$app/assets/add.svg';
+import { useViewId } from '$app/hooks';
+import { rowService } from '../../../application';
export interface GridCellRowActionsProps {
className?: string;
@@ -18,7 +18,7 @@ export const GridCellRowActions: FC<PropsWithChildren<GridCellRowActionsProps>>
const viewId = useViewId();
const handleInsertRowClick = useCallback(() => {
- void service.createRow(viewId, {
+ void rowService.createRow(viewId, {
startRowId: rowId,
});
}, [viewId, rowId]);
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridRow/GridCellRow/index.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridRow/GridCellRow/index.ts
new file mode 100644
index 0000000000..2b5749c5aa
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridRow/GridCellRow/index.ts
@@ -0,0 +1 @@
+export * from './GridCellRow';
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridRow/GridFieldRow.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridRow/GridFieldRow.tsx
index 04df6e283b..6d37714cf1 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridRow/GridFieldRow.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridRow/GridFieldRow.tsx
@@ -3,10 +3,11 @@ import { FC } from 'react';
import { Button } from '@mui/material';
import { FieldType } from '@/services/backend';
import { ReactComponent as AddSvg } from '$app/assets/add.svg';
-import * as service from '$app/components/database/database_bd_svc';
-import { useDatabase } from '../../database.hooks';
+import { fieldService } from '../../application';
+import { useDatabase } from '../../Database.hooks';
import { VirtualizedList } from '../../_shared';
import { GridField } from '../GridField';
+import { useViewId } from '@/appflowy_app/hooks';
export interface GridFieldRowProps {
virtualizer: Virtualizer<Element, Element>;
@@ -15,9 +16,10 @@ export interface GridFieldRowProps {
export const GridFieldRow: FC<GridFieldRowProps> = ({
virtualizer,
}) => {
- const { viewId, fields } = useDatabase();
+ const viewId = useViewId();
+ const { fields } = useDatabase();
const handleClick = async () => {
- await service.createFieldTypeOption(viewId, FieldType.RichText);
+ await fieldService.createField(viewId, FieldType.RichText);
};
return (
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridRow/GridNewRow.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridRow/GridNewRow.tsx
index cf9dd8788b..6bd080628e 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridRow/GridNewRow.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridRow/GridNewRow.tsx
@@ -1,20 +1,27 @@
-import { useCallback } from 'react';
+import { FC, useCallback } from 'react';
import { t } from 'i18next';
import { Button } from '@mui/material';
import { ReactComponent as AddSvg } from '$app/assets/add.svg';
-import * as service from '$app/components/database/database_bd_svc';
-import { useDatabase, useViewId } from '../../database.hooks';
+import { useViewId } from '$app/hooks';
+import { rowService } from '../../application';
-export const GridNewRow = () => {
+export interface GridNewRowProps {
+ startRowId?: string;
+ groupId?: string;
+}
+
+export const GridNewRow: FC<GridNewRowProps> = ({
+ startRowId,
+ groupId,
+}) => {
const viewId = useViewId();
- const { rows } = useDatabase();
- const lastRowId = rows.at(-1)?.id;
const handleClick = useCallback(() => {
- void service.createRow(viewId, {
- startRowId: lastRowId,
+ void rowService.createRow(viewId, {
+ startRowId,
+ groupId,
});
- }, [viewId, lastRowId]);
+ }, [viewId, groupId, startRowId]);
return (
<div className="flex grow border-b border-line-divider">
@@ -22,7 +29,7 @@ export const GridNewRow = () => {
className="grow justify-start"
onClick={handleClick}
>
- <span className="inline-flex items-center sticky left-[72px]">
+ <span className="inline-flex items-center sticky left-2">
<AddSvg className="text-base mr-1" />
{t('grid.row.newRow')}
</span>
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridRow/GridRow.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridRow/GridRow.tsx
index a1749451d3..aaad94ee04 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridRow/GridRow.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridRow/GridRow.tsx
@@ -20,14 +20,14 @@ export const GridRow: FC<GridRowProps> = ({
case RenderRowType.Row:
return (
<GridCellRow
- row={row.data}
+ rowMeta={row.data.meta}
virtualizer={virtualizer}
/>
);
case RenderRowType.Fields:
return <GridFieldRow virtualizer={virtualizer} />;
case RenderRowType.NewRow:
- return <GridNewRow />;
+ return <GridNewRow startRowId={row.data.startRowId} groupId={row.data.groupId} />;
case RenderRowType.Calculate:
return <GridCalculateRow />;
default:
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridRow/constants.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridRow/constants.ts
index e8ae30c1dd..71a2745046 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridRow/constants.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridRow/constants.ts
@@ -1,4 +1,4 @@
-import { Database } from '$app/interfaces/database';
+import { RowMeta } from '../../application';
export enum RenderRowType {
Fields = 'fields',
@@ -13,11 +13,17 @@ export interface FieldRenderRow {
export interface CellRenderRow {
type: RenderRowType.Row;
- data: Database.Row;
+ data: {
+ meta: RowMeta,
+ };
}
export interface NewRenderRow {
type: RenderRowType.NewRow;
+ data: {
+ startRowId?: string;
+ groupId?: string;
+ },
}
export interface CalculateRenderRow {
@@ -25,3 +31,27 @@ export interface CalculateRenderRow {
}
export type RenderRow = FieldRenderRow | CellRenderRow | NewRenderRow | CalculateRenderRow;
+
+export const rowMetasToRenderRow = (rowMetas: RowMeta[]): RenderRow[] => {
+ return [
+ {
+ type: RenderRowType.Fields,
+ },
+ ...rowMetas.map<RenderRow>(rowMeta => ({
+ type: RenderRowType.Row,
+ data: {
+ meta: rowMeta,
+ },
+ })),
+ {
+ type: RenderRowType.NewRow,
+ data: {
+ startRowId: rowMetas.at(-1)?.id,
+ },
+ },
+ {
+ type: RenderRowType.Calculate,
+ },
+ ];
+};
+
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridTable/GridTable.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridTable/GridTable.tsx
index 587e2ec8ea..338370a121 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridTable/GridTable.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridTable/GridTable.tsx
@@ -1,77 +1,50 @@
import { useVirtualizer } from '@tanstack/react-virtual';
-import { FC, useContext, useMemo, useRef } from 'react';
-import { VerticalScrollElementRefContext } from '../../database.context';
-import { useDatabase } from '../../database.hooks';
+import { FC, useMemo, useRef } from 'react';
+import { RowMeta } from '../../application';
+import { useDatabase, useVerticalScrollElement } from '../../Database.hooks';
import { VirtualizedList } from '../../_shared';
-import { GridRow, RenderRow, RenderRowType } from '../GridRow';
+import { GridRow, RenderRow, RenderRowType, rowMetasToRenderRow } from '../GridRow';
const getRenderRowKey = (row: RenderRow) => {
if (row.type === RenderRowType.Row) {
- return `row:${row.data.id}`;
+ return `row:${row.data.meta.id}`;
}
return row.type;
};
-const getRenderRowHeight = (row: RenderRow) => {
- const defaultRowHeight = 37;
-
- if (row.type === RenderRowType.Row) {
- return row.data.height ?? defaultRowHeight;
- }
-
- return defaultRowHeight;
-};
-
export const GridTable: FC = () => {
- const verticalScrollElementRef = useContext(VerticalScrollElementRefContext);
+ const verticalScrollElementRef = useVerticalScrollElement();
const horizontalScrollElementRef = useRef<HTMLDivElement>(null);
- const { rows, fields } = useDatabase();
+ const { rowMetas, fields } = useDatabase();
- const renderRows = useMemo<RenderRow[]>(() => {
- return [
- {
- type: RenderRowType.Fields,
- },
- ...rows.map(row => ({
- type: RenderRowType.Row,
- data: row,
- })),
- {
- type: RenderRowType.NewRow,
- },
- {
- type: RenderRowType.Calculate,
- },
- ];
- }, [rows]);
+ const renderRows = useMemo<RenderRow[]>(() => rowMetasToRenderRow(rowMetas as RowMeta[]), [rowMetas]);
const rowVirtualizer = useVirtualizer({
count: renderRows.length,
overscan: 10,
getItemKey: i => getRenderRowKey(renderRows[i]),
getScrollElement: () => verticalScrollElementRef.current,
- estimateSize: i => getRenderRowHeight(renderRows[i]),
+ estimateSize: () => 37,
});
- const defaultColumnWidth = 221;
const columnVirtualizer = useVirtualizer<Element, Element>({
horizontal: true,
count: fields.length,
overscan: 5,
getItemKey: i => fields[i].id,
getScrollElement: () => horizontalScrollElementRef.current,
- estimateSize: (i) => fields[i].width ?? defaultColumnWidth,
+ estimateSize: (i) => fields[i].width ?? 201,
});
return (
<div
ref={horizontalScrollElementRef}
- className="flex w-full overflow-x-auto"
+ className="flex w-full overflow-x-auto px-16"
style={{ minHeight: 'calc(100% - 132px)' }}
>
<VirtualizedList
- className="flex flex-col basis-full px-16"
+ className="flex flex-col basis-full"
virtualizer={rowVirtualizer}
itemClassName="flex"
renderItem={index => (
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridToolbar/GridToolbar.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridToolbar/GridToolbar.tsx
deleted file mode 100644
index a9ef34b769..0000000000
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridToolbar/GridToolbar.tsx
+++ /dev/null
@@ -1,41 +0,0 @@
-import { t } from 'i18next';
-import { Button, Input, IconButton } from '@mui/material';
-import { ReactComponent as AddSvg } from '$app/assets/add.svg';
-import { ReactComponent as SearchSvg } from '$app/assets/search.svg';
-import { ReactComponent as SettingsSvg } from '$app/assets/settings.svg';
-
-export const GridToolbar = () => {
- // TODO: get view title
- const title = 'My plans on week';
-
- return (
- <div className="database-grid-toolbar flex items-center h-10 px-16">
- <div className="flex flex-1 items-center font-semibold">
- <span className="text-base">
- {title}
- </span>
- <span className="ml-2">
- <IconButton size="small">
- <SettingsSvg />
- </IconButton>
- </span>
- </div>
- <div className="flex items-center">
- <Button
- variant="text"
- color="inherit"
- size="small"
- startIcon={<AddSvg />}
- >
- {t('grid.createView')}
- </Button>
- <Input
- className="ml-8 w-36"
- placeholder={t('search.label')}
- disableUnderline
- startAdornment={<SearchSvg className="w-4 h-4 mr-2" />}
- />
- </div>
- </div>
- );
-};
\ No newline at end of file
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridToolbar/index.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridToolbar/index.ts
deleted file mode 100644
index e4a94567a0..0000000000
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/grid/GridToolbar/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from './GridToolbar';
\ No newline at end of file
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/database/index.ts b/frontend/appflowy_tauri/src/appflowy_app/components/database/index.ts
index fafeee00d4..42a6f31592 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/database/index.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/database/index.ts
@@ -1,3 +1,3 @@
-export * from './database.context';
-export * from './database.hooks';
+export * from './Database.hooks';
export * from './Database';
+export * from './DatabaseTitle';
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/BlockSelection/BlockRectSelection.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/components/document/BlockSelection/BlockRectSelection.hooks.ts
index 5122af621b..f0258354c1 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/BlockSelection/BlockRectSelection.hooks.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/BlockSelection/BlockRectSelection.hooks.ts
@@ -90,7 +90,7 @@ export function useBlockRectSelection({ container, getIntersectedBlockIds }: Blo
const blockIds = getIntersectedBlockIds(newRect);
setRect(newRect);
- dispatch(
+ void dispatch(
setRectSelectionThunk({
selection: blockIds,
docId,
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/BlockSelection/NodesRect.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/components/document/BlockSelection/NodesRect.hooks.ts
index d528e41050..a0824836bd 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/BlockSelection/NodesRect.hooks.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/BlockSelection/NodesRect.hooks.ts
@@ -16,6 +16,7 @@ export function useNodesRect(container: HTMLDivElement) {
(node: Element) => {
const { x, y, width, height } = node.getBoundingClientRect();
const id = node.getAttribute('data-block-id');
+
if (!id) return;
const rect = {
id,
@@ -24,6 +25,7 @@ export function useNodesRect(container: HTMLDivElement) {
width,
height,
};
+
regionGrid?.updateBlock(rect);
},
[container.scrollLeft, container.scrollTop, regionGrid]
@@ -31,6 +33,7 @@ export function useNodesRect(container: HTMLDivElement) {
const updateViewPortNodesRect = useCallback(() => {
const nodes = container.querySelectorAll('[data-block-id]');
+
nodes.forEach(updateNodeRect);
}, [container, updateNodeRect]);
@@ -55,6 +58,7 @@ export function useNodesRect(container: HTMLDivElement) {
const y = Math.min(startY, endY);
const width = Math.abs(endX - startX);
const height = Math.abs(endY - startY);
+
return regionGrid
.getIntersectingBlocks({
x,
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/BlockSelection/RangeKeyDown.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/components/document/BlockSelection/RangeKeyDown.hooks.ts
index 8a85fcb71a..21d18b07b6 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/BlockSelection/RangeKeyDown.hooks.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/BlockSelection/RangeKeyDown.hooks.ts
@@ -2,7 +2,6 @@ import { useCallback, useMemo } from 'react';
import { Keyboard } from '$app/constants/document/keyboard';
import { useAppDispatch } from '$app/stores/store';
import { arrowActionForRangeThunk, deleteRangeAndInsertThunk } from '$app_reducers/document/async-actions';
-import Delta from 'quill-delta';
import isHotkey from 'is-hotkey';
import { deleteRangeAndInsertEnterThunk } from '$app_reducers/document/async-actions/range';
import { useRangeRef } from '$app/components/document/_shared/SubscribeSelection.hooks';
@@ -26,7 +25,7 @@ export function useRangeKeyDown() {
},
handler: (_: KeyboardEvent) => {
if (!controller) return;
- dispatch(
+ void dispatch(
deleteRangeAndInsertThunk({
controller,
})
@@ -40,7 +39,7 @@ export function useRangeKeyDown() {
},
handler: (e: KeyboardEvent) => {
if (!controller) return;
- dispatch(
+ void dispatch(
deleteRangeAndInsertThunk({
controller,
insertChar: e.key,
@@ -53,9 +52,9 @@ export function useRangeKeyDown() {
canHandle: (e: KeyboardEvent) => {
return isHotkey(Keyboard.keys.SHIFT_ENTER, e);
},
- handler: (e: KeyboardEvent) => {
+ handler: () => {
if (!controller) return;
- dispatch(
+ void dispatch(
deleteRangeAndInsertEnterThunk({
controller,
shiftKey: true,
@@ -68,9 +67,9 @@ export function useRangeKeyDown() {
canHandle: (e: KeyboardEvent) => {
return isHotkey(Keyboard.keys.ENTER, e);
},
- handler: (e: KeyboardEvent) => {
+ handler: () => {
if (!controller) return;
- dispatch(
+ void dispatch(
deleteRangeAndInsertEnterThunk({
controller,
shiftKey: false,
@@ -89,7 +88,7 @@ export function useRangeKeyDown() {
);
},
handler: (e: KeyboardEvent) => {
- dispatch(
+ void dispatch(
arrowActionForRangeThunk({
key: e.key,
docId,
@@ -105,7 +104,7 @@ export function useRangeKeyDown() {
const format = parseFormat(e);
if (!format) return;
- dispatch(
+ void dispatch(
toggleFormatThunk({
format,
controller,
@@ -117,7 +116,7 @@ export function useRangeKeyDown() {
[controller, dispatch, docId]
);
- const onKeyDownCapture = useCallback(
+ return useCallback(
(e: KeyboardEvent) => {
if (!rangeRef.current) {
return;
@@ -147,6 +146,4 @@ export function useRangeKeyDown() {
},
[interceptEvents, rangeRef]
);
-
- return onKeyDownCapture;
}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/BlockSideToolbar/BlockMenu.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/document/BlockSideToolbar/BlockMenu.tsx
index cef2c02184..932a3ad330 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/BlockSideToolbar/BlockMenu.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/BlockSideToolbar/BlockMenu.tsx
@@ -93,9 +93,7 @@ function BlockMenu({ id, onClose }: { id: string; onClose: () => void }) {
if (hovered) {
const option = options.find((option) => option.key === hovered);
- if (option) {
- option.operate?.();
- }
+ void option?.operate?.();
} else {
onClose();
}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/BlockSideToolbar/index.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/document/BlockSideToolbar/index.tsx
index b48d34516d..a086fed1dc 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/BlockSideToolbar/index.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/BlockSideToolbar/index.tsx
@@ -38,7 +38,7 @@ export default function BlockSideToolbar({ id }: { id: string }) {
pointerEvents: show ? 'auto' : 'none',
}}
onClick={(_: React.MouseEvent<HTMLButtonElement>) => {
- dispatch(
+ void dispatch(
addBlockBelowClickThunk({
id,
controller,
@@ -74,8 +74,8 @@ export default function BlockSideToolbar({ id }: { id: string }) {
pointerEvents: show ? 'auto' : 'none',
}}
data-draggable-anchor={id}
- onClick={(e: React.MouseEvent<HTMLButtonElement>) => {
- dispatch(
+ onClick={async (e: React.MouseEvent<HTMLButtonElement>) => {
+ await dispatch(
setRectSelectionThunk({
docId,
selection: [id],
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/BlockSlash/BlockSlashMenu.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/document/BlockSlash/BlockSlashMenu.tsx
index 234ff085f8..583d57594d 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/BlockSlash/BlockSlashMenu.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/BlockSlash/BlockSlashMenu.tsx
@@ -27,7 +27,7 @@ import { slashCommandActions } from '$app_reducers/document/slice';
import { Keyboard } from '$app/constants/document/keyboard';
import { selectOptionByUpDown } from '$app/utils/document/menu';
import { turnToBlockThunk } from '$app_reducers/document/async-actions';
-import {useTranslation} from "react-i18next";
+import { useTranslation } from 'react-i18next';
function BlockSlashMenu({
id,
@@ -43,11 +43,11 @@ function BlockSlashMenu({
container: HTMLDivElement;
}) {
const dispatch = useAppDispatch();
- const { t } = useTranslation()
+ const { t } = useTranslation();
const ref = useRef<HTMLDivElement | null>(null);
const { docId, controller } = useSubscribeDocument();
const handleInsert = useCallback(
- async (type: BlockType, data?: BlockData<any>) => {
+ async (type: BlockType, data?: BlockData) => {
if (!controller) return;
await dispatch(
turnToBlockThunk({
@@ -245,7 +245,7 @@ function BlockSlashMenu({
e.preventDefault();
if (isEnter) {
if (hoverOption) {
- handleInsert(hoverOption.type, hoverOption.data);
+ void handleInsert(hoverOption.type, hoverOption.data);
}
return;
@@ -282,9 +282,9 @@ function BlockSlashMenu({
);
const renderEmptyContent = useCallback(() => {
- return <div className={'m-5 text-text-caption flex justify-center items-center'}>
- {t('findAndReplace.noResult')}
- </div>
+ return (
+ <div className={'m-5 flex items-center justify-center text-text-caption'}>{t('findAndReplace.noResult')}</div>
+ );
}, [t]);
return (
@@ -296,30 +296,32 @@ function BlockSlashMenu({
className={'flex h-[100%] max-h-[40vh] w-[324px] min-w-[180px] max-w-[calc(100vw-32px)] flex-col p-1'}
>
<div ref={ref} className={'min-h-0 flex-1 overflow-y-auto overflow-x-hidden'}>
- {options.length === 0 ? renderEmptyContent(): Object.entries(optionsByGroup).map(([group, options]) => (
- <div key={group}>
- <div className={'px-2 py-2 text-sm text-text-caption'}>{group}</div>
- <div>
- {options.map((option) => {
- return (
- <MenuItem
- id={`slash-item-${option.key}`}
- key={option.key}
- title={option.title}
- icon={option.icon}
- onHover={() => {
- onHoverOption(option);
- }}
- isHovered={hoverOption?.key === option.key}
- onClick={() => {
- handleInsert(option.type, option.data);
- }}
- />
- );
- })}
- </div>
- </div>
- ))}
+ {options.length === 0
+ ? renderEmptyContent()
+ : Object.entries(optionsByGroup).map(([group, options]) => (
+ <div key={group}>
+ <div className={'px-2 py-2 text-sm text-text-caption'}>{group}</div>
+ <div>
+ {options.map((option) => {
+ return (
+ <MenuItem
+ id={`slash-item-${option.key}`}
+ key={option.key}
+ title={option.title}
+ icon={option.icon}
+ onHover={() => {
+ onHoverOption(option);
+ }}
+ isHovered={hoverOption?.key === option.key}
+ onClick={() => {
+ void handleInsert(option.type, option.data);
+ }}
+ />
+ );
+ })}
+ </div>
+ </div>
+ ))}
</div>
</div>
);
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/CodeBlock/SelectLanguage.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/document/CodeBlock/SelectLanguage.tsx
index f1a5132818..01a96028df 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/CodeBlock/SelectLanguage.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/CodeBlock/SelectLanguage.tsx
@@ -17,7 +17,7 @@ function SelectLanguage({ id, language }: { id: string; language: string }) {
if (!controller) return;
const language = event.target.value;
- dispatch(
+ void dispatch(
updateNodeDataThunk({
id,
controller,
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/CodeBlock/useKeyDown.ts b/frontend/appflowy_tauri/src/appflowy_app/components/document/CodeBlock/useKeyDown.ts
index 2a64f350de..a24413a69b 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/CodeBlock/useKeyDown.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/CodeBlock/useKeyDown.ts
@@ -1,5 +1,5 @@
import isHotkey from 'is-hotkey';
-import { useCallback, useContext, useMemo } from 'react';
+import { useCallback, useMemo } from 'react';
import { useAppDispatch } from '$app/stores/store';
import { Keyboard } from '$app/constants/document/keyboard';
import { useCommonKeyEvents } from '$app/components/document/_shared/EditorHooks/useCommonKeyEvents';
@@ -8,7 +8,7 @@ import { useSubscribeDocument } from '$app/components/document/_shared/Subscribe
export function useKeyDown(id: string) {
const dispatch = useAppDispatch();
- const { docId, controller } = useSubscribeDocument();
+ const { controller } = useSubscribeDocument();
const commonKeyEvents = useCommonKeyEvents(id);
const customEvents = useMemo(() => {
@@ -22,7 +22,7 @@ export function useKeyDown(id: string) {
handler: (e: React.KeyboardEvent<HTMLDivElement>) => {
e.preventDefault();
if (!controller) return;
- dispatch(
+ void dispatch(
enterActionForBlockThunk({
id,
controller,
@@ -37,6 +37,7 @@ export function useKeyDown(id: string) {
(e) => {
e.stopPropagation();
const keyEvents = [...customEvents];
+
keyEvents.forEach((keyEvent) => {
// Here we check if the key event can be handled by the current key event
if (keyEvent.canHandle(e)) {
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/ColumnListBlock/Column.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/document/ColumnListBlock/Column.tsx
deleted file mode 100644
index f88031e64f..0000000000
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/ColumnListBlock/Column.tsx
+++ /dev/null
@@ -1,39 +0,0 @@
-import NodeComponent from '$app/components/document/Node';
-import React from 'react';
-
-export function ColumnBlock({ id, index, width }: { id: string; index: number; width: string }) {
- const renderResizer = () => {
- return (
- <div className={`relative w-[46px] flex-shrink-0 flex-grow-0 transition-opacity`} style={{ opacity: 0 }}></div>
- );
- };
-
- return (
- <>
- {index === 0 ? (
- <div className='contents'>
- <div
- className='absolute flex'
- style={{
- inset: '0px 100% 0px auto',
- }}
- >
- {renderResizer()}
- </div>
- </div>
- ) : (
- renderResizer()
- )}
-
- <NodeComponent
- className={`column-block py-3`}
- style={{
- flexGrow: 0,
- flexShrink: 0,
- width,
- }}
- id={id}
- />
- </>
- );
-}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/ColumnListBlock/index.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/document/ColumnListBlock/index.tsx
deleted file mode 100644
index b0c406908b..0000000000
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/ColumnListBlock/index.tsx
+++ /dev/null
@@ -1,31 +0,0 @@
-import React, { useMemo } from 'react';
-import { Node } from '$app/interfaces/document';
-import { ColumnBlock } from './Column';
-
-export default function ColumnListBlock({
- node,
- childIds,
-}: {
- node: Node & {
- data: Record<string, any>;
- };
- childIds?: string[];
-}) {
- const resizerWidth = useMemo(() => {
- return 46 * (node.children?.length || 0);
- }, [node.children?.length]);
- return (
- <>
- <div className='column-list-block flex-grow-1 flex flex-row'>
- {childIds?.map((item, index) => (
- <ColumnBlock
- key={item}
- index={index}
- width={`calc((100% - ${resizerWidth}px) * ${node.data.ratio})`}
- id={item}
- />
- ))}
- </div>
- </>
- );
-}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/DocumentBanner/DocumentBanner.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/components/document/DocumentBanner/DocumentBanner.hooks.ts
index 6c57f6ba5b..200816463a 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/DocumentBanner/DocumentBanner.hooks.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/DocumentBanner/DocumentBanner.hooks.ts
@@ -6,6 +6,7 @@ import { ViewIconTypePB } from '@/services/backend';
import { CoverType } from '$app/interfaces/document';
import { updateNodeDataThunk } from '$app_reducers/document/async-actions';
import { useSubscribeNode } from '$app/components/document/_shared/SubscribeNode.hooks';
+
export const heightCls = {
cover: 'h-[220px]',
icon: 'h-[80px]',
@@ -22,7 +23,7 @@ export function useDocumentBanner(id: string) {
const onUpdateIcon = useCallback(
(icon: string) => {
- dispatch(
+ void dispatch(
updatePageIcon({
id: docId,
icon: icon
@@ -39,7 +40,7 @@ export function useDocumentBanner(id: string) {
const onUpdateCover = useCallback(
(coverType: CoverType | null, cover: string | null) => {
- dispatch(
+ void dispatch(
updateNodeDataThunk({
id,
data: {
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/DocumentBanner/cover/ChangeImages.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/document/DocumentBanner/cover/ChangeImages.tsx
index 1ff91eaea9..0a3b9d42e7 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/DocumentBanner/cover/ChangeImages.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/DocumentBanner/cover/ChangeImages.tsx
@@ -7,7 +7,7 @@ import { readCoverImageUrls, readImage, writeCoverImageUrls } from '$app/utils/d
import { Log } from '$app/utils/log';
import { Image } from '$app/components/document/DocumentBanner/cover/GalleryItem';
-function ChangeImages({ cover, onChange }: { onChange: (url: string) => void; cover: string }) {
+function ChangeImages({ onChange }: { onChange: (url: string) => void; cover: string }) {
const { t } = useTranslation();
const [images, setImages] = useState<Image[]>([]);
const loadImageUrls = useCallback(async () => {
@@ -58,7 +58,7 @@ function ChangeImages({ cover, onChange }: { onChange: (url: string) => void; co
}, [loadImageUrls]);
useEffect(() => {
- loadImageUrls();
+ void loadImageUrls();
}, [loadImageUrls]);
return (
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/DocumentBanner/index.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/document/DocumentBanner/index.tsx
index 036ee0e127..f8d4c269ac 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/DocumentBanner/index.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/DocumentBanner/index.tsx
@@ -5,6 +5,7 @@ import DocumentIcon from './DocumentIcon';
function DocumentBanner({ id, hover }: { id: string; hover: boolean }) {
const { onUpdateCover, node, onUpdateIcon, icon, cover, className, coverType } = useDocumentBanner(id);
+
return (
<>
<div
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/ImageBlock/ImageAlign.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/document/ImageBlock/ImageAlign.tsx
index 5217eaa94a..bbd2c40c31 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/ImageBlock/ImageAlign.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/ImageBlock/ImageAlign.tsx
@@ -47,7 +47,7 @@ function ImageAlign({
const updateAlign = useCallback(
(align: Align) => {
- dispatch(
+ void dispatch(
updateNodeDataThunk({
id,
data: {
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/ImageBlock/ImageToolbar.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/document/ImageBlock/ImageToolbar.tsx
index c2175ec3f5..c9fc838a81 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/ImageBlock/ImageToolbar.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/ImageBlock/ImageToolbar.tsx
@@ -27,7 +27,7 @@ function ImageToolbar({ id, open, align }: { id: string; open: boolean; align: A
<Tooltip disableInteractive placement={'top'} title={t('button.delete')}>
<div
onClick={() => {
- dispatch(deleteNodeThunk({ id, controller }));
+ void dispatch(deleteNodeThunk({ id, controller }));
}}
className='flex items-center justify-center p-1'
>
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/ImageBlock/index.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/document/ImageBlock/index.tsx
index 9aecb525f5..b497989eb3 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/ImageBlock/index.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/ImageBlock/index.tsx
@@ -20,7 +20,7 @@ function ImageBlock({ node }: { node: NestedBlock<BlockType.ImageBlock> }) {
({ onClose }: { onClose: () => void }) => {
const onSubmitUrl = (url: string) => {
if (!url) return;
- dispatch(
+ void dispatch(
updateNodeDataThunk({
id,
data: {
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/ImageBlock/useImageBlock.ts b/frontend/appflowy_tauri/src/appflowy_app/components/document/ImageBlock/useImageBlock.ts
index 80c0940f17..f9b7c7da5d 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/ImageBlock/useImageBlock.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/ImageBlock/useImageBlock.ts
@@ -47,7 +47,7 @@ export function useImageBlock(node: NestedBlock<BlockType.ImageBlock>) {
const updateWidth = useCallback(
(width: number, height: number) => {
- dispatch(
+ void dispatch(
updateNodeDataThunk({
id: node.id,
data: {
@@ -93,7 +93,7 @@ export function useImageBlock(node: NestedBlock<BlockType.ImageBlock>) {
});
};
- const onResizeEnd = (e: MouseEvent) => {
+ const onResizeEnd = () => {
setResizing(false);
if (!startResizePoint.current) return;
startResizePoint.current = undefined;
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/NumberedListBlock/NumberedListBlock.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/components/document/NumberedListBlock/NumberedListBlock.hooks.ts
index 5356456558..f9ff2c55ed 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/NumberedListBlock/NumberedListBlock.hooks.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/NumberedListBlock/NumberedListBlock.hooks.ts
@@ -10,16 +10,20 @@ export function useNumberedListBlock(node: NestedBlock<BlockType.NumberedListBlo
const documentState = state['document'][docId];
const nodes = documentState.nodes;
const children = documentState.children;
+
+ if (!node.parent) return 0;
// The parent must be existed
- const parent = nodes[node.parent!];
+ const parent = nodes[node.parent];
const siblings = children[parent.children];
const index = siblings.indexOf(node.id);
+
if (index === 0) return 0;
const prevNodeIds = siblings.slice(0, index);
// The index is distance from last block to the last non-numbered-list block
const lastIndex = prevNodeIds.reverse().findIndex((id) => {
return nodes[id].type !== BlockType.NumberedListBlock;
});
+
if (lastIndex === -1) return prevNodeIds.length;
return lastIndex;
});
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/TextActionMenu/menu/CustomColorPicker.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/document/TextActionMenu/menu/CustomColorPicker.tsx
index ed0e4e6cce..eee5f9c126 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/TextActionMenu/menu/CustomColorPicker.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/TextActionMenu/menu/CustomColorPicker.tsx
@@ -46,7 +46,7 @@ function CustomColorPicker({
onClose={onClose}
>
<SketchPicker
- onChange={(color, event) => {
+ onChange={(color) => {
setColor(color.rgb);
}}
color={color}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/TextActionMenu/menu/FormatButton.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/document/TextActionMenu/menu/FormatButton.tsx
index 8180ebc868..9d8412e5e3 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/TextActionMenu/menu/FormatButton.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/TextActionMenu/menu/FormatButton.tsx
@@ -61,7 +61,7 @@ const FormatButton = ({ format, icon }: { format: TextAction; icon: string }) =>
const addTemporaryInput = useCallback(
(type: TemporaryType) => {
- dispatch(createTemporary({ type, docId }));
+ void dispatch(createTemporary({ type, docId }));
},
[dispatch, docId]
);
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/TextActionMenu/menu/index.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/components/document/TextActionMenu/menu/index.hooks.ts
index a1098e99c2..315ccd3337 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/TextActionMenu/menu/index.hooks.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/TextActionMenu/menu/index.hooks.ts
@@ -36,6 +36,7 @@ export function useTextActionMenu() {
return groups.map((group) => {
return group.filter((item) => items.includes(item));
});
+ // eslint-disable-next-line react-hooks/exhaustive-deps
}, [JSON.stringify(items), node]);
return {
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/TextBlock/useKeyDown.ts b/frontend/appflowy_tauri/src/appflowy_app/components/document/TextBlock/useKeyDown.ts
index 931f81a396..0c49ef54e4 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/TextBlock/useKeyDown.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/TextBlock/useKeyDown.ts
@@ -10,10 +10,9 @@ import {
import { useTurnIntoBlockEvents } from './useTurnIntoBlockEvents';
import { useCommonKeyEvents } from '../_shared/EditorHooks/useCommonKeyEvents';
import { useSubscribeDocument } from '$app/components/document/_shared/SubscribeDoc.hooks';
-import { openMention } from '$app_reducers/document/async-actions/mention';
export function useKeyDown(id: string) {
- const { controller, docId } = useSubscribeDocument();
+ const { controller } = useSubscribeDocument();
const dispatch = useAppDispatch();
const turnIntoEvents = useTurnIntoBlockEvents(id);
const commonKeyEvents = useCommonKeyEvents(id);
@@ -34,9 +33,9 @@ export function useKeyDown(id: string) {
canHandle: (e: React.KeyboardEvent<HTMLDivElement>) => {
return isHotkey(Keyboard.keys.ENTER, e);
},
- handler: (e: React.KeyboardEvent<HTMLDivElement>) => {
+ handler: () => {
if (!controller) return;
- dispatch(
+ void dispatch(
enterActionForBlockThunk({
id,
controller,
@@ -58,9 +57,9 @@ export function useKeyDown(id: string) {
canHandle: (e: React.KeyboardEvent<HTMLDivElement>) => {
return isHotkey(Keyboard.keys.TAB, e);
},
- handler: (e: React.KeyboardEvent<HTMLDivElement>) => {
+ handler: () => {
if (!controller) return;
- dispatch(
+ void dispatch(
tabActionForBlockThunk({
id,
controller,
@@ -73,9 +72,9 @@ export function useKeyDown(id: string) {
canHandle: (e: React.KeyboardEvent<HTMLDivElement>) => {
return isHotkey(Keyboard.keys.SHIFT_TAB, e);
},
- handler: (e: React.KeyboardEvent<HTMLDivElement>) => {
+ handler: () => {
if (!controller) return;
- dispatch(
+ void dispatch(
shiftTabActionForBlockThunk({
id,
controller,
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/TextBlock/useTurnIntoBlockEvents.ts b/frontend/appflowy_tauri/src/appflowy_app/components/document/TextBlock/useTurnIntoBlockEvents.ts
index bb4859017e..d06f17b1b0 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/TextBlock/useTurnIntoBlockEvents.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/TextBlock/useTurnIntoBlockEvents.ts
@@ -6,7 +6,7 @@ import { blockConfig } from '$app/constants/document/config';
import Delta from 'quill-delta';
import { useRangeRef } from '$app/components/document/_shared/SubscribeSelection.hooks';
-import { getBlockDelta } from '$app/components/document/_shared/SubscribeNode.hooks';
+import { getBlockDelta } from '$app/components/document/_shared/SubscribeNode.hooks';
import { getDeltaText } from '$app/utils/document/delta';
import { useSubscribeDocument } from '$app/components/document/_shared/SubscribeDoc.hooks';
import { turnIntoConfig } from './shortchut';
@@ -155,7 +155,7 @@ export function useTurnIntoBlockEvents(id: string) {
const data = getData();
if (!data) return;
- dispatch(turnToBlockThunk({ id, data, type: blockType, controller }));
+ void dispatch(turnToBlockThunk({ id, data, type: blockType, controller }));
},
};
});
@@ -167,9 +167,8 @@ export function useTurnIntoBlockEvents(id: string) {
handler: (e: React.KeyboardEvent<HTMLDivElement>) => {
e.preventDefault();
if (!controller) return;
- const delta = getDeltaContent();
- dispatch(
+ void dispatch(
turnToBlockThunk({
id,
controller,
@@ -186,7 +185,7 @@ export function useTurnIntoBlockEvents(id: string) {
if (!controller) return;
const defaultData = blockConfig[BlockType.CodeBlock].defaultData;
- dispatch(
+ void dispatch(
turnToBlockThunk({
id,
data: {
@@ -208,10 +207,11 @@ export function useTurnIntoBlockEvents(id: string) {
formula,
};
- dispatch(turnToBlockThunk({ id, data, type: BlockType.EquationBlock, controller }));
+ void dispatch(turnToBlockThunk({ id, data, type: BlockType.EquationBlock, controller }));
},
- }
+ },
];
+ // eslint-disable-next-line react-hooks/exhaustive-deps
}, [canHandle, controller, dispatch, getAttrs, getDeltaContent, id, spaceTriggerMap]);
return turnIntoBlockEvents;
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/ToggleListBlock/index.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/document/ToggleListBlock/index.tsx
index 9c3b980bdf..54387fe922 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/ToggleListBlock/index.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/ToggleListBlock/index.tsx
@@ -3,13 +3,13 @@ import { BlockType, NestedBlock } from '$app/interfaces/document';
import TextBlock from '$app/components/document/TextBlock';
import NodeChildren from '$app/components/document/Node/NodeChildren';
import { useToggleListBlock } from '$app/components/document/ToggleListBlock/ToggleListBlock.hooks';
-import { IconButton } from '@mui/material';
import { DropDownShowSvg } from '$app/components/_shared/svg/DropDownShowSvg';
import Button from '@mui/material/Button';
function ToggleListBlock({ node, childIds }: { node: NestedBlock<BlockType.ToggleListBlock>; childIds?: string[] }) {
const { toggleCollapsed, handleShortcut } = useToggleListBlock(node.id, node.data);
const collapsed = node.data.collapsed;
+
return (
<>
<div className={'flex'} onKeyDownCapture={handleShortcut}>
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/BlockPopover/BlockPopover.hooks.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/BlockPopover/BlockPopover.hooks.tsx
index 81c9cd0e4c..a86f5e8e9e 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/BlockPopover/BlockPopover.hooks.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/BlockPopover/BlockPopover.hooks.tsx
@@ -42,7 +42,7 @@ export function useBlockPopover({
}, [dispatch, docId, id, onAfterClose]);
const selectBlock = useCallback(() => {
- dispatch(
+ void dispatch(
setRectSelectionThunk({
docId,
selection: [id],
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/CopyPasteHooks/useCopy.ts b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/CopyPasteHooks/useCopy.ts
index 2c31f9ab95..0a34e4971c 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/CopyPasteHooks/useCopy.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/CopyPasteHooks/useCopy.ts
@@ -19,7 +19,8 @@ export function useCopy(container: HTMLDivElement) {
e.clipboardData?.setData(clipboardTypes.TEXT, data.text);
e.clipboardData?.setData(clipboardTypes.HTML, data.html);
};
- dispatch(
+
+ void dispatch(
copyThunk({
setClipboardData,
controller,
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/CopyPasteHooks/usePaste.ts b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/CopyPasteHooks/usePaste.ts
index a2cc09d643..6ed3c9fd6b 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/CopyPasteHooks/usePaste.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/CopyPasteHooks/usePaste.ts
@@ -1,4 +1,4 @@
-import { useCallback, useContext, useEffect } from 'react';
+import { useCallback, useEffect } from 'react';
import { useAppDispatch } from '$app/stores/store';
import { pasteThunk } from '$app_reducers/document/async-actions/copy_paste';
import { clipboardTypes } from '$app/constants/document/copy_paste';
@@ -12,7 +12,7 @@ export function usePaste(container: HTMLDivElement) {
if (!controller) return;
e.stopPropagation();
e.preventDefault();
- dispatch(
+ void dispatch(
pasteThunk({
controller,
data: {
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/EditorHooks/useCommonKeyEvents.ts b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/EditorHooks/useCommonKeyEvents.ts
index 84a95e5bd9..e7da44baf8 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/EditorHooks/useCommonKeyEvents.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/EditorHooks/useCommonKeyEvents.ts
@@ -12,8 +12,6 @@ import { useAppDispatch } from '$app/stores/store';
import { isFormatHotkey, parseFormat } from '$app/utils/document/format';
import { toggleFormatThunk } from '$app_reducers/document/async-actions/format';
import { useSubscribeDocument } from '$app/components/document/_shared/SubscribeDoc.hooks';
-import { getBlock } from '$app/components/document/_shared/SubscribeNode.hooks';
-import Delta from 'quill-delta';
export function useCommonKeyEvents(id: string) {
const { focused, caretRef } = useFocused(id);
@@ -35,7 +33,7 @@ export function useCommonKeyEvents(id: string) {
handler: (e: React.KeyboardEvent<HTMLDivElement>) => {
e.preventDefault();
if (!controller) return;
- dispatch(backspaceDeleteActionForBlockThunk({ id, controller }));
+ void dispatch(backspaceDeleteActionForBlockThunk({ id, controller }));
},
},
{
@@ -45,7 +43,7 @@ export function useCommonKeyEvents(id: string) {
},
handler: (e: React.KeyboardEvent<HTMLDivElement>) => {
e.preventDefault();
- dispatch(upDownActionForBlockThunk({ docId, id }));
+ void dispatch(upDownActionForBlockThunk({ docId, id }));
},
},
{
@@ -55,7 +53,7 @@ export function useCommonKeyEvents(id: string) {
},
handler: (e: React.KeyboardEvent<HTMLDivElement>) => {
e.preventDefault();
- dispatch(upDownActionForBlockThunk({ docId, id, down: true }));
+ void dispatch(upDownActionForBlockThunk({ docId, id, down: true }));
},
},
{
@@ -66,7 +64,7 @@ export function useCommonKeyEvents(id: string) {
handler: (e: React.KeyboardEvent<HTMLDivElement>) => {
e.preventDefault();
e.stopPropagation();
- dispatch(leftActionForBlockThunk({ docId, id }));
+ void dispatch(leftActionForBlockThunk({ docId, id }));
},
},
{
@@ -76,7 +74,7 @@ export function useCommonKeyEvents(id: string) {
},
handler: (e: React.KeyboardEvent<HTMLDivElement>) => {
e.preventDefault();
- dispatch(rightActionForBlockThunk({ docId, id }));
+ void dispatch(rightActionForBlockThunk({ docId, id }));
},
},
{
@@ -87,7 +85,7 @@ export function useCommonKeyEvents(id: string) {
const format = parseFormat(e);
if (!format) return;
- dispatch(
+ void dispatch(
toggleFormatThunk({
format,
controller,
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/EditorHooks/useDelta.ts b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/EditorHooks/useDelta.ts
index 98baf30121..9d690d9b0a 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/EditorHooks/useDelta.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/EditorHooks/useDelta.ts
@@ -1,5 +1,5 @@
import { useSubscribeNode } from '$app/components/document/_shared/SubscribeNode.hooks';
-import { useCallback, useContext, useEffect, useMemo, useRef } from 'react';
+import { useCallback, useEffect, useMemo, useRef } from 'react';
import { useAppDispatch } from '$app/stores/store';
import { updateNodeDeltaThunk } from '$app_reducers/document/async-actions';
import Delta, { Op } from 'quill-delta';
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/EditorHooks/useSelection.ts b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/EditorHooks/useSelection.ts
index 92517f5720..563241fec3 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/EditorHooks/useSelection.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/EditorHooks/useSelection.ts
@@ -19,8 +19,8 @@ export function useSelection(id: string) {
const { docId } = useSubscribeDocument();
const storeRange = useCallback(
- (range: RangeStatic) => {
- dispatch(storeRangeThunk({ id, range, docId }));
+ async (range: RangeStatic) => {
+ await dispatch(storeRangeThunk({ id, range, docId }));
},
[docId, id, dispatch]
);
@@ -38,7 +38,7 @@ export function useSelection(id: string) {
},
})
);
- storeRange(range);
+ void storeRange(range);
},
[docId, id, dispatch, storeRange]
);
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/InlineBlock/CodeInline.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/InlineBlock/CodeInline.tsx
index 4f2c031602..f28892ab22 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/InlineBlock/CodeInline.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/InlineBlock/CodeInline.tsx
@@ -1,6 +1,6 @@
import React from 'react';
-function CodeInline({ text, children, selected }: { text: string; children: React.ReactNode; selected: boolean }) {
+function CodeInline({ children, selected }: { text: string; children: React.ReactNode; selected: boolean }) {
return (
<span
className={'bg-content-blue-50 py-1'}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/InlineBlock/FormulaInline.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/InlineBlock/FormulaInline.tsx
index 6646c7c92a..97f4b9e00c 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/InlineBlock/FormulaInline.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/InlineBlock/FormulaInline.tsx
@@ -28,12 +28,12 @@ function FormulaInline({
const { docId } = useSubscribeDocument();
const dispatch = useAppDispatch();
const onClick = useCallback(
- (node: HTMLSpanElement) => {
+ async (node: HTMLSpanElement) => {
const selection = getSelection(node);
if (!selection) return;
- dispatch(
+ await dispatch(
createTemporary({
docId,
state: {
@@ -57,7 +57,7 @@ function FormulaInline({
getSelection={getSelection}
isFirst={isFirst}
isLast={isLast}
- renderNode={() => <KatexMath latex={data.latex!} isInline />}
+ renderNode={() => <KatexMath latex={data.latex || ''} isInline />}
>
{children}
</FakeCursorContainer>
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/InlineBlock/LinkInline.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/InlineBlock/LinkInline.tsx
index 070ec257f0..ebb5c0f4c2 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/InlineBlock/LinkInline.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/InlineBlock/LinkInline.tsx
@@ -26,17 +26,18 @@ function LinkInline({
const dispatch = useAppDispatch();
const onClick = useCallback(
- (e: React.MouseEvent) => {
+ async (e: React.MouseEvent) => {
if (!ref.current) return;
const selection = getSelection(ref.current);
if (!selection) return;
const rect = ref.current?.getBoundingClientRect();
+
if (!rect) return;
e.stopPropagation();
e.preventDefault();
- dispatch(
+ await dispatch(
createTemporary({
docId,
state: {
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/InlineBlock/PageInline.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/InlineBlock/PageInline.tsx
index a97726aded..6786ba8389 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/InlineBlock/PageInline.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/InlineBlock/PageInline.tsx
@@ -7,7 +7,7 @@ import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import { pageTypeMap } from '$app/constants';
import { LinearProgress } from '@mui/material';
-import Tooltip from "@mui/material/Tooltip";
+import Tooltip from '@mui/material/Tooltip';
function PageInline({ pageId }: { pageId: string }) {
const { t } = useTranslation();
@@ -18,12 +18,14 @@ function PageInline({ pageId }: { pageId: string }) {
const controller = new PageController(id);
const page = await controller.getPage();
+
setCurrentPage(page);
}, []);
const navigateToPage = useCallback(
(page: Page) => {
const pageType = pageTypeMap[page.layout];
+
navigate(`/page/${pageType}/${page.id}`);
},
[navigate]
@@ -31,14 +33,12 @@ function PageInline({ pageId }: { pageId: string }) {
useEffect(() => {
if (!page) {
- loadPage(pageId);
+ void loadPage(pageId);
} else {
setCurrentPage(page);
}
-
}, [page, loadPage, pageId]);
-
return currentPage ? (
<Tooltip arrow title={t('document.mention.page.tooltip')} placement={'top'}>
<span
@@ -49,11 +49,10 @@ function PageInline({ pageId }: { pageId: string }) {
}}
className={'inline-block cursor-pointer rounded px-1 hover:bg-content-blue-100'}
>
- <span className={'mr-1'}>{currentPage.icon?.value || <Article />}</span>
- <span className={'font-medium underline '}>{currentPage.name || t('menuAppHeader.defaultNewPageName')}</span>
- </span>
+ <span className={'mr-1'}>{currentPage.icon?.value || <Article />}</span>
+ <span className={'font-medium underline '}>{currentPage.name || t('menuAppHeader.defaultNewPageName')}</span>
+ </span>
</Tooltip>
-
) : (
<span>
<LinearProgress />
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/SlateEditor/TextLeaf.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/SlateEditor/TextLeaf.tsx
index 83bd7fe680..6e2e87bb64 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/SlateEditor/TextLeaf.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/SlateEditor/TextLeaf.tsx
@@ -92,6 +92,7 @@ const TextLeaf = (props: TextLeafProps) => {
}
const mention = leaf.mention;
+
if (mention && mention.type === MentionType.PAGE && leaf.text) {
newChildren = (
<FakeCursorContainer
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/SlateEditor/useEditor.ts b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/SlateEditor/useEditor.ts
index 6d2da98079..53d805f3ab 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/SlateEditor/useEditor.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/SlateEditor/useEditor.ts
@@ -7,7 +7,6 @@ import { focusNodeByIndex } from '$app/utils/document/node';
import { Keyboard } from '$app/constants/document/keyboard';
import isHotkey from 'is-hotkey';
import { useSlateYjs } from '$app/components/document/_shared/SlateEditor/useSlateYjs';
-import { openMention } from '$app_reducers/document/async-actions/mention';
const AFTER_RENDER_DELAY = 100;
@@ -49,6 +48,7 @@ export function useEditor({
: [];
const currentSelection = editor.selection || [];
let removeMark = markKeys.length > 0;
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
const [_, path] = editor.node(currentSelection);
if (removeMark) {
@@ -113,9 +113,10 @@ export function useEditor({
const decorate = useCallback(
(entry: NodeEntry) => {
- const [node, path] = entry;
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
+ const [_, path] = entry;
- const ranges: Range[] = [
+ return [
getDecorateRange(path, decorateSelection, {
selection_high_lighted: true,
}),
@@ -123,8 +124,6 @@ export function useEditor({
temporary: true,
}),
].filter((range) => range !== null) as Range[];
-
- return ranges;
},
[temporarySelection, decorateSelection, getDecorateRange]
);
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/SlateEditor/useSlateYjs.ts b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/SlateEditor/useSlateYjs.ts
index f377567d52..ba4669db6c 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/SlateEditor/useSlateYjs.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/SlateEditor/useSlateYjs.ts
@@ -21,6 +21,7 @@ export function useSlateYjs({ delta, onChange }: { delta?: Delta; onChange: (ops
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
+ // eslint-disable-next-line react-hooks/exhaustive-deps
const editor = useMemo(() => withYjs(withMarkdown(withReact(createEditor())), sharedType), []);
// Connect editor in useEffect to comply with concurrent mode requirements.
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/SubscribeMention.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/SubscribeMention.hooks.ts
index 17d103a30d..2043209b40 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/SubscribeMention.hooks.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/SubscribeMention.hooks.ts
@@ -7,6 +7,7 @@ const initialState: MentionState = {
open: false,
blockId: '',
};
+
export function useSubscribeMentionState() {
const { docId } = useSubscribeDocument();
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/SubscribeNode.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/SubscribeNode.hooks.ts
index c687177c6d..0efefa4621 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/SubscribeNode.hooks.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/SubscribeNode.hooks.ts
@@ -18,14 +18,17 @@ export function useSubscribeNode(id: string) {
}>((state) => {
const documentState = state[DOCUMENT_NAME][docId];
const node = documentState?.nodes[id];
+
// if node is root, return page name
if (!node?.parent) {
const delta = state.pages?.pageMap[docId]?.name;
+
return {
node,
delta: delta ? JSON.stringify(new Delta().insert(delta)) : '',
};
}
+
const externalId = node?.externalId;
return {
@@ -51,7 +54,9 @@ export function useSubscribeNode(id: string) {
// Memoize the node and its children
// So that the component will not be re-rendered when other node is changed
// It very important for performance
+ // eslint-disable-next-line react-hooks/exhaustive-deps
const memoizedNode = useMemo(() => node, [JSON.stringify(node)]);
+ // eslint-disable-next-line react-hooks/exhaustive-deps
const memoizedChildIds = useMemo(() => childIds, [JSON.stringify(childIds)]);
return {
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/SubscribeSelection.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/SubscribeSelection.hooks.ts
index 649d33bc38..fa1ee30fd1 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/SubscribeSelection.hooks.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/SubscribeSelection.hooks.ts
@@ -2,7 +2,7 @@ import { useAppSelector } from '$app/stores/store';
import { RangeState, RangeStatic } from '$app/interfaces/document';
import { useMemo, useRef } from 'react';
import { useSubscribeDocument } from '$app/components/document/_shared/SubscribeDoc.hooks';
-import { RANGE_NAME, TEMPORARY_NAME, TEXT_LINK_NAME } from '$app/constants/document/name';
+import { RANGE_NAME, TEMPORARY_NAME } from '$app/constants/document/name';
export function useSubscribeDecorate(id: string) {
const { docId } = useSubscribeDocument();
@@ -51,7 +51,7 @@ export function useFocused(id: string) {
}
export function useRangeRef() {
- const { docId, controller } = useSubscribeDocument();
+ const { docId } = useSubscribeDocument();
const rangeRef = useRef<RangeState>();
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/TemporaryInput/TemporaryLink.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/TemporaryInput/TemporaryLink.tsx
index 117f787b1a..f16352a31b 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/TemporaryInput/TemporaryLink.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/TemporaryInput/TemporaryLink.tsx
@@ -2,8 +2,9 @@ import React from 'react';
import { AddLinkOutlined } from '@mui/icons-material';
import { useTranslation } from 'react-i18next';
-function TemporaryLink({ href = '', text = '' }: { href?: string; text?: string }) {
+function TemporaryLink({ text = '' }: { href?: string; text?: string }) {
const { t } = useTranslation();
+
return (
<span className={'bg-content-blue-100'} contentEditable={false}>
{text ? (
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/TemporaryInput/TemporaryPopover.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/TemporaryInput/TemporaryPopover.tsx
index 6f27a871bf..ec53767774 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/TemporaryInput/TemporaryPopover.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/TemporaryInput/TemporaryPopover.tsx
@@ -17,7 +17,6 @@ function TemporaryPopover() {
const anchorPosition = useMemo(() => temporaryState?.popoverPosition, [temporaryState]);
const open = Boolean(anchorPosition);
const id = temporaryState?.id;
- const type = temporaryState?.type;
const dispatch = useAppDispatch();
const { docId, controller } = useSubscribeDocument();
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/TemporaryInput/index.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/TemporaryInput/index.tsx
index 4afe2ae2c6..4e9460dbf3 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/TemporaryInput/index.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/TemporaryInput/index.tsx
@@ -77,6 +77,7 @@ function TemporaryInput({
useEffect(() => {
const match = getMatch();
+
setMatch(match);
}, [getMatch]);
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/TurnInto/TurnInto.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/TurnInto/TurnInto.hooks.ts
index edbda07333..1f1df71304 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/TurnInto/TurnInto.hooks.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/TurnInto/TurnInto.hooks.ts
@@ -12,7 +12,7 @@ export function useTurnInto({ node, onClose }: { node: NestedBlock; onClose?: ()
const { controller, docId } = useSubscribeDocument();
const turnIntoBlock = useCallback(
- async (type: BlockType, isSelected: boolean, data?: BlockData<any>) => {
+ async (type: BlockType, isSelected: boolean, data?: BlockData) => {
if (!controller || isSelected) {
onClose?.();
return;
@@ -35,7 +35,7 @@ export function useTurnInto({ node, onClose }: { node: NestedBlock; onClose?: ()
);
onClose?.();
- dispatch(
+ await dispatch(
setRectSelectionThunk({
docId,
selection: [newBlockId as string],
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/TurnInto/index.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/TurnInto/index.tsx
index eb3661fb51..b1388ff6ce 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/TurnInto/index.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/TurnInto/index.tsx
@@ -57,7 +57,7 @@ const TurnIntoPopover = ({
icon: <Title />,
selected: node?.data?.level === 1,
onClick: (type: BlockType, isSelected: boolean) => {
- turnIntoHeading(1, isSelected);
+ void turnIntoHeading(1, isSelected);
},
},
{
@@ -67,7 +67,7 @@ const TurnIntoPopover = ({
icon: <Title />,
selected: node?.data?.level === 2,
onClick: (type: BlockType, isSelected: boolean) => {
- turnIntoHeading(2, isSelected);
+ void turnIntoHeading(2, isSelected);
},
},
{
@@ -77,7 +77,7 @@ const TurnIntoPopover = ({
icon: <Title />,
selected: node?.data?.level === 3,
onClick: (type: BlockType, isSelected: boolean) => {
- turnIntoHeading(3, isSelected);
+ void turnIntoHeading(3, isSelected);
},
},
{
@@ -143,7 +143,7 @@ const TurnIntoPopover = ({
(option: Option) => {
const isSelected = getSelected(option);
- option.onClick ? option.onClick(option.type, isSelected) : turnIntoBlock(option.type, isSelected);
+ option.onClick ? option.onClick(option.type, isSelected) : void turnIntoBlock(option.type, isSelected);
onOk?.();
},
[onOk, getSelected, turnIntoBlock]
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/UndoHooks/useUndoRedo.ts b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/UndoHooks/useUndoRedo.ts
index f9f3579963..3a101cac22 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/UndoHooks/useUndoRedo.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/UndoHooks/useUndoRedo.ts
@@ -6,25 +6,26 @@ import { useSubscribeDocument } from '$app/components/document/_shared/Subscribe
export function useUndoRedo(container: HTMLDivElement) {
const { controller } = useSubscribeDocument();
- const onUndo = useCallback(() => {
+ const onUndo = useCallback(async () => {
if (!controller) return;
- controller.undo();
+ await controller.undo();
}, [controller]);
- const onRedo = useCallback(() => {
+ const onRedo = useCallback(async () => {
if (!controller) return;
- controller.redo();
+ await controller.redo();
}, [controller]);
const handleKeyDownCapture = useCallback(
- (e: KeyboardEvent) => {
+ async (e: KeyboardEvent) => {
if (isHotkey(Keyboard.keys.UNDO, e)) {
e.stopPropagation();
- onUndo();
+ await onUndo();
}
+
if (isHotkey(Keyboard.keys.REDO, e)) {
e.stopPropagation();
- onRedo();
+ await onRedo();
}
},
[onRedo, onUndo]
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/UploadImage/ImageEditPopover.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/UploadImage/ImageEditPopover.tsx
index af31ae70c5..e341563d57 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/UploadImage/ImageEditPopover.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/UploadImage/ImageEditPopover.tsx
@@ -1,7 +1,6 @@
import React from 'react';
import Popover, { PopoverProps } from '@mui/material/Popover';
import ImageEdit from './ImageEdit';
-import { PopoverOrigin } from '@mui/material/Popover/Popover';
interface Props extends PopoverProps {
onSubmitUrl: (url: string) => void;
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/UploadImage/TabPanel.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/UploadImage/TabPanel.tsx
index 1f0f6ab4ef..9356a246aa 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/UploadImage/TabPanel.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/UploadImage/TabPanel.tsx
@@ -1,4 +1,5 @@
import React from 'react';
+
export enum TAB_KEYS {
UPLOAD = 'upload',
LINK = 'link',
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/UploadImage/UploadImage.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/UploadImage/UploadImage.tsx
index ecb14d7d2f..5990f5b5b9 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/UploadImage/UploadImage.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/UploadImage/UploadImage.tsx
@@ -42,6 +42,7 @@ function UploadImage({ onChange }: UploadImageProps) {
duration: 3000,
type: 'error',
});
+ // eslint-disable-next-line react-hooks/exhaustive-deps
}, [error]);
const handleUpload = useCallback(
@@ -74,7 +75,7 @@ function UploadImage({ onChange }: UploadImageProps) {
if (!files || files.length === 0) return;
const file = files[0];
- handleUpload(file);
+ void handleUpload(file);
},
[handleUpload]
);
@@ -87,7 +88,7 @@ function UploadImage({ onChange }: UploadImageProps) {
if (!files || files.length === 0) return;
const file = files[0];
- handleUpload(file);
+ void handleUpload(file);
},
[handleUpload]
);
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/useBindArrowKey.ts b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/useBindArrowKey.ts
index 8d2ac27796..29aebe52e9 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/useBindArrowKey.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/useBindArrowKey.ts
@@ -83,6 +83,7 @@ export const useBindArrowKey = ({
} else {
document.removeEventListener('keydown', handleArrowKey, true);
}
+
return () => {
document.removeEventListener('keydown', handleArrowKey, true);
};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/usePanelSearchText.ts b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/usePanelSearchText.ts
index 245041f702..034919e838 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/usePanelSearchText.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/document/_shared/usePanelSearchText.ts
@@ -25,9 +25,11 @@ export function useSubscribePanelSearchText({ blockId, open }: { blockId: string
beforeOpenDeltaRef.current = [];
return;
}
+
if (beforeOpenDeltaRef.current.length > 0) return;
const delta = new Delta(JSON.parse(deltaStr || "{}"));
+
beforeOpenDeltaRef.current = delta.ops;
handleSearch(delta);
}, [deltaStr, handleSearch, open]);
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/error/Error.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/components/error/Error.hooks.ts
index 2da03c5f5c..ceaa5a51a0 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/error/Error.hooks.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/error/Error.hooks.ts
@@ -1,6 +1,6 @@
-import { useAppDispatch, useAppSelector } from '../../stores/store';
-import { errorActions } from '../../stores/reducers/error/slice';
-import { useEffect, useState } from 'react';
+import { useAppDispatch, useAppSelector } from '$app/stores/store';
+import { errorActions } from '$app_reducers/error/slice';
+import { useCallback, useEffect, useState } from 'react';
export const useError = (e: Error) => {
const dispatch = useAppDispatch();
@@ -13,15 +13,18 @@ export const useError = (e: Error) => {
setErrorMessage(error.message);
}, [error]);
+ const showError = useCallback(
+ (msg: string) => {
+ dispatch(errorActions.showError(msg));
+ },
+ [dispatch]
+ );
+
useEffect(() => {
if (e) {
showError(e.message);
}
- }, [e]);
-
- const showError = (msg: string) => {
- dispatch(errorActions.showError(msg));
- };
+ }, [e, showError]);
const hideError = () => {
dispatch(errorActions.hideError());
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableCount/GridTableCount.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableCount/GridTableCount.tsx
index 727f831a81..51ffd11186 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableCount/GridTableCount.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableCount/GridTableCount.tsx
@@ -2,6 +2,7 @@ import { RowInfo } from '@/appflowy_app/stores/effects/database/row/row_cache';
export const GridTableCount = ({ rows }: { rows: readonly RowInfo[] }) => {
const count = rows.length;
+
return (
<span>
Count : <span className='font-semibold'>{count}</span>
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableHeader/GridTableHeaderItem.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableHeader/GridTableHeaderItem.tsx
index c4b85be45b..194709d40c 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableHeader/GridTableHeaderItem.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/grid/GridTableHeader/GridTableHeaderItem.tsx
@@ -53,7 +53,8 @@ export const GridTableHeaderItem = ({
if (newSizeX >= MIN_COLUMN_WIDTH) {
dispatch(databaseActions.changeWidth({ fieldId: field.fieldId, width: newSizeX }));
}
- }, [newSizeX]);
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [newSizeX, dispatch]);
const changeFieldType = async (newType: FieldType) => {
if (!editingField) return;
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/layout/Breadcrumb/Breadcrumb.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/components/layout/Breadcrumb/Breadcrumb.hooks.ts
index 2288657d7b..7063cea877 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/layout/Breadcrumb/Breadcrumb.hooks.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/layout/Breadcrumb/Breadcrumb.hooks.ts
@@ -1,9 +1,9 @@
-import { useAppSelector } from "$app/stores/store";
+import { useAppSelector } from '$app/stores/store';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { useParams, useLocation } from 'react-router-dom';
import { Page } from '$app_reducers/pages/slice';
import { useTranslation } from 'react-i18next';
-import { PageController } from "$app/stores/effects/workspace/page/page_controller";
+import { PageController } from '$app/stores/effects/workspace/page/page_controller';
export function useLoadExpandedPages() {
const { t } = useTranslation();
@@ -25,6 +25,7 @@ export function useLoadExpandedPages() {
async (pageId: string) => {
let page = pageMap[pageId];
const controller = new PageController(pageId);
+
if (!page) {
try {
page = await controller.getPage();
@@ -36,22 +37,22 @@ export function useLoadExpandedPages() {
return;
}
}
- setPagePath(prev => {
- return [
- page,
- ...prev
- ]
+
+ setPagePath((prev) => {
+ return [page, ...prev];
});
await loadPagePath(page.parentId);
-
- }, [pageMap]);
+ },
+ [pageMap]
+ );
useEffect(() => {
setPagePath([]);
if (!currentPageId) {
return;
}
- loadPagePath(currentPageId);
+
+ void loadPagePath(currentPageId);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [currentPageId]);
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/layout/NestedPage/NestedPage.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/components/layout/NestedPage/NestedPage.hooks.ts
index 7acd565087..428c77193b 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/layout/NestedPage/NestedPage.hooks.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/layout/NestedPage/NestedPage.hooks.ts
@@ -36,30 +36,30 @@ export function useLoadChildPages(pageId: string) {
[dispatch]
);
+ const loadPageChildren = useCallback(
+ async (pageId: string) => {
+ const childPages = await controller.getChildPages();
- const loadPageChildren = useCallback(async (pageId: string) => {
- const childPages = await controller.getChildPages();
-
- dispatch(
- pagesActions.addChildPages({
- id: pageId,
- childPages,
- })
- );
-
- }, [controller, dispatch]);
-
+ dispatch(
+ pagesActions.addChildPages({
+ id: pageId,
+ childPages,
+ })
+ );
+ },
+ [controller, dispatch]
+ );
useEffect(() => {
void loadPageChildren(pageId);
}, [loadPageChildren, pageId]);
useEffect(() => {
- controller.subscribe({
+ void controller.subscribe({
onPageChanged,
});
return () => {
- controller.dispose();
+ void controller.dispose();
};
}, [controller, onPageChanged]);
@@ -88,7 +88,7 @@ export function usePageActions(pageId: string) {
async (layout: ViewLayoutPB) => {
const newViewId = await controller.createPage({
layout,
- name: ""
+ name: '',
});
dispatch(pagesActions.expandPage(pageId));
@@ -116,7 +116,7 @@ export function usePageActions(pageId: string) {
useEffect(() => {
return () => {
- controller.dispose();
+ void controller.dispose();
};
}, [controller]);
@@ -134,4 +134,3 @@ export function useSelectedPage(pageId: string) {
return id === pageId;
}
-
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/layout/Share/Share.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/components/layout/Share/Share.hooks.ts
index 8cce47a2ab..b281706848 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/layout/Share/Share.hooks.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/layout/Share/Share.hooks.ts
@@ -1,4 +1,4 @@
-import { useLocation, useParams } from 'react-router-dom';
+import { useParams } from 'react-router-dom';
export function useShareConfig() {
const params = useParams();
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/layout/TopBar/MoreButton.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/layout/TopBar/MoreButton.tsx
index bf2d48d827..ca104218ab 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/layout/TopBar/MoreButton.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/layout/TopBar/MoreButton.tsx
@@ -1,8 +1,7 @@
-import React, { useCallback, useMemo } from 'react';
+import React, { useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { Drawer, IconButton } from '@mui/material';
import { Details2Svg } from '$app/components/_shared/svg/Details2Svg';
-import { LogoutOutlined } from '@mui/icons-material';
import Tooltip from '@mui/material/Tooltip';
import MoreOptions from '$app/components/layout/TopBar/MoreOptions';
import { useMoreOptionsConfig } from '$app/components/layout/TopBar/MoreOptions.hooks';
@@ -19,7 +18,7 @@ function MoreButton() {
return (
<>
<Tooltip placement={'bottom-end'} title={t('moreAction.moreOptions')}>
- <IconButton onClick={(e) => toggleDrawer(true)} className={'h-8 w-8 text-icon-primary'}>
+ <IconButton onClick={() => toggleDrawer(true)} className={'h-8 w-8 text-icon-primary'}>
<Details2Svg />
</IconButton>
</Tooltip>
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/layout/TopBar/MoreOptions.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/components/layout/TopBar/MoreOptions.hooks.ts
index 57b10a4fed..63f1173885 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/layout/TopBar/MoreOptions.hooks.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/layout/TopBar/MoreOptions.hooks.ts
@@ -4,7 +4,8 @@ import { useMemo } from 'react';
export function useMoreOptionsConfig() {
const location = useLocation();
- const { type, pageType, id } = useMemo(() => {
+ const { type, pageType } = useMemo(() => {
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
const [_, type, pageType, id] = location.pathname.split('/');
return {
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/layout/TopBar/MoreOptions.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/layout/TopBar/MoreOptions.tsx
index 97a48128f7..28f2b46759 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/layout/TopBar/MoreOptions.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/layout/TopBar/MoreOptions.tsx
@@ -1,12 +1,8 @@
import React from 'react';
-import { useTranslation } from 'react-i18next';
import FontSizeConfig from '$app/components/layout/TopBar/FontSizeConfig';
-import { Divider } from '@mui/material';
-import { useLocation } from 'react-router-dom';
import { useMoreOptionsConfig } from '$app/components/layout/TopBar/MoreOptions.hooks';
function MoreOptions() {
- const { t } = useTranslation();
const { showStyleOptions } = useMoreOptionsConfig();
return <div className={'flex w-[220px] flex-col'}>{showStyleOptions && <FontSizeConfig />}</div>;
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/layout/UserSetting/LanguageSetting.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/layout/UserSetting/LanguageSetting.tsx
index b2395d7645..bcd171f4c0 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/layout/UserSetting/LanguageSetting.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/layout/UserSetting/LanguageSetting.tsx
@@ -56,7 +56,7 @@ function LanguageSetting({
onChange({
language,
});
- i18n.changeLanguage(language);
+ void i18n.changeLanguage(language);
}}
>
{languages.map((option) => (
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/layout/UserSetting/index.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/layout/UserSetting/index.tsx
index 5b4ec98294..9fa5beabcf 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/layout/UserSetting/index.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/layout/UserSetting/index.tsx
@@ -30,7 +30,7 @@ function UserSettings({ open, onClose }: { open: boolean; onClose: () => void })
if (userSettingController) {
const language = newSetting.language || 'en';
- userSettingController.setAppearanceSetting({
+ void userSettingController.setAppearanceSetting({
theme: newSetting.theme || Theme.Default,
theme_mode: newSetting.themeMode || ThemeModePB.Light,
locale: {
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/layout/WorkspaceManager/NewPageButton.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/layout/WorkspaceManager/NewPageButton.tsx
index e2346fa7a9..ad405024a1 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/layout/WorkspaceManager/NewPageButton.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/layout/WorkspaceManager/NewPageButton.tsx
@@ -12,7 +12,7 @@ function NewPageButton({ workspaceId }: { workspaceId: string }) {
useEffect(() => {
return () => {
- controller.dispose();
+ void controller.dispose();
};
}, [controller]);
@@ -21,7 +21,7 @@ function NewPageButton({ workspaceId }: { workspaceId: string }) {
<button
onClick={async () => {
const { id } = await controller.createView({
- name: "",
+ name: '',
layout: ViewLayoutPB.Document,
parent_view_id: workspaceId,
});
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/layout/WorkspaceManager/Workspace.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/components/layout/WorkspaceManager/Workspace.hooks.ts
index a6e00bbbfe..e04bd734a0 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/layout/WorkspaceManager/Workspace.hooks.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/layout/WorkspaceManager/Workspace.hooks.ts
@@ -45,7 +45,7 @@ export function useLoadWorkspaces() {
})();
return () => {
- controller.dispose();
+ void controller.dispose();
};
}, [controller, initializeWorkspaces, subscribeToWorkspaces]);
@@ -85,6 +85,7 @@ export function useLoadWorkspace(workspace: WorkspaceItem) {
const initializeWorkspace = useCallback(async () => {
const childPages = await controller.getChildPages();
+
dispatch(
pagesActions.addChildPages({
id,
@@ -106,7 +107,7 @@ export function useLoadWorkspace(workspace: WorkspaceItem) {
})();
return () => {
- controller.dispose();
+ void controller.dispose();
};
}, [controller, initializeWorkspace, subscribeToWorkspace]);
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/layout/WorkspaceManager/Workspace.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/layout/WorkspaceManager/Workspace.tsx
index bafea58b3a..b30002777d 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/layout/WorkspaceManager/Workspace.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/layout/WorkspaceManager/Workspace.tsx
@@ -1,12 +1,8 @@
import React from 'react';
import { WorkspaceItem } from '$app_reducers/workspace/slice';
import NestedViews from '$app/components/layout/WorkspaceManager/NestedPages';
-import { useLoadWorkspace } from '$app/components/layout/WorkspaceManager/Workspace.hooks';
-import WorkspaceTitle from '$app/components/layout/WorkspaceManager/WorkspaceTitle';
function Workspace({ workspace, opened }: { workspace: WorkspaceItem; opened: boolean }) {
- const { openWorkspace, deleteWorkspace } = useLoadWorkspace(workspace);
-
return (
<div className={'flex h-[100%] flex-col'}>
<div
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/tests/DatabaseTestHelper.ts b/frontend/appflowy_tauri/src/appflowy_app/components/tests/DatabaseTestHelper.ts
index 98a91855a4..eb5ea8a909 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/tests/DatabaseTestHelper.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/tests/DatabaseTestHelper.ts
@@ -1,32 +1,23 @@
-import {
- FieldType,
- FlowyError,
- SingleSelectTypeOptionPB,
- ViewLayoutPB,
- ViewPB,
- WorkspaceSettingPB,
-} from '../../../services/backend';
-import { DatabaseController } from '../../stores/effects/database/database_controller';
-import { RowInfo } from '../../stores/effects/database/row/row_cache';
-import { RowController } from '../../stores/effects/database/row/row_controller';
+import { FieldType, SingleSelectTypeOptionPB, ViewLayoutPB, ViewPB, WorkspaceSettingPB } from '@/services/backend';
+import { DatabaseController } from '$app/stores/effects/database/database_controller';
+import { RowInfo } from '$app/stores/effects/database/row/row_cache';
+import { RowController } from '$app/stores/effects/database/row/row_controller';
import {
CellControllerBuilder,
CheckboxCellController,
DateCellController,
- NumberCellController,
SelectOptionCellController,
TextCellController,
URLCellController,
-} from '../../stores/effects/database/cell/controller_builder';
-import { None, Ok, Option, Result, Some } from 'ts-results';
-import { TypeOptionBackendService } from '../../stores/effects/database/field/type_option/type_option_bd_svc';
-import { DatabaseBackendService } from '../../stores/effects/database/database_bd_svc';
-import { FieldInfo } from '../../stores/effects/database/field/field_controller';
-import { TypeOptionController } from '../../stores/effects/database/field/type_option/type_option_controller';
-import { makeSingleSelectTypeOptionContext } from '../../stores/effects/database/field/type_option/type_option_context';
-import { SelectOptionBackendService } from '../../stores/effects/database/cell/select_option_bd_svc';
-import { Log } from '$app/utils/log';
-import { WorkspaceController } from '../../stores/effects/workspace/workspace_controller';
+} from '$app/stores/effects/database/cell/controller_builder';
+import { None, Option, Some } from 'ts-results';
+import { TypeOptionBackendService } from '$app/stores/effects/database/field/type_option/type_option_bd_svc';
+import { DatabaseBackendService } from '$app/stores/effects/database/database_bd_svc';
+import { FieldInfo } from '$app/stores/effects/database/field/field_controller';
+import { TypeOptionController } from '$app/stores/effects/database/field/type_option/type_option_controller';
+import { makeSingleSelectTypeOptionContext } from '$app/stores/effects/database/field/type_option/type_option_context';
+import { SelectOptionBackendService } from '$app/stores/effects/database/cell/select_option_bd_svc';
+import { WorkspaceController } from '$app/stores/effects/workspace/workspace_controller';
import { FolderEventGetCurrentWorkspaceSetting } from '@/services/backend/events/flowy-folder2';
// Create a database page for specific layout type
@@ -36,9 +27,8 @@ export async function createTestDatabaseView(layout: ViewLayoutPB): Promise<View
result.unwrap()
);
const wsSvc = new WorkspaceController(workspaceSetting.workspace_id);
- const viewRes = await wsSvc.createView({ name: 'New Grid', layout });
- return viewRes;
+ return await wsSvc.createView({ name: 'New Grid', layout });
}
export async function openTestDatabase(viewId: string): Promise<DatabaseController> {
@@ -92,18 +82,6 @@ export async function makeTextCellController(
return Some(builder.build() as TextCellController);
}
-export async function makeNumberCellController(
- fieldId: string,
- rowInfo: RowInfo,
- databaseController: DatabaseController
-): Promise<Option<NumberCellController>> {
- const builder = await makeCellControllerBuilder(fieldId, rowInfo, FieldType.Number, databaseController).then(
- (result) => result.unwrap()
- );
-
- return Some(builder.build() as NumberCellController);
-}
-
export async function makeSingleSelectCellController(
fieldId: string,
rowInfo: RowInfo,
@@ -167,7 +145,7 @@ export async function makeURLCellController(
export async function makeCellControllerBuilder(
fieldId: string,
rowInfo: RowInfo,
- fieldType: FieldType,
+ _fieldType: FieldType,
databaseController: DatabaseController
): Promise<Option<CellControllerBuilder>> {
const rowCache = databaseController.databaseViewCache.getRowCache();
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/tests/TestDocument.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/tests/TestDocument.tsx
index 8508232eb9..b6f70acb02 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/tests/TestDocument.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/tests/TestDocument.tsx
@@ -5,7 +5,8 @@ import { DocumentBackendService } from '../../stores/effects/document/document_b
async function testCreateDocument() {
const view = await createTestDocument();
const svc = new DocumentBackendService(view.id);
- const document = await svc.open().then((result) => result.unwrap());
+
+ await svc.open().then((result) => result.unwrap());
// eslint-disable-next-line @typescript-eslint/no-unused-vars
// const content = JSON.parse(document.content);
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/tests/TestFolder.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/tests/TestFolder.tsx
index 44585d039a..6e24aae8a1 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/tests/TestFolder.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/tests/TestFolder.tsx
@@ -33,7 +33,7 @@ const testCreateFolder = async (userId?: number) => {
}
for (let i = 1; i <= 3; i++) {
- const result = await workspaceService.createView({
+ await workspaceService.createView({
name: `test board 1 ${i}`,
desc: 'test description',
layout: ViewLayoutPB.Board,
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/tests/TestFonts.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/tests/TestFonts.tsx
index c2c5d5d13c..04e4c566a6 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/tests/TestFonts.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/tests/TestFonts.tsx
@@ -1,9 +1,9 @@
-import { useState } from 'react';
+import { ChangeEvent, useState } from 'react';
const TestFonts = () => {
const [sampleText, setSampleText] = useState('Sample Text');
- const onInputChange = (e: any) => {
+ const onInputChange = (e: ChangeEvent<HTMLInputElement>) => {
setSampleText(e.target.value);
};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/tests/TestGrid.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/tests/TestGrid.tsx
index d4345b6760..e9e687a923 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/tests/TestGrid.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/tests/TestGrid.tsx
@@ -65,6 +65,7 @@ export const RunAllGridTests = () => {
async function createBuildInGrid() {
const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id);
+
databaseController.subscribe({
onViewChanged: (databasePB) => {
Log.debug('Did receive database:' + databasePB);
@@ -87,11 +88,13 @@ async function createBuildInGrid() {
async function testEditGridCell() {
const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id);
+
await databaseController.open().then((result) => result.unwrap());
for (const [index, row] of databaseController.databaseViewCache.rowInfos.entries()) {
const cellContent = index.toString();
const fieldInfo = findFirstFieldInfoWithFieldType(row, FieldType.RichText).unwrap();
+
await editTextCell(fieldInfo.field.id, row, databaseController, cellContent);
await assertTextCell(fieldInfo.field.id, row, databaseController, cellContent);
}
@@ -100,6 +103,7 @@ async function testEditGridCell() {
async function testEditTextCell() {
const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id);
+
await databaseController.open().then((result) => result.unwrap());
const row = databaseController.databaseViewCache.rowInfos[0];
@@ -122,9 +126,11 @@ async function testEditTextCell() {
async function testEditURLCell() {
const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id);
+
await databaseController.open().then((result) => result.unwrap());
const typeOptionController = new TypeOptionController(view.id, None, FieldType.URL);
+
await typeOptionController.initialize();
const row = databaseController.databaseViewCache.rowInfos[0];
@@ -135,6 +141,7 @@ async function testEditURLCell() {
urlCellController.subscribeChanged({
onCellChanged: (content) => {
const pb = content.unwrap();
+
Log.info('Receive url data:', pb.url, pb.content);
},
});
@@ -149,9 +156,11 @@ async function testEditURLCell() {
async function testEditDateCell() {
const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id);
+
await databaseController.open().then((result) => result.unwrap());
const typeOptionController = new TypeOptionController(view.id, None, FieldType.DateTime);
+
await typeOptionController.initialize();
const row = databaseController.databaseViewCache.rowInfos[0];
@@ -162,11 +171,13 @@ async function testEditDateCell() {
dateCellController.subscribeChanged({
onCellChanged: (content) => {
const pb = content.unwrap();
+
Log.info('Receive date data:', pb.date, pb.time);
},
});
const date = new CalendarData(new Date(), true, '13:00');
+
await dateCellController.saveCellData(date);
await new Promise((resolve) => setTimeout(resolve, 200));
}
@@ -174,15 +185,18 @@ async function testEditDateCell() {
async function testEditDateFormatPB() {
const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id);
+
await databaseController.open().then((result) => result.unwrap());
// Create date field
const typeOptionController = new TypeOptionController(view.id, None, FieldType.DateTime);
+
await typeOptionController.initialize();
// update date type option
const dateTypeOptionContext = makeDateTypeOptionContext(typeOptionController);
const typeOption = await dateTypeOptionContext.getTypeOption().then((a) => a.unwrap());
+
assert(typeOption.date_format === DateFormatPB.Friendly, 'Date format not match');
assert(typeOption.time_format === TimeFormatPB.TwentyFourHour, 'Time format not match');
typeOption.date_format = DateFormatPB.Local;
@@ -190,6 +204,7 @@ async function testEditDateFormatPB() {
await dateTypeOptionContext.setTypeOption(typeOption);
const typeOption2 = await dateTypeOptionContext.getTypeOption().then((a) => a.unwrap());
+
assert(typeOption2.date_format === DateFormatPB.Local, 'Date format not match');
assert(typeOption2.time_format === TimeFormatPB.TwelveHour, 'Time format not match');
@@ -199,20 +214,24 @@ async function testEditDateFormatPB() {
async function testEditNumberFormatPB() {
const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id);
+
await databaseController.open().then((result) => result.unwrap());
// Create date field
const typeOptionController = new TypeOptionController(view.id, None, FieldType.Number);
+
await typeOptionController.initialize();
// update date type option
const dateTypeOptionContext = makeNumberTypeOptionContext(typeOptionController);
const typeOption = await dateTypeOptionContext.getTypeOption().then((a) => a.unwrap());
+
typeOption.format = NumberFormatPB.EUR;
typeOption.name = 'Money';
await dateTypeOptionContext.setTypeOption(typeOption);
const typeOption2 = await dateTypeOptionContext.getTypeOption().then((a) => a.unwrap());
+
Log.info(typeOption2);
await new Promise((resolve) => setTimeout(resolve, 200));
}
@@ -220,9 +239,11 @@ async function testEditNumberFormatPB() {
async function testCheckboxCell() {
const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id);
+
await databaseController.open().then((result) => result.unwrap());
const typeOptionController = new TypeOptionController(view.id, None, FieldType.Checkbox);
+
await typeOptionController.initialize();
const row = databaseController.databaseViewCache.rowInfos[0];
@@ -235,6 +256,7 @@ async function testCheckboxCell() {
checkboxCellController.subscribeChanged({
onCellChanged: (content) => {
const pb = content.unwrap();
+
Log.info('Receive checkbox data:', pb);
},
});
@@ -246,6 +268,7 @@ async function testCheckboxCell() {
async function testCreateRow() {
const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id);
+
await databaseController.open().then((result) => result.unwrap());
await assertNumberOfRows(view.id, 3);
@@ -258,9 +281,11 @@ async function testCreateRow() {
async function testDeleteRow() {
const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id);
+
await databaseController.open().then((result) => result.unwrap());
const rows = databaseController.databaseViewCache.rowInfos;
+
await databaseController.deleteRow(rows[0].row.id);
await assertNumberOfRows(view.id, 2);
@@ -270,12 +295,14 @@ async function testDeleteRow() {
if (databaseController.databaseViewCache.rowInfos.length !== 2) {
throw Error('The number of rows is not match');
}
+
await databaseController.dispose();
}
async function testCreateOptionInCell() {
const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id);
+
await databaseController.open().then((result) => result.unwrap());
for (const [index, row] of databaseController.databaseViewCache.rowInfos.entries()) {
if (index === 0) {
@@ -283,39 +310,47 @@ async function testCreateOptionInCell() {
const cellController = await makeSingleSelectCellController(fieldInfo.field.id, row, databaseController).then(
(result) => result.unwrap()
);
+
// eslint-disable-next-line @typescript-eslint/await-thenable
await cellController.subscribeChanged({
onCellChanged: (value) => {
if (value.some) {
const option: SelectOptionCellDataPB = value.unwrap();
+
console.log(option);
}
},
});
const backendSvc = new SelectOptionCellBackendService(cellController.cellIdentifier);
+
await backendSvc.createOption({ name: 'option' + index });
await cellController.dispose();
}
}
+
await databaseController.dispose();
}
async function testMoveField() {
const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id);
+
await databaseController.open().then((result) => result.unwrap());
const ids = databaseController.fieldController.fieldInfos.map((value) => value.field.id);
+
Log.info('Receive fields data:', ids);
databaseController.subscribe({
onFieldsChanged: (values) => {
const new_ids = values.map((value) => value.field.id);
+
Log.info('Receive fields data:', new_ids);
},
});
const fieldInfos = [...databaseController.fieldController.fieldInfos];
const field_id = fieldInfos[0].field.id;
+
await databaseController.moveField({ fieldId: field_id, fromIndex: 0, toIndex: 1 });
await new Promise((resolve) => setTimeout(resolve, 200));
assert(databaseController.fieldController.fieldInfos[1].field.id === field_id);
@@ -324,6 +359,7 @@ async function testMoveField() {
async function testGetSingleSelectFieldData() {
const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id);
+
await databaseController.open().then((result) => result.unwrap());
// Find the single select column
@@ -341,6 +377,7 @@ async function testGetSingleSelectFieldData() {
// Read options
const options = await singleSelectTypeOptionContext.getTypeOption().then((result) => result.unwrap());
+
console.log(options);
await databaseController.dispose();
@@ -349,6 +386,7 @@ async function testGetSingleSelectFieldData() {
async function testSwitchFromSingleSelectToNumber() {
const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id);
+
await databaseController.open().then((result) => result.unwrap());
// Find the single select column
@@ -357,6 +395,7 @@ async function testSwitchFromSingleSelectToNumber() {
(fieldInfo) => fieldInfo.field.field_type === FieldType.SingleSelect
)!;
const typeOptionController = new TypeOptionController(view.id, Some(singleSelect));
+
await typeOptionController.switchToField(FieldType.Number);
// Check the number type option
@@ -365,6 +404,7 @@ async function testSwitchFromSingleSelectToNumber() {
.getTypeOption()
.then((result) => result.unwrap());
const format: NumberFormatPB = numberTypeOption.format;
+
if (format !== NumberFormatPB.Num) {
throw Error('The default format should be number');
}
@@ -375,10 +415,12 @@ async function testSwitchFromSingleSelectToNumber() {
async function testSwitchFromMultiSelectToRichText() {
const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id);
+
await databaseController.open().then((result) => result.unwrap());
// Create multi-select field
const typeOptionController = new TypeOptionController(view.id, None, FieldType.MultiSelect);
+
await typeOptionController.initialize();
// Insert options to first row
@@ -391,11 +433,13 @@ async function testSwitchFromMultiSelectToRichText() {
databaseController
).then((result) => result.unwrap());
const backendSvc = new SelectOptionCellBackendService(selectOptionCellController.cellIdentifier);
+
await backendSvc.createOption({ name: 'A' });
await backendSvc.createOption({ name: 'B' });
await backendSvc.createOption({ name: 'C' });
const selectOptionCellData = await selectOptionCellController.getCellData().then((result) => result.unwrap());
+
if (selectOptionCellData.options.length !== 3) {
throw Error('The options should equal to 3');
}
@@ -403,6 +447,7 @@ async function testSwitchFromMultiSelectToRichText() {
if (selectOptionCellData.select_options.length !== 3) {
throw Error('The selected options should equal to 3');
}
+
await selectOptionCellController.dispose();
// Switch to RichText field type
@@ -415,6 +460,7 @@ async function testSwitchFromMultiSelectToRichText() {
(result) => result.unwrap()
);
const cellContent = await textCellController.getCellData();
+
if (cellContent.unwrap() !== 'A,B,C') {
throw Error('The cell content should be A,B,C, but receive: ' + cellContent.unwrap());
}
@@ -425,14 +471,17 @@ async function testSwitchFromMultiSelectToRichText() {
async function testEditField() {
const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id);
+
await databaseController.open().then((result) => result.unwrap());
const fieldInfos = databaseController.fieldController.fieldInfos;
// Modify the name of the field
const firstFieldInfo = fieldInfos[0];
const controller = new TypeOptionController(view.id, Some(firstFieldInfo));
+
await controller.initialize();
const newName = 'hello world';
+
await controller.setFieldName(newName);
await new Promise((resolve) => setTimeout(resolve, 200));
@@ -443,11 +492,13 @@ async function testEditField() {
async function testCreateNewField() {
const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id);
+
await databaseController.open().then((result) => result.unwrap());
await assertNumberOfFields(view.id, 3);
// Modify the name of the field
const controller = new TypeOptionController(view.id, None);
+
await controller.initialize();
await assertNumberOfFields(view.id, 4);
await databaseController.dispose();
@@ -456,6 +507,7 @@ async function testCreateNewField() {
async function testDeleteField() {
const view = await createTestDatabaseView(ViewLayoutPB.Grid);
const databaseController = await openTestDatabase(view.id);
+
await databaseController.open().then((result) => result.unwrap());
// Modify the name of the field.
@@ -463,6 +515,7 @@ async function testDeleteField() {
// So let choose the second fieldInfo.
const fieldInfo = databaseController.fieldController.fieldInfos[1];
const controller = new TypeOptionController(view.id, Some(fieldInfo));
+
await controller.initialize();
await assertNumberOfFields(view.id, 3);
await controller.deleteField();
@@ -485,24 +538,31 @@ export const TestEditTextCell = () => {
export const TestEditURLCell = () => {
return TestButton('Test editing URL cell', testEditURLCell);
};
+
export const TestEditDateCell = () => {
return TestButton('Test editing date cell', testEditDateCell);
};
+
export const TestEditDateFormat = () => {
return TestButton('Test editing date format', testEditDateFormatPB);
};
+
export const TestEditNumberFormat = () => {
return TestButton('Test editing number format', testEditNumberFormatPB);
};
+
export const TestEditCheckboxCell = () => {
return TestButton('Test editing checkbox cell', testCheckboxCell);
};
+
export const TestCreateRow = () => {
return TestButton('Test create row', testCreateRow);
};
+
export const TestDeleteRow = () => {
return TestButton('Test delete row', testDeleteRow);
};
+
export const TestCreateSelectOptionInCell = () => {
return TestButton('Test create a select option in cell', testCreateOptionInCell);
};
@@ -522,6 +582,7 @@ export const TestSwitchFromMultiSelectToText = () => {
export const TestMoveField = () => {
return TestButton('Test move field', testMoveField);
};
+
export const TestEditField = () => {
return TestButton('Test edit the column name', testEditField);
};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/tests/TestGroup.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/tests/TestGroup.tsx
index 31ea758924..c161eeeeb1 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/tests/TestGroup.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/tests/TestGroup.tsx
@@ -31,6 +31,7 @@ export const TestAllKanbanTests = () => {
async function createBuildInBoard() {
const view = await createTestDatabaseView(ViewLayoutPB.Board);
const databaseController = await openTestDatabase(view.id);
+
databaseController.subscribe({
onGroupByField: (groups) => {
console.log(groups);
@@ -51,10 +52,12 @@ async function createBuildInBoard() {
async function createKanbanBoardRow() {
const view = await createTestDatabaseView(ViewLayoutPB.Board);
const databaseController = await openTestDatabase(view.id);
+
await databaseController.open().then((result) => result.unwrap());
// Create row in no status group
const noStatusGroup = databaseController.groups.getValue()[0];
+
await noStatusGroup.createRow().then((result) => result.unwrap());
await assertNumberOfRowsInGroup(view.id, noStatusGroup.groupId, 1);
@@ -64,11 +67,13 @@ async function createKanbanBoardRow() {
async function moveKanbanBoardRow() {
const view = await createTestDatabaseView(ViewLayoutPB.Board);
const databaseController = await openTestDatabase(view.id);
+
await databaseController.open().then((result) => result.unwrap());
// Create row in no status group
const firstGroup = databaseController.groups.getValue()[1];
const secondGroup = databaseController.groups.getValue()[2];
+
// subscribe the group changes
firstGroup.subscribe({
onRemoveRow: (groupId, deleteRowId) => {
@@ -101,6 +106,7 @@ async function moveKanbanBoardRow() {
});
const row = firstGroup.rowAtIndex(0).unwrap();
+
await databaseController.moveGroupRow(row.id, secondGroup.groupId);
assert(firstGroup.rows.length === 2);
@@ -115,11 +121,13 @@ async function moveKanbanBoardRow() {
async function createKanbanBoardColumn() {
const view = await createTestDatabaseView(ViewLayoutPB.Board);
const databaseController = await openTestDatabase(view.id);
+
await databaseController.open().then((result) => result.unwrap());
// Create row in no status group
const firstGroup = databaseController.groups.getValue()[1];
const secondGroup = databaseController.groups.getValue()[2];
+
await databaseController.moveGroup(firstGroup.groupId, secondGroup.groupId);
assert(databaseController.groups.getValue()[1].groupId === secondGroup.groupId);
@@ -130,6 +138,7 @@ async function createKanbanBoardColumn() {
async function createColumnInBoard() {
const view = await createTestDatabaseView(ViewLayoutPB.Board);
const databaseController = await openTestDatabase(view.id);
+
await databaseController.open().then((result) => result.unwrap());
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -139,6 +148,7 @@ async function createColumnInBoard() {
// Create a option which will cause creating a new group
const name = 'New column';
+
await createSingleSelectOptions(view.id, singleSelect, [name]);
// Wait the backend posting the notification to update the groups
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/trash/Trash.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/components/trash/Trash.hooks.ts
index a95ae94a77..9948a2b189 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/trash/Trash.hooks.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/trash/Trash.hooks.ts
@@ -17,7 +17,7 @@ export function useLoadTrash() {
}, [controller, dispatch]);
const subscribeToTrash = useCallback(async () => {
- controller.subscribe({
+ await controller.subscribe({
onTrashChanged: (trash) => {
dispatch(trashActions.onTrashChanged(trash.map(trashPBToTrash)));
},
@@ -33,7 +33,7 @@ export function useLoadTrash() {
useEffect(() => {
return () => {
- controller.dispose();
+ void controller.dispose();
};
}, [controller]);
@@ -52,7 +52,7 @@ export function useTrashActions() {
useEffect(() => {
return () => {
- controller.dispose();
+ void controller.dispose();
};
}, [controller]);
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/trash/Trash.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/trash/Trash.tsx
index 23a78a9bef..6387437162 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/trash/Trash.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/trash/Trash.tsx
@@ -28,11 +28,11 @@ function Trash() {
<div className={'flex items-center justify-between'}>
<div className={'text-2xl font-bold'}>{t('trash.text')}</div>
<div className={'flex items-center justify-end'}>
- <Button color={'inherit'} onClick={(e) => onClickRestoreAll()}>
+ <Button color={'inherit'} onClick={() => onClickRestoreAll()}>
<RestoreOutlined />
<span className={'ml-1'}>{t('trash.restoreAll')}</span>
</Button>
- <Button color={'error'} onClick={(e) => onClickDeleteAll()}>
+ <Button color={'error'} onClick={() => onClickDeleteAll()}>
<DeleteOutline />
<span className={'ml-1'}>{t('trash.deleteAll')}</span>
</Button>
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/trash/TrashItem.tsx b/frontend/appflowy_tauri/src/appflowy_app/components/trash/TrashItem.tsx
index 78ce773423..3d970257fd 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/trash/TrashItem.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/trash/TrashItem.tsx
@@ -23,10 +23,10 @@ function TrashItem({
return (
<ListItem
- onMouseEnter={(e) => {
+ onMouseEnter={() => {
setHoverId(item.id);
}}
- onMouseLeave={(e) => {
+ onMouseLeave={() => {
setHoverId('');
}}
key={item.id}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/user/application/notifications/parser.ts b/frontend/appflowy_tauri/src/appflowy_app/components/user/application/notifications/parser.ts
index 4e3a57af4b..866d910e83 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/user/application/notifications/parser.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/user/application/notifications/parser.ts
@@ -10,6 +10,7 @@ export class UserNotificationParser extends NotificationParser<UserNotification>
params.callback,
(ty) => {
const notification = UserNotification[ty];
+
if (isUserNotification(notification)) {
return UserNotification[notification];
} else {
diff --git a/frontend/appflowy_tauri/src/appflowy_app/components/user/application/notifications/user_listener.ts b/frontend/appflowy_tauri/src/appflowy_app/components/user/application/notifications/user_listener.ts
index d63963eaf0..112ee9b6a2 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/components/user/application/notifications/user_listener.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/components/user/application/notifications/user_listener.ts
@@ -18,6 +18,7 @@ export class UserNotificationListener extends AFNotificationObserver<UserNotific
} else {
this.onProfileUpdate?.(result);
}
+
break;
default:
break;
@@ -26,6 +27,7 @@ export class UserNotificationListener extends AFNotificationObserver<UserNotific
id: params.userId,
onError: params.onError,
});
+
super(parser);
this.onProfileUpdate = params.onProfileUpdate;
}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/hooks/ViewId.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/hooks/ViewId.hooks.ts
new file mode 100644
index 0000000000..6711ece8c8
--- /dev/null
+++ b/frontend/appflowy_tauri/src/appflowy_app/hooks/ViewId.hooks.ts
@@ -0,0 +1,6 @@
+import { createContext, useContext } from 'react';
+
+const ViewIdContext = createContext('');
+
+export const ViewIdProvider = ViewIdContext.Provider;
+export const useViewId = () => useContext(ViewIdContext);
diff --git a/frontend/appflowy_tauri/src/appflowy_app/hooks/index.ts b/frontend/appflowy_tauri/src/appflowy_app/hooks/index.ts
index d9223c236b..c29ddd04aa 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/hooks/index.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/hooks/index.ts
@@ -1 +1,2 @@
export * from './notification.hooks';
+export * from './ViewId.hooks';
diff --git a/frontend/appflowy_tauri/src/appflowy_app/hooks/notification.hooks.ts b/frontend/appflowy_tauri/src/appflowy_app/hooks/notification.hooks.ts
index 87327b71be..5c1efe43db 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/hooks/notification.hooks.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/hooks/notification.hooks.ts
@@ -1,9 +1,8 @@
/* eslint-disable no-redeclare */
+/* eslint-disable @typescript-eslint/no-explicit-any */
import { useEffect } from 'react';
import { listen } from '@tauri-apps/api/event';
-import { Ok, Err, Result } from 'ts-results';
import { SubscribeObject } from '@/services/backend/models/flowy-notification';
-import { FlowyError } from '@/services/backend/models/flowy-error';
import {
DatabaseFieldChangesetPB,
DatabaseNotification,
@@ -14,33 +13,39 @@ import {
ReorderSingleRowPB,
RowsChangePB,
RowsVisibilityChangePB,
+ SortChangesetNotificationPB,
} from '@/services/backend';
const NotificationPBMap = {
[DatabaseNotification.DidUpdateViewRowsVisibility]: RowsVisibilityChangePB,
[DatabaseNotification.DidUpdateViewRows]: RowsChangePB,
[DatabaseNotification.DidReorderRows]: ReorderAllRowsPB,
- [DatabaseNotification.DidReorderSingleRow]:ReorderSingleRowPB,
- [DatabaseNotification.DidUpdateFields]:DatabaseFieldChangesetPB,
- [DatabaseNotification.DidGroupByField]:GroupChangesPB,
- [DatabaseNotification.DidUpdateNumOfGroups]:GroupChangesPB,
+ [DatabaseNotification.DidReorderSingleRow]: ReorderSingleRowPB,
+ [DatabaseNotification.DidUpdateFields]: DatabaseFieldChangesetPB,
+ [DatabaseNotification.DidGroupByField]: GroupChangesPB,
+ [DatabaseNotification.DidUpdateNumOfGroups]: GroupChangesPB,
[DatabaseNotification.DidUpdateGroupRow]: GroupRowsNotificationPB,
[DatabaseNotification.DidUpdateField]: FieldPB,
[DatabaseNotification.DidUpdateCell]: null,
+ [DatabaseNotification.DidUpdateSort]: SortChangesetNotificationPB,
};
type NotificationMap = typeof NotificationPBMap;
type NotificationEnum = keyof NotificationMap;
-type NullableInstanceType<K extends ((abstract new (...args: any) => any) | null)> = K extends (abstract new (...args: any) => any) ? InstanceType<K> : void;
+type NullableInstanceType<K extends (abstract new (...args: any) => any) | null> = K extends abstract new (
+ ...args: any
+) => any
+ ? InstanceType<K>
+ : void;
-type NotificationHandler<K extends NotificationEnum> = (result: Result<NullableInstanceType<NotificationMap[K]>, FlowyError>) => void;
+type NotificationHandler<K extends NotificationEnum> = (result: NullableInstanceType<NotificationMap[K]>) => void;
/**
* Subscribes to a set of notifications.
- *
- * This function subscribes to notifications defined by the `NotificationEnum` and
+ *
+ * This function subscribes to notifications defined by the `NotificationEnum` and
* calls the appropriate `NotificationHandler` when each type of notification is received.
*
* @param {Object} callbacks - An object containing handlers for various notification types.
@@ -48,9 +53,9 @@ type NotificationHandler<K extends NotificationEnum> = (result: Result<NullableI
*
* @param {Object} [options] - Optional settings for the subscription.
* @param {string} [options.id] - An optional ID. If provided, only notifications with a matching ID will be processed.
- *
+ *
* @returns {Promise<() => void>} A Promise that resolves to an unsubscribe function.
- *
+ *
* @example
* subscribeNotifications({
* [DatabaseNotification.DidUpdateField]: (result) => {
@@ -75,16 +80,16 @@ type NotificationHandler<K extends NotificationEnum> = (result: Result<NullableI
* // ...
* // To unsubscribe, call `unsubscribe()`
* });
- *
+ *
* @throws {Error} Throws an error if unable to subscribe.
*/
export function subscribeNotifications(
callbacks: {
[K in NotificationEnum]?: NotificationHandler<K>;
},
- options?: { id?: string },
+ options?: { id?: string }
): Promise<() => void> {
- return listen<ReturnType<typeof SubscribeObject.prototype.toObject>>('af-notification', event => {
+ return listen<ReturnType<typeof SubscribeObject.prototype.toObject>>('af-notification', (event) => {
const subject = SubscribeObject.fromObject(event.payload);
const { id, ty } = subject;
@@ -101,13 +106,12 @@ export function subscribeNotifications(
}
if (subject.has_error) {
- const error = FlowyError.deserializeBinary(subject.error);
-
- callback(Err(error));
+ // const error = FlowyError.deserialize(subject.error);
+ return;
} else {
const { payload } = subject;
- callback(pb ? Ok(pb.deserializeBinary(payload)) : Ok.EMPTY);
+ pb ? callback(pb.deserialize(payload)) : callback();
}
});
}
@@ -115,7 +119,7 @@ export function subscribeNotifications(
export function subscribeNotification<K extends NotificationEnum>(
notification: K,
callback: NotificationHandler<K>,
- options?: { id?: string },
+ options?: { id?: string }
): Promise<() => void> {
return subscribeNotifications({ [notification]: callback }, options);
}
@@ -123,7 +127,7 @@ export function subscribeNotification<K extends NotificationEnum>(
export function useNotification<K extends NotificationEnum>(
notification: K,
callback: NotificationHandler<K>,
- options: { id?: string },
+ options: { id?: string }
): void {
const { id } = options;
@@ -131,7 +135,7 @@ export function useNotification<K extends NotificationEnum>(
const unsubscribePromise = subscribeNotification(notification, callback, { id });
return () => {
- void unsubscribePromise.then(fn => fn());
+ void unsubscribePromise.then((fn) => fn());
};
}, [callback, id, notification]);
}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/i18n/config.ts b/frontend/appflowy_tauri/src/appflowy_app/i18n/config.ts
index 59f0d77cf2..202b6a4220 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/i18n/config.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/i18n/config.ts
@@ -3,7 +3,7 @@ import LanguageDetector from 'i18next-browser-languagedetector';
import { initReactI18next } from 'react-i18next';
import resourcesToBackend from 'i18next-resources-to-backend';
-i18next
+void i18next
.use(resourcesToBackend((language: string) => import(`./translations/${language}.json`)))
.use(LanguageDetector)
.use(initReactI18next)
diff --git a/frontend/appflowy_tauri/src/appflowy_app/interfaces/database/index.ts b/frontend/appflowy_tauri/src/appflowy_app/interfaces/database/index.ts
deleted file mode 100644
index a478f9c12d..0000000000
--- a/frontend/appflowy_tauri/src/appflowy_app/interfaces/database/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-export * from './types';
-export * from './transform';
diff --git a/frontend/appflowy_tauri/src/appflowy_app/interfaces/database/transform.ts b/frontend/appflowy_tauri/src/appflowy_app/interfaces/database/transform.ts
deleted file mode 100644
index cb35f1e8e2..0000000000
--- a/frontend/appflowy_tauri/src/appflowy_app/interfaces/database/transform.ts
+++ /dev/null
@@ -1,72 +0,0 @@
-import { CellPB, ChecklistCellDataPB, DateCellDataPB, FieldPB, FieldType, SelectOptionCellDataPB, URLCellDataPB } from '@/services/backend';
-import type { Database } from './types';
-
-export const fieldPbToField = (fieldPb: FieldPB): Database.Field => ({
- id: fieldPb.id,
- name: fieldPb.name,
- type: fieldPb.field_type,
- visibility: fieldPb.visibility,
- width: fieldPb.width,
- isPrimary: fieldPb.is_primary,
-});
-
-const toDateCellData = (pb: DateCellDataPB): Database.DateTimeCellData => ({
- date: pb.date,
- time: pb.time,
- timestamp: pb.timestamp,
- includeTime: pb.include_time,
-});
-
-const toSelectCellData = (pb: SelectOptionCellDataPB): Database.SelectCellData => {
- return {
- options: pb.options.map(option => ({
- id: option.id,
- name: option.name,
- color: option.color,
- })),
- selectOptions: pb.select_options.map(option => ({
- id: option.id,
- name: option.name,
- color: option.color,
- })),
- };
-};
-
-const toURLCellData = (pb: URLCellDataPB): Database.UrlCellData => ({
- url: pb.url,
- content: pb.content,
-});
-
-const toChecklistCellData = (pb: ChecklistCellDataPB): Database.ChecklistCellData => ({
- selectedOptions: pb.selected_options.map(({ id }) => id),
- percentage: pb.percentage,
-});
-
-function parseCellData(fieldType: FieldType, data: Uint8Array) {
- switch (fieldType) {
- case FieldType.RichText:
- case FieldType.Number:
- case FieldType.Checkbox:
- return new TextDecoder().decode(data);
- case FieldType.DateTime:
- case FieldType.LastEditedTime:
- case FieldType.CreatedTime:
- return toDateCellData(DateCellDataPB.deserializeBinary(data));
- case FieldType.SingleSelect:
- case FieldType.MultiSelect:
- return toSelectCellData(SelectOptionCellDataPB.deserializeBinary(data));
- case FieldType.URL:
- return toURLCellData(URLCellDataPB.deserializeBinary(data));
- case FieldType.Checklist:
- return toChecklistCellData(ChecklistCellDataPB.deserializeBinary(data));
- }
-}
-
-export const cellPbToCell = (cellPb: CellPB, fieldType: FieldType): Database.Cell => {
- return {
- rowId: cellPb.row_id,
- fieldId: cellPb.field_id,
- fieldType: fieldType,
- data: parseCellData(fieldType, cellPb.data),
- };
-};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/interfaces/database/types.ts b/frontend/appflowy_tauri/src/appflowy_app/interfaces/database/types.ts
deleted file mode 100644
index 445406c490..0000000000
--- a/frontend/appflowy_tauri/src/appflowy_app/interfaces/database/types.ts
+++ /dev/null
@@ -1,227 +0,0 @@
-import {
- CalendarLayoutPB,
- DatabaseLayoutPB,
- DateFormatPB,
- FieldType,
- NumberFormatPB,
- SelectOptionColorPB,
- SelectOptionConditionPB,
- SortConditionPB,
- TextFilterConditionPB,
- TimeFormatPB,
-} from '@/services/backend';
-
-
-export interface Database {
- id: string;
- viewId: string;
- name: string;
- fields: Database.UndeterminedField[];
- rows: Database.Row[];
- layoutType: DatabaseLayoutPB;
- layoutSetting: Database.GridLayoutSetting | Database.CalendarLayoutSetting;
- isLinked: boolean;
-}
-
-// eslint-disable-next-line @typescript-eslint/no-namespace, no-redeclare
-export namespace Database {
-
- export interface GridLayoutSetting {
- filters?: UndeterminedFilter[];
- groups?: Group[];
- sorts?: Sort[];
- }
-
- export interface CalendarLayoutSetting {
- fieldId?: string;
- layoutTy?: CalendarLayoutPB;
- firstDayOfWeek?: number;
- showWeekends?: boolean;
- showWeekNumbers?: boolean;
- }
-
- export interface Field {
- id: string;
- name: string;
- type: FieldType;
- typeOption?: unknown;
- visibility?: boolean;
- width?: number;
- isPrimary?: boolean;
- }
-
- export interface NumberTypeOption {
- format?: NumberFormatPB;
- scale?: number;
- symbol?: string;
- name?: string;
- }
-
- export interface NumberField extends Field {
- type: FieldType.Number;
- typeOption: NumberTypeOption;
- }
-
- export interface DateTimeTypeOption {
- dateFormat?: DateFormatPB;
- timeFormat?: TimeFormatPB;
- timezoneId?: string;
- fieldType?: FieldType;
- }
-
- export interface DateTimeField extends Field {
- type: FieldType.DateTime;
- typeOption: DateTimeTypeOption;
- }
-
- export interface SelectOption {
- id: string;
- name: string;
- color: SelectOptionColorPB;
- }
-
- export interface SelectTypeOption {
- options?: SelectOption[];
- disableColor?: boolean;
- }
-
- export interface SelectField extends Field {
- type: FieldType.SingleSelect | FieldType.MultiSelect;
- typeOption: SelectTypeOption;
- }
-
- export interface ChecklistTypeOption {
- config?: string;
- }
-
- export interface ChecklistField extends Field {
- type: FieldType.Checklist;
- typeOption: ChecklistTypeOption;
- }
-
- export type UndeterminedField = NumberField | DateTimeField | SelectField | ChecklistField | Field;
-
- export interface Sort {
- id: string;
- fieldId: string;
- fieldType: FieldType;
- condition: SortConditionPB;
- }
-
- export interface Group {
- id: string;
- fieldId: string;
- }
-
- export interface Filter {
- id: string;
- fieldId: string;
- fieldType: FieldType;
- data: unknown;
- }
-
- export interface TextFilter extends Filter {
- fieldType: FieldType.RichText;
- data: TextFilterCondition;
- }
-
- export interface TextFilterCondition {
- condition?: TextFilterConditionPB;
- content?: string;
- }
-
- export interface SelectFilter extends Filter {
- fieldType: FieldType.SingleSelect | FieldType.MultiSelect;
- data: SelectFilterCondition;
- }
-
- export interface SelectFilterCondition {
- condition?: SelectOptionConditionPB;
- /**
- * link to [SelectOption's id property]{@link SelectOption#id}.
- */
- optionIds?: string[];
- }
-
- export type UndeterminedFilter = TextFilter | SelectFilter | Filter;
-
- export interface Row {
- id: string;
- documentId?: string;
- icon?: string;
- cover?: string;
- createdAt?: number;
- modifiedAt?: number;
- height?: number;
- visibility?: boolean;
- }
-
- export interface Cell {
- rowId: string;
- fieldId: string;
- fieldType: FieldType;
- data: unknown;
- }
-
- export interface TextCell extends Cell {
- fieldType: FieldType.RichText;
- data: string;
- }
-
- export interface NumberCell extends Cell {
- fieldType: FieldType.Number;
- data: string;
- }
-
- export interface CheckboxCell extends Cell {
- fieldType: FieldType.Checkbox;
- data: 'Yes' | 'No';
- }
-
- export interface UrlCell extends Cell {
- fieldType: FieldType.URL;
- data: UrlCellData;
- }
-
- export interface UrlCellData {
- url: string;
- content?: string;
- }
-
- export interface SelectCell extends Cell {
- fieldType: FieldType.SingleSelect | FieldType.MultiSelect;
- data: SelectCellData;
- }
-
- export interface SelectCellData {
- options?: SelectOption[];
- selectOptions?: SelectOption[];
- }
-
- export interface DateTimeCell extends Cell {
- fieldType: FieldType.DateTime;
- data: DateTimeCellData;
- }
-
- export interface DateTimeCellData {
- date?: string;
- time?: string;
- timestamp?: number;
- includeTime?: boolean;
- }
-
- export interface ChecklistCell extends Cell {
- fieldType: FieldType.Checklist;
- data: ChecklistCellData;
- }
-
- export interface ChecklistCellData {
- /**
- * link to [SelectOption's id property]{@link SelectOption#id}.
- */
- selectedOptions?: string[];
- percentage?: number;
- }
-
- export type UndeterminedCell = TextCell | NumberCell | DateTimeCell | SelectCell | CheckboxCell | UrlCell | ChecklistCell;
-}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/interfaces/document.ts b/frontend/appflowy_tauri/src/appflowy_app/interfaces/document.ts
index a7a122dc29..e66edd77af 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/interfaces/document.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/interfaces/document.ts
@@ -3,12 +3,6 @@ import { BlockActionTypePB } from '@/services/backend';
import { Sources } from 'quill';
import React from 'react';
-export interface DocumentBlockJSON {
- type: BlockType;
- data: BlockData<any>;
- children: DocumentBlockJSON[];
-}
-
export interface RangeStatic {
id: string;
length: number;
@@ -61,11 +55,9 @@ export interface QuoteBlockData extends TextBlockData {
export interface CalloutBlockData extends TextBlockData {
icon: string;
}
-
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type TextBlockData = Record<string, any>;
-export interface DividerBlockData {}
-
export enum Align {
Left = 'left',
Center = 'center',
@@ -88,8 +80,11 @@ export interface PageBlockData extends TextBlockData {
cover?: string;
coverType?: CoverType;
}
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
+type Data = any;
-export type BlockData<Type> = Type extends BlockType.HeadingBlock
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
+export type BlockData<Type = any> = Type extends BlockType.HeadingBlock
? HeadingBlockData
: Type extends BlockType.PageBlock
? PageBlockData
@@ -103,8 +98,6 @@ export type BlockData<Type> = Type extends BlockType.HeadingBlock
? NumberedListBlockData
: Type extends BlockType.ToggleListBlock
? ToggleListBlockData
- : Type extends BlockType.DividerBlock
- ? DividerBlockData
: Type extends BlockType.CalloutBlock
? CalloutBlockData
: Type extends BlockType.EquationBlock
@@ -113,12 +106,13 @@ export type BlockData<Type> = Type extends BlockType.HeadingBlock
? ImageBlockData
: Type extends BlockType.TextBlock
? TextBlockData
- : any;
+ : Data;
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
export interface NestedBlock<Type = any> {
id: string;
type: BlockType;
- data: BlockData<Type> | any;
+ data: BlockData<Type> | Data;
parent: string | null;
children: string;
externalId?: string;
@@ -152,7 +146,6 @@ export interface SlashCommandState {
export enum SlashCommandOptionKey {
TEXT,
- PAGE,
TODO,
BULLET,
NUMBER,
@@ -170,7 +163,7 @@ export enum SlashCommandOptionKey {
export interface SlashCommandOption {
type: BlockType;
- data?: BlockData<any>;
+ data?: BlockData;
key: SlashCommandOptionKey;
}
@@ -273,7 +266,7 @@ export interface BlockConfig {
/**
* The default data of the block
*/
- defaultData?: BlockData<any>;
+ defaultData?: BlockData;
/**
* The props that will be passed to the text split function
diff --git a/frontend/appflowy_tauri/src/appflowy_app/interfaces/index.ts b/frontend/appflowy_tauri/src/appflowy_app/interfaces/index.ts
index d10ea3cdff..7d1466630a 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/interfaces/index.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/interfaces/index.ts
@@ -1,7 +1,6 @@
import { ThemeModePB as ThemeMode } from '@/services/backend';
export { ThemeMode };
-export interface Document {}
export interface UserSetting {
theme?: Theme;
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/cell_bd_svc.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/cell_bd_svc.ts
index 99d3a64f06..30ec4e5812 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/cell_bd_svc.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/cell_bd_svc.ts
@@ -18,6 +18,7 @@ class CellBackendService {
row_id: cellId.rowId,
cell_changeset: data,
});
+
return DatabaseEventUpdateCell(payload);
};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/cell_cache.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/cell_cache.ts
index a19ad13d27..d81415660c 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/cell_cache.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/cell_cache.ts
@@ -14,6 +14,7 @@ export class CellCache {
remove = (key: CellCacheKey) => {
const cellDataByRowId = this.cellDataByFieldId.get(key.fieldId);
+
if (cellDataByRowId !== undefined) {
cellDataByRowId.delete(key.rowId);
}
@@ -25,8 +26,10 @@ export class CellCache {
insert = (key: CellCacheKey, value: any) => {
const cellDataByRowId = this.cellDataByFieldId.get(key.fieldId);
+
if (cellDataByRowId === undefined) {
const map = new Map();
+
map.set(key.rowId, value);
this.cellDataByFieldId.set(key.fieldId, map);
} else {
@@ -36,10 +39,12 @@ export class CellCache {
get<T>(key: CellCacheKey): Option<T> {
const cellDataByRowId = this.cellDataByFieldId.get(key.fieldId);
+
if (cellDataByRowId === undefined) {
return None;
} else {
const value = cellDataByRowId.get(key.rowId);
+
if (typeof value === typeof undefined) {
return None;
}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/cell_controller.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/cell_controller.ts
index d569c547ae..a753fb9ab1 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/cell_controller.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/cell_controller.ts
@@ -55,6 +55,7 @@ export class CellController<T, D> {
if (this.cellDataLoader.reloadOnFieldChanged) {
await this._loadCellData();
}
+
this.subscribeCallbacks?.onFieldChanged?.();
},
});
@@ -71,6 +72,7 @@ export class CellController<T, D> {
getTypeOption = async <P extends TypeOptionParser<PD>, PD>(parser: P) => {
const result = await this.fieldBackendService.getTypeOptionData(this.cellIdentifier.fieldType);
+
if (result.ok) {
return Ok(parser.fromBuffer(result.val.type_option_data));
} else {
@@ -80,6 +82,7 @@ export class CellController<T, D> {
saveCellData = async (data: D) => {
const result = await this.cellDataPersistence.save(data);
+
if (result.err) {
Log.error(result.val);
}
@@ -90,17 +93,21 @@ export class CellController<T, D> {
/// subscribers of the [onCellChanged] will get noticed
getCellData = async (): Promise<Option<T>> => {
const cellData = this.cellCache.get<T>(this.cacheKey);
+
if (cellData.none) {
await this._loadCellData();
return this.cellCache.get<T>(this.cacheKey);
}
+
return cellData;
};
private _loadCellData = async () => {
const result = await this.cellDataLoader.loadData();
+
if (result.ok) {
const cellData = result.val;
+
if (cellData.some) {
this.cellCache.insert(this.cacheKey, cellData.val);
this.cellDataNotifier.cellData = cellData;
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/cell_observer.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/cell_observer.ts
index dba0290d7a..0cd5ae35c2 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/cell_observer.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/cell_observer.ts
@@ -29,6 +29,7 @@ export class CellObserver {
} else {
this.notifier?.notify(result);
}
+
return;
default:
break;
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/data_parser.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/data_parser.ts
index 86b2198b4e..80afed8f9f 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/data_parser.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/data_parser.ts
@@ -1,4 +1,3 @@
-import utf8 from 'utf8';
import { CellBackendService, CellIdentifier } from './cell_bd_svc';
import { SelectOptionCellDataPB, URLCellDataPB, DateCellDataPB } from '@/services/backend';
import { Err, None, Ok, Option, Some } from 'ts-results';
@@ -19,6 +18,7 @@ class CellDataLoader<T> {
loadData = async () => {
const result = await this.service.getCell(this.cellId);
+
if (result.ok) {
return Ok(this.parser.parserData(result.val.data));
} else {
@@ -48,6 +48,7 @@ class SelectOptionCellDataParser extends CellDataParser<SelectOptionCellDataPB>
if (data.length === 0) {
return None;
}
+
return Some(SelectOptionCellDataPB.deserializeBinary(data));
}
}
@@ -57,6 +58,7 @@ class URLCellDataParser extends CellDataParser<URLCellDataPB> {
if (data.length === 0) {
return None;
}
+
return Some(URLCellDataPB.deserializeBinary(data));
}
}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/data_persistence.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/data_persistence.ts
index 9066b61150..ea8e9e2953 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/data_persistence.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/data_persistence.ts
@@ -25,10 +25,12 @@ export class DateCellDataPersistence extends CellDataPersistence<CalendarData> {
save(data: CalendarData): Promise<Result<void, FlowyError>> {
const payload = DateChangesetPB.fromObject({ cell_id: _makeCellId(this.cellIdentifier) });
+
payload.date = (data.date.getTime() / 1000) | 0;
if (data.time !== undefined) {
payload.time = data.time;
}
+
payload.include_time = data.includeTime;
return DatabaseEventUpdateDateCell(payload);
}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/select_option_bd_svc.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/select_option_bd_svc.ts
index 068ae60797..5e3e86fadc 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/select_option_bd_svc.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/cell/select_option_bd_svc.ts
@@ -40,6 +40,7 @@ export class SelectOptionCellBackendService {
});
const result = await DatabaseEventCreateSelectOption(payload);
+
if (result.ok) {
return await this._insertOption(result.val, params.isSelect || true);
} else {
@@ -47,7 +48,7 @@ export class SelectOptionCellBackendService {
}
};
- private _insertOption = (option: SelectOptionPB, isSelect: boolean) => {
+ private _insertOption = (option: SelectOptionPB, _: boolean) => {
const payload = RepeatedSelectOptionPayload.fromObject({
view_id: this.cellIdentifier.viewId,
field_id: this.cellIdentifier.fieldId,
@@ -73,6 +74,7 @@ export class SelectOptionCellBackendService {
field_id: this.cellIdentifier.fieldId,
row_id: this.cellIdentifier.rowId,
});
+
payload.items.push(...options);
return DatabaseEventDeleteSelectOption(payload);
};
@@ -83,12 +85,14 @@ export class SelectOptionCellBackendService {
selectOption = (optionIds: string[]) => {
const payload = SelectOptionCellChangesetPB.fromObject({ cell_identifier: this._cellIdentifier() });
+
payload.insert_option_ids.push(...optionIds);
return DatabaseEventUpdateSelectOptionCell(payload);
};
unselectOption = (optionIds: string[]) => {
const payload = SelectOptionCellChangesetPB.fromObject({ cell_identifier: this._cellIdentifier() });
+
payload.delete_option_ids.push(...optionIds);
return DatabaseEventUpdateSelectOptionCell(payload);
};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/database_bd_svc.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/database_bd_svc.ts
index 7a03c82beb..a38dc176c4 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/database_bd_svc.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/database_bd_svc.ts
@@ -19,7 +19,6 @@ import {
MoveGroupRowPayloadPB,
MoveRowPayloadPB,
RowIdPB,
- DatabaseEventUpdateDatabaseSetting,
DuplicateFieldPayloadPB,
DatabaseEventDuplicateField,
} from '@/services/backend/events/flowy-database2';
@@ -92,6 +91,7 @@ export class DatabaseBackendService {
moveRow = async (fromRowId: string, toRowId: string) => {
const payload = MoveRowPayloadPB.fromObject({ view_id: this.viewId, from_row_id: fromRowId, to_row_id: toRowId });
+
return DatabaseEventMoveRow(payload);
};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/database_controller.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/database_controller.ts
index f4e94f4790..39d1db308a 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/database_controller.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/database_controller.ts
@@ -76,7 +76,6 @@ export class DatabaseController {
// load database initial data
await this.fieldController.loadFields(database.fields);
- const loadGroupResult = await this.loadGroup();
this.databaseViewCache.initializeWithRows(database.rows);
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/field/field_bd_svc.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/field/field_bd_svc.ts
index 3580aece0b..10c9010678 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/field/field_bd_svc.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/field/field_bd_svc.ts
@@ -55,11 +55,13 @@ export class FieldBackendService {
deleteField = () => {
const payload = DeleteFieldPayloadPB.fromObject({ view_id: this.viewId, field_id: this.fieldId });
+
return DatabaseEventDeleteField(payload);
};
duplicateField = () => {
const payload = DuplicateFieldPayloadPB.fromObject({ view_id: this.viewId, field_id: this.fieldId });
+
return DatabaseEventDuplicateField(payload);
};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/field/field_controller.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/field/field_controller.ts
index 46902ddef4..2234c06dbd 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/field/field_controller.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/field/field_controller.ts
@@ -29,6 +29,7 @@ export class FieldController {
loadFields = async (fieldIds: FieldIdPB[]) => {
const result = await this.backendService.getFields(fieldIds);
+
if (result.ok) {
this.numOfFieldsNotifier.fieldInfos = result.val.map((field) => new FieldInfo(field));
} else {
@@ -47,6 +48,7 @@ export class FieldController {
onFieldsChanged: (result) => {
if (result.ok) {
const changeset = result.val;
+
this._deleteFields(changeset.deleted_fields);
this._insertFields(changeset.inserted_fields);
this._updateFields(changeset.updated_fields);
@@ -66,6 +68,7 @@ export class FieldController {
const predicate = (element: FieldInfo): boolean => {
return !deletedFieldIds.includes(element.field.id);
};
+
this.numOfFieldsNotifier.fieldInfos = [...this.fieldInfos].filter(predicate);
};
@@ -73,9 +76,12 @@ export class FieldController {
if (insertedFields.length === 0) {
return;
}
+
const newFieldInfos = [...this.fieldInfos];
+
insertedFields.forEach((insertedField) => {
const fieldInfo = new FieldInfo(insertedField.field);
+
if (newFieldInfos.length > insertedField.index) {
newFieldInfos.splice(insertedField.index, 0, fieldInfo);
} else {
@@ -91,10 +97,12 @@ export class FieldController {
}
const newFieldInfos = [...this.fieldInfos];
+
updatedFields.forEach((updatedField) => {
const index = newFieldInfos.findIndex((fieldInfo) => {
return fieldInfo.field.id === updatedField.id;
});
+
if (index !== -1) {
newFieldInfos.splice(index, 1, new FieldInfo(updatedField));
}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/field/field_observer.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/field/field_observer.ts
index d6a3e307b2..162c5c972a 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/field/field_observer.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/field/field_observer.ts
@@ -26,6 +26,7 @@ export class DatabaseFieldChangesetObserver {
} else {
this.notifier?.notify(result);
}
+
return;
default:
break;
@@ -64,6 +65,7 @@ export class DatabaseFieldObserver {
} else {
this._notifier?.notify(result);
}
+
break;
default:
break;
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/field/type_option/type_option_bd_svc.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/field/type_option/type_option_bd_svc.ts
index 31da01b9d8..240615a2e6 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/field/type_option/type_option_bd_svc.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/field/type_option/type_option_bd_svc.ts
@@ -10,6 +10,7 @@ export class TypeOptionBackendService {
createTypeOption = (fieldType: FieldType) => {
const payload = CreateFieldPayloadPB.fromObject({ view_id: this.viewId, field_type: fieldType });
+
return DatabaseEventCreateTypeOption(payload);
};
@@ -19,6 +20,7 @@ export class TypeOptionBackendService {
field_id: fieldId,
field_type: fieldType,
});
+
return DatabaseEventGetTypeOption(payload);
};
@@ -28,6 +30,7 @@ export class TypeOptionBackendService {
field_id: fieldId,
field_type: fieldType,
});
+
return DatabaseEventUpdateFieldType(payload);
};
}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/field/type_option/type_option_context.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/field/type_option/type_option_context.ts
index 7e1f55bc30..ce1b05251d 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/field/type_option/type_option_context.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/field/type_option/type_option_context.ts
@@ -22,6 +22,7 @@ abstract class TypeOptionSerde<T> {
// RichText
export function makeRichTextTypeOptionContext(controller: TypeOptionController): RichTextTypeOptionContext {
const parser = new RichTextTypeOptionSerde();
+
return new TypeOptionContext<string>(parser, controller);
}
@@ -40,6 +41,7 @@ class RichTextTypeOptionSerde extends TypeOptionSerde<string> {
// Number
export function makeNumberTypeOptionContext(controller: TypeOptionController): NumberTypeOptionContext {
const parser = new NumberTypeOptionSerde();
+
return new TypeOptionContext<NumberTypeOptionPB>(parser, controller);
}
@@ -58,6 +60,7 @@ class NumberTypeOptionSerde extends TypeOptionSerde<NumberTypeOptionPB> {
// Checkbox
export function makeCheckboxTypeOptionContext(controller: TypeOptionController): CheckboxTypeOptionContext {
const parser = new CheckboxTypeOptionSerde();
+
return new TypeOptionContext<CheckboxTypeOptionPB>(parser, controller);
}
@@ -76,6 +79,7 @@ class CheckboxTypeOptionSerde extends TypeOptionSerde<CheckboxTypeOptionPB> {
// URL
export function makeURLTypeOptionContext(controller: TypeOptionController): URLTypeOptionContext {
const parser = new URLTypeOptionSerde();
+
return new TypeOptionContext<URLTypeOptionPB>(parser, controller);
}
@@ -94,6 +98,7 @@ class URLTypeOptionSerde extends TypeOptionSerde<URLTypeOptionPB> {
// Date
export function makeDateTypeOptionContext(controller: TypeOptionController): DateTypeOptionContext {
const parser = new DateTypeOptionSerde();
+
return new TypeOptionContext<DateTypeOptionPB>(parser, controller);
}
@@ -112,6 +117,7 @@ class DateTypeOptionSerde extends TypeOptionSerde<DateTypeOptionPB> {
// SingleSelect
export function makeSingleSelectTypeOptionContext(controller: TypeOptionController): SingleSelectTypeOptionContext {
const parser = new SingleSelectTypeOptionSerde();
+
return new TypeOptionContext<SingleSelectTypeOptionPB>(parser, controller);
}
@@ -130,6 +136,7 @@ class SingleSelectTypeOptionSerde extends TypeOptionSerde<SingleSelectTypeOption
// Multi-select
export function makeMultiSelectTypeOptionContext(controller: TypeOptionController): MultiSelectTypeOptionContext {
const parser = new MultiSelectTypeOptionSerde();
+
return new TypeOptionContext<MultiSelectTypeOptionPB>(parser, controller);
}
@@ -148,6 +155,7 @@ class MultiSelectTypeOptionSerde extends TypeOptionSerde<MultiSelectTypeOptionPB
// Checklist
export function makeChecklistTypeOptionContext(controller: TypeOptionController): ChecklistTypeOptionContext {
const parser = new ChecklistTypeOptionSerde();
+
return new TypeOptionContext<ChecklistTypeOptionPB>(parser, controller);
}
@@ -184,8 +192,10 @@ export class TypeOptionContext<T> {
getTypeOption = async (): Promise<Result<T, FlowyError>> => {
const result = await this.controller.getTypeOption();
+
if (result.ok) {
const typeOption = this.parser.deserialize(result.val.type_option_data);
+
this.typeOption = Some(typeOption);
return Ok(typeOption);
} else {
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/field/type_option/type_option_controller.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/field/type_option/type_option_controller.ts
index a13196a236..a315140d94 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/field/type_option/type_option_controller.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/field/type_option/type_option_controller.ts
@@ -48,18 +48,23 @@ export class TypeOptionController {
throw Error('Unexpected empty type option data. Should call initialize first');
}
}
+
return new FieldInfo(this.typeOptionData.val.field);
};
switchToField = async (fieldType: FieldType) => {
const result = await this.typeOptionBackendSvc.updateTypeOptionType(this.fieldId, fieldType);
+
if (result.ok) {
const getResult = await this.typeOptionBackendSvc.getTypeOption(this.fieldId, fieldType);
+
if (getResult.ok) {
this.updateTypeOptionData(getResult.val);
}
+
return getResult;
}
+
return result;
};
@@ -114,6 +119,7 @@ export class TypeOptionController {
if (this.fieldBackendSvc === undefined) {
Log.error('Unexpected empty field backend service');
}
+
return this.fieldBackendSvc?.deleteField();
};
@@ -121,6 +127,7 @@ export class TypeOptionController {
if (this.fieldBackendSvc === undefined) {
Log.error('Unexpected empty field backend service');
}
+
return this.fieldBackendSvc?.duplicateField();
};
@@ -130,6 +137,7 @@ export class TypeOptionController {
if (result.ok) {
this.updateTypeOptionData(result.val);
}
+
return result;
});
};
@@ -139,6 +147,7 @@ export class TypeOptionController {
if (result.ok) {
this.updateTypeOptionData(result.val);
}
+
return result;
});
};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/group/group_controller.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/group/group_controller.ts
index 71e498bf9a..0a5c8de4af 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/group/group_controller.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/group/group_controller.ts
@@ -1,11 +1,4 @@
-import {
- DatabaseNotification,
- FlowyError,
- GroupPB,
- GroupRowsNotificationPB,
- RowMetaPB,
- RowPB,
-} from '@/services/backend';
+import { DatabaseNotification, FlowyError, GroupPB, GroupRowsNotificationPB, RowMetaPB } from '@/services/backend';
import { ChangeNotifier } from '$app/utils/change_notifier';
import { None, Ok, Option, Result, Some } from 'ts-results';
import { DatabaseNotificationObserver } from '../notifications/observer';
@@ -48,6 +41,7 @@ export class DatabaseGroupController {
if (this.group.rows.length < index) {
return None;
}
+
return Some(this.group.rows[index]);
};
@@ -56,6 +50,7 @@ export class DatabaseGroupController {
onRowsChanged: (result) => {
if (result.ok) {
const changeset = result.val;
+
// Delete
changeset.deleted_rows.forEach((deletedRowId) => {
this.group.rows = this.group.rows.filter((row) => row.id !== deletedRowId);
@@ -65,6 +60,7 @@ export class DatabaseGroupController {
// Insert
changeset.inserted_rows.forEach((insertedRow) => {
let index: number | undefined = insertedRow.index;
+
if (insertedRow.has_index && this.group.rows.length > insertedRow.index) {
this.group.rows.splice(index, 0, insertedRow.row_meta);
} else {
@@ -82,6 +78,7 @@ export class DatabaseGroupController {
// Update
changeset.updated_rows.forEach((updatedRow) => {
const index = this.group.rows.findIndex((row) => row.id === updatedRow.id);
+
if (index !== -1) {
this.group.rows[index] = updatedRow;
this.callbacks?.onUpdateRow(this.group.group_id, updatedRow);
@@ -134,6 +131,7 @@ class GroupDataObserver {
} else {
this.notifier?.notify(result);
}
+
return;
default:
break;
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/group/group_observer.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/group/group_observer.ts
index 46cfb10961..7967351145 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/group/group_observer.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/group/group_observer.ts
@@ -33,6 +33,7 @@ export class DatabaseGroupObserver {
} else {
this.groupByNotifier?.notify(result);
}
+
break;
case DatabaseNotification.DidUpdateNumOfGroups:
if (result.ok) {
@@ -40,6 +41,7 @@ export class DatabaseGroupObserver {
} else {
this.groupChangesetNotifier?.notify(result);
}
+
break;
default:
break;
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/notifications/observer.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/notifications/observer.ts
index 04a819d884..210258cde8 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/notifications/observer.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/notifications/observer.ts
@@ -11,6 +11,7 @@ export class DatabaseNotificationObserver extends AFNotificationObserver<Databas
callback: params.parserHandler,
id: params.id,
});
+
super(parser);
}
}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/notifications/parser.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/notifications/parser.ts
index 264a6036bd..caac06d1ba 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/notifications/parser.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/notifications/parser.ts
@@ -10,6 +10,7 @@ export class DatabaseNotificationParser extends NotificationParser<DatabaseNotif
params.callback,
(ty) => {
const notification = DatabaseNotification[ty];
+
if (isDatabaseNotification(notification)) {
return DatabaseNotification[notification];
} else {
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/row/row_cache.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/row/row_cache.ts
index 8cf7bc6230..a353fa6198 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/row/row_cache.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/row/row_cache.ts
@@ -1,9 +1,7 @@
import {
- RowPB,
InsertedRowPB,
UpdatedRowPB,
RowIdPB,
- OptionalRowPB,
RowsChangePB,
RowsVisibilityChangePB,
ReorderSingleRowPB,
@@ -13,7 +11,7 @@ import { ChangeNotifier } from '$app/utils/change_notifier';
import { FieldInfo } from '../field/field_controller';
import { CellCache, CellCacheKey } from '../cell/cell_cache';
import { CellIdentifier } from '../cell/cell_bd_svc';
-import { DatabaseEventGetRow, DatabaseEventGetRowMeta } from '@/services/backend/events/flowy-database2';
+import { DatabaseEventGetRowMeta } from '@/services/backend/events/flowy-database2';
import { None, Option, Some } from 'ts-results';
import { Log } from '$app/utils/log';
@@ -40,10 +38,12 @@ export class RowCache {
loadCells = async (rowId: string): Promise<CellByFieldId> => {
const opRow = this.rowList.getRow(rowId);
+
if (opRow.some) {
return this._toCellMap(opRow.val.row.id, this.getFieldInfos());
} else {
const rowResult = await this._loadRow(rowId);
+
if (rowResult.ok) {
this._refreshRow(rowResult.val);
return this._toCellMap(rowId, this.getFieldInfos());
@@ -101,6 +101,7 @@ export class RowCache {
applyReorderSingleRow = (reorderRow: ReorderSingleRowPB) => {
const rowInfo = this.rowList.getRow(reorderRow.row_id);
+
if (rowInfo !== undefined) {
this.rowList.move({ rowId: reorderRow.row_id, fromIndex: reorderRow.old_index, toIndex: reorderRow.new_index });
this.notifier.withChange(RowChangedReason.ReorderSingleRow, reorderRow.row_id);
@@ -109,24 +110,29 @@ export class RowCache {
private _refreshRow = (updatedRow: RowMetaPB) => {
const option = this.rowList.getRowWithIndex(updatedRow.id);
+
if (option.some) {
const { rowInfo, index } = option.val;
+
this.rowList.remove(rowInfo.row.id);
this.rowList.insert(index, rowInfo.copyWith({ row: updatedRow }));
} else {
const newRowInfo = new RowInfo(this.viewId, this.getFieldInfos(), updatedRow);
+
this.rowList.push(newRowInfo);
}
};
private _loadRow = (rowId: string) => {
const payload = RowIdPB.fromObject({ view_id: this.viewId, row_id: rowId });
+
return DatabaseEventGetRowMeta(payload);
};
private _deleteRows = (rowIds: string[]) => {
rowIds.forEach((rowId) => {
const deletedRow = this.rowList.remove(rowId);
+
if (deletedRow !== undefined) {
this.notifier.withChange(RowChangedReason.Delete, deletedRow.rowInfo.row.id);
}
@@ -137,6 +143,7 @@ export class RowCache {
rows.forEach((insertedRow) => {
const rowInfo = this._toRowInfo(insertedRow.row_meta);
const insertedIndex = this.rowList.insert(insertedRow.index, rowInfo);
+
if (insertedIndex !== undefined) {
this.notifier.withChange(RowChangedReason.Insert, insertedIndex.rowId);
}
@@ -149,9 +156,11 @@ export class RowCache {
}
const rowInfos: RowInfo[] = [];
+
updatedRows.forEach((updatedRow) => {
updatedRow.field_ids.forEach((fieldId) => {
const key = new CellCacheKey(fieldId, updatedRow.row_meta.id);
+
this.cellCache.remove(key);
});
@@ -159,6 +168,7 @@ export class RowCache {
});
const updatedIndexs = this.rowList.insertRows(rowInfos);
+
updatedIndexs.forEach((row) => {
this.notifier.withChange(RowChangedReason.Update, row.rowId);
});
@@ -167,6 +177,7 @@ export class RowCache {
private _hideRows = (rowIds: string[]) => {
rowIds.forEach((rowId) => {
const deletedRow = this.rowList.remove(rowId);
+
if (deletedRow !== undefined) {
this.notifier.withChange(RowChangedReason.Delete, deletedRow.rowInfo.row.id);
}
@@ -196,6 +207,7 @@ export class RowCache {
fieldInfos.forEach((fieldInfo) => {
const identifier = new CellIdentifier(this.viewId, rowId, fieldInfo.field.id, fieldInfo.field.field_type);
+
cellIdentifierByFieldId.set(fieldInfo.field.id, identifier);
});
@@ -213,6 +225,7 @@ class RowList {
getRow = (rowId: string): Option<RowInfo> => {
const rowInfo = this._rowInfoByRowId.get(rowId);
+
if (rowInfo === undefined) {
return None;
} else {
@@ -221,23 +234,29 @@ class RowList {
};
getRowWithIndex = (rowId: string): Option<{ rowInfo: RowInfo; index: number }> => {
const rowInfo = this._rowInfoByRowId.get(rowId);
+
if (rowInfo !== undefined) {
const index = this._rowInfos.indexOf(rowInfo, 0);
+
return Some({ rowInfo: rowInfo, index: index });
}
+
return None;
};
indexOfRow = (rowId: string): number => {
const rowInfo = this._rowInfoByRowId.get(rowId);
+
if (rowInfo !== undefined) {
return this._rowInfos.indexOf(rowInfo, 0);
}
+
return -1;
};
push = (rowInfo: RowInfo) => {
const index = this.indexOfRow(rowInfo.row.id);
+
if (index !== -1) {
this._rowInfos.splice(index, 1, rowInfo);
} else {
@@ -249,8 +268,10 @@ class RowList {
remove = (rowId: string): DeletedRow | undefined => {
const result = this.getRowWithIndex(rowId);
+
if (result.some) {
const { rowInfo, index } = result.val;
+
this._rowInfoByRowId.delete(rowInfo.row.id);
this._rowInfos.splice(index, 1);
return new DeletedRow(index, rowInfo);
@@ -263,13 +284,16 @@ class RowList {
const rowId = newRowInfo.row.id;
// Calibrate where to insert
let insertedIndex = insertIndex;
+
if (this._rowInfos.length <= insertedIndex) {
insertedIndex = this._rowInfos.length;
}
+
const result = this.getRowWithIndex(rowId);
if (result.some) {
const { index } = result.val;
+
// remove the old row info
this._rowInfos.splice(index, 1);
// insert the new row info to the insertedIndex
@@ -285,8 +309,10 @@ class RowList {
insertRows = (rowInfos: RowInfo[]) => {
const map = new Map<string, InsertedRow>();
+
rowInfos.forEach((rowInfo) => {
const index = this.indexOfRow(rowInfo.row.id);
+
if (index !== -1) {
this._rowInfos.splice(index, 1, rowInfo);
this._rowInfoByRowId.set(rowInfo.row.id, rowInfo);
@@ -299,8 +325,10 @@ class RowList {
move = (params: { rowId: string; fromIndex: number; toIndex: number }) => {
const currentIndex = this.indexOfRow(params.rowId);
+
if (currentIndex !== -1 && currentIndex !== params.toIndex) {
const rowInfo = this.remove(params.rowId)?.rowInfo;
+
if (rowInfo !== undefined) {
this.insert(params.toIndex, rowInfo);
}
@@ -312,6 +340,7 @@ class RowList {
this._rowInfos = [];
rowIds.forEach((rowId) => {
const rowInfo = this._rowInfoByRowId.get(rowId);
+
if (rowInfo !== undefined) {
this._rowInfos.push(rowInfo);
}
@@ -324,6 +353,7 @@ class RowList {
setFieldInfos = (fieldInfos: readonly FieldInfo[]) => {
const newRowInfos: RowInfo[] = [];
+
this._rowInfos.forEach((rowInfo) => {
newRowInfos.push(rowInfo.copyWith({ fieldInfos: fieldInfos }));
});
@@ -371,6 +401,7 @@ export class RowChangeNotifier extends ChangeNotifier<RowChanged> {
withChange = (reason: RowChangedReason, rowId?: string) => {
const newChange = new RowChanged(reason, rowId);
+
if (this._currentChanged !== newChange) {
this._currentChanged = newChange;
this.notify(this._currentChanged);
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/view/database_view_cache.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/view/database_view_cache.ts
index e099d3ba6b..072dae5189 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/view/database_view_cache.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/view/database_view_cache.ts
@@ -1,7 +1,7 @@
import { DatabaseViewRowsObserver } from './view_row_observer';
import { RowCache, RowInfo } from '../row/row_cache';
import { FieldController } from '../field/field_controller';
-import { RowMetaPB, RowPB } from '@/services/backend';
+import { RowMetaPB } from '@/services/backend';
export class DatabaseViewCache {
private readonly rowsObserver: DatabaseViewRowsObserver;
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/view/view_row_observer.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/view/view_row_observer.ts
index 7bc66f9115..2b7a67e4f1 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/view/view_row_observer.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/database/view/view_row_observer.ts
@@ -47,6 +47,7 @@ export class DatabaseViewRowsObserver {
} else {
this.rowsVisibilityNotifier.notify(result);
}
+
break;
case DatabaseNotification.DidUpdateViewRows:
if (result.ok) {
@@ -54,6 +55,7 @@ export class DatabaseViewRowsObserver {
} else {
this.rowsNotifier.notify(result);
}
+
break;
case DatabaseNotification.DidReorderRows:
if (result.ok) {
@@ -61,6 +63,7 @@ export class DatabaseViewRowsObserver {
} else {
this.reorderRowsNotifier.notify(result);
}
+
break;
case DatabaseNotification.DidReorderSingleRow:
if (result.ok) {
@@ -68,6 +71,7 @@ export class DatabaseViewRowsObserver {
} else {
this.reorderSingleRowNotifier.notify(result);
}
+
break;
default:
break;
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/document/notifications/observer.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/document/notifications/observer.ts
index ee149e5718..0d7a3d97d1 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/document/notifications/observer.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/document/notifications/observer.ts
@@ -11,6 +11,7 @@ export class DocumentNotificationObserver extends AFNotificationObserver<Documen
callback: params.parserHandler,
id: params.viewId,
});
+
super(parser);
}
}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/document/notifications/parser.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/document/notifications/parser.ts
index e29956803b..8609148153 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/document/notifications/parser.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/document/notifications/parser.ts
@@ -10,6 +10,7 @@ export class DocumentNotificationParser extends NotificationParser<DocumentNotif
params.callback,
(ty) => {
const notification = DocumentNotification[ty];
+
if (isDocumentNotification(notification)) {
return DocumentNotification[notification];
} else {
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/user/user_bd_svc.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/user/user_bd_svc.ts
index 38f5850f3f..7306fcfaea 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/user/user_bd_svc.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/user/user_bd_svc.ts
@@ -1,8 +1,6 @@
import { nanoid } from '@reduxjs/toolkit';
import {
AppearanceSettingsPB,
- AuthTypePB,
- ThemeModePB,
UserEventGetAppearanceSetting,
UserEventGetUserProfile,
UserEventGetUserSetting,
@@ -13,7 +11,6 @@ import {
UserEventUpdateUserProfile,
} from '@/services/backend/events/flowy-user';
import {
- BlockActionPB,
CreateWorkspacePayloadPB,
SignInPayloadPB,
SignUpPayloadPB,
@@ -72,6 +69,7 @@ export class UserBackendService {
openWorkspace = (workspaceId: string) => {
const payload = WorkspaceIdPB.fromObject({ value: workspaceId });
+
return FolderEventOpenWorkspace(payload);
};
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/workspace/page/page_controller.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/workspace/page/page_controller.ts
index 5bdea28e39..95d0a2a5b0 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/workspace/page/page_controller.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/workspace/page/page_controller.ts
@@ -11,8 +11,8 @@ export class PageController {
//
}
- dispose = () => {
- this.observer.unsubscribe();
+ dispose = async () => {
+ await this.observer.unsubscribe();
};
createPage = async (params: { name: string; layout: ViewLayoutPB }): Promise<string> => {
@@ -56,7 +56,6 @@ export class PageController {
getPage = async (id?: string): Promise<Page> => {
const result = await this.backendService.getPage(id || this.id);
-
if (result.ok) {
return parserViewPBToPage(result.val);
}
@@ -76,8 +75,10 @@ export class PageController {
const res = ViewPB.deserializeBinary(payload);
const page = parserViewPBToPage(ViewPB.deserializeBinary(payload));
const childPages = res.child_views.map(parserViewPBToPage);
+
callbacks.onPageChanged?.(page, childPages);
};
+
await this.observer.subscribeView(this.id, {
didUpdateView,
});
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/workspace/trash/controller.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/workspace/trash/controller.ts
index 5b84faa37c..86563a0ab7 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/workspace/trash/controller.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/workspace/trash/controller.ts
@@ -7,20 +7,20 @@ export class TrashController {
private readonly backendService: TrashBackendService = new TrashBackendService();
- subscribe = (callbacks: { onTrashChanged?: (trash: TrashPB[]) => void }) => {
+ subscribe = async (callbacks: { onTrashChanged?: (trash: TrashPB[]) => void }) => {
const didUpdateTrash = (payload: Uint8Array) => {
const res = RepeatedTrashPB.deserializeBinary(payload);
callbacks.onTrashChanged?.(res.items);
};
- this.observer.subscribeTrash({
+ await this.observer.subscribeTrash({
didUpdateTrash,
});
};
- dispose = () => {
- this.observer.unsubscribe();
+ dispose = async () => {
+ await this.observer.unsubscribe();
};
getTrash = async () => {
const res = await this.backendService.getTrash();
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/workspace/workspace_controller.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/workspace/workspace_controller.ts
index 9ff2856bfb..56b7003c42 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/workspace/workspace_controller.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/workspace/workspace_controller.ts
@@ -1,6 +1,6 @@
import { WorkspaceBackendService } from '$app/stores/effects/workspace/workspace_bd_svc';
import { WorkspaceObserver } from '$app/stores/effects/workspace/workspace_observer';
-import { CreateViewPayloadPB, RepeatedViewPB } from "@/services/backend";
+import { CreateViewPayloadPB, RepeatedViewPB } from '@/services/backend';
import { PageBackendService } from '$app/stores/effects/workspace/page/page_bd_svc';
import { Page, parserViewPBToPage } from '$app_reducers/pages/slice';
@@ -13,8 +13,8 @@ export class WorkspaceController {
this.backendService = new WorkspaceBackendService();
}
- dispose = () => {
- this.observer.unsubscribe();
+ dispose = async () => {
+ await this.observer.unsubscribe();
};
open = async () => {
@@ -37,16 +37,15 @@ export class WorkspaceController {
return Promise.reject(result.err);
};
- subscribe = async (callbacks: {
- onChildPagesChanged?: (childPages: Page[]) => void;
- }) => {
-
+ subscribe = async (callbacks: { onChildPagesChanged?: (childPages: Page[]) => void }) => {
const didUpdateWorkspace = (payload: Uint8Array) => {
const res = RepeatedViewPB.deserializeBinary(payload).items;
+
callbacks.onChildPagesChanged?.(res.map(parserViewPBToPage));
- }
+ };
+
await this.observer.subscribeWorkspace(this.workspaceId, {
- didUpdateWorkspace
+ didUpdateWorkspace,
});
};
@@ -71,6 +70,4 @@ export class WorkspaceController {
return [];
};
-
-
}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/workspace/workspace_manager_controller.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/workspace/workspace_manager_controller.ts
index d717a07495..67bfdd92ee 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/effects/workspace/workspace_manager_controller.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/effects/workspace/workspace_manager_controller.ts
@@ -1,5 +1,5 @@
import { WorkspaceBackendService } from './workspace_bd_svc';
-import { CreateWorkspacePayloadPB, RepeatedWorkspacePB } from '@/services/backend';
+import { CreateWorkspacePayloadPB } from '@/services/backend';
import { WorkspaceItem } from '$app_reducers/workspace/slice';
import { WorkspaceObserver } from '$app/stores/effects/workspace/workspace_observer';
@@ -51,6 +51,7 @@ export class WorkspaceManagerController {
if (result.ok) {
const workspace = result.val;
+
return {
id: workspace.id,
name: workspace.name,
@@ -64,8 +65,8 @@ export class WorkspaceManagerController {
await this.observer.unsubscribe();
};
- private didCreateWorkspace = (payload: Uint8Array) => {
- const data = RepeatedWorkspacePB.deserializeBinary(payload);
+ private didCreateWorkspace = () => {
+ // const data = RepeatedWorkspacePB.deserializeBinary(payload);
// onWorkspacesChanged(data.toObject().items);
};
}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/block-draggable/slice.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/block-draggable/slice.ts
index f5c9462095..123225a64d 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/block-draggable/slice.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/block-draggable/slice.ts
@@ -81,17 +81,21 @@ export const blockDraggableSlice = createSlice({
state.draggingPosition = draggingPosition;
state.dropContext = dropContext;
- const moveDistance = Math.sqrt(
- Math.pow(draggingPosition.x - state.startDraggingPosition!.x, 2) +
- Math.pow(draggingPosition.y - state.startDraggingPosition!.y, 2)
- );
+ const { startDraggingPosition } = state;
+
+ const moveDistance = startDraggingPosition
+ ? Math.sqrt(
+ Math.pow(draggingPosition.x - startDraggingPosition.x, 2) +
+ Math.pow(draggingPosition.y - startDraggingPosition.y, 2)
+ )
+ : 0;
state.dropId = dropId;
state.insertType = insertType;
state.dragShadowVisible = moveDistance > DRAG_DISTANCE_THRESHOLD;
},
- endDrag: (state) => {
+ endDrag: () => {
return initialState;
},
},
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/current-user/slice.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/current-user/slice.ts
index f7a245ad60..267c3e68f1 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/current-user/slice.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/current-user/slice.ts
@@ -1,5 +1,4 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
-import { nanoid } from 'nanoid';
import { WorkspaceSettingPB } from '@/services/backend/models/flowy-folder2/workspace';
import { UserSetting } from '$app/interfaces';
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/blocks/duplicate.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/blocks/duplicate.ts
index cb6334aaf7..7a95846059 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/blocks/duplicate.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/blocks/duplicate.ts
@@ -21,7 +21,7 @@ export const duplicateBelowNodeThunk = createAsyncThunk(
if (!duplicateActions) return;
await controller.applyActions(duplicateActions.actions);
- dispatch(
+ await dispatch(
setRectSelectionThunk({
docId,
selection: [duplicateActions.newNodeId],
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/blocks/insert.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/blocks/insert.ts
index 76cdca31ba..5f19743be3 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/blocks/insert.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/blocks/insert.ts
@@ -14,7 +14,7 @@ export const insertAfterNodeThunk = createAsyncThunk(
id: string;
controller: DocumentController;
type: BlockType;
- data?: BlockData<any>;
+ data?: BlockData;
defaultDelta?: Delta;
},
thunkAPI
@@ -22,8 +22,7 @@ export const insertAfterNodeThunk = createAsyncThunk(
const { controller, id, type, data, defaultDelta } = payload;
const { getState } = thunkAPI;
const state = getState() as RootState;
- const docId = controller.documentId;
- const documentState = state[DOCUMENT_NAME][docId];
+ const documentState = state[DOCUMENT_NAME][controller.documentId];
const node = documentState.nodes[id];
if (!node) return;
@@ -34,8 +33,9 @@ export const insertAfterNodeThunk = createAsyncThunk(
const actions = [];
let newNodeId;
const deltaOperator = new BlockDeltaOperator(documentState, controller);
+
if (type === BlockType.DividerBlock) {
- const newNode = newBlock<any>(type, parentId, data);
+ const newNode = newBlock(type, parentId, data);
actions.push(controller.getInsertAction(newNode, node.id));
newNodeId = newNode.id;
@@ -64,7 +64,7 @@ export const insertAfterNodeThunk = createAsyncThunk(
})
);
} else {
- const newNode = newBlock<any>(type, parentId, data);
+ const newNode = newBlock(type, parentId, data);
actions.push(controller.getInsertAction(newNode, node.id));
newNodeId = newNode.id;
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/blocks/update.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/blocks/update.ts
index 72f68e1edd..6e211cc728 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/blocks/update.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/blocks/update.ts
@@ -8,7 +8,7 @@ import { updatePageName } from '$app_reducers/pages/async_actions';
import { getDeltaText } from '$app/utils/document/delta';
import { BlockDeltaOperator } from '$app/utils/document/block_delta';
import { openMention, closeMention } from '$app_reducers/document/async-actions/mention';
-import {slashCommandActions} from "$app_reducers/document/slice";
+import { slashCommandActions } from '$app_reducers/document/slice';
const updateNodeDeltaAfterThunk = createAsyncThunk(
'document/updateNodeDeltaAfter',
@@ -27,9 +27,11 @@ const updateNodeDeltaAfterThunk = createAsyncThunk(
if (insertOps.length === 1) {
const char = insertOps[0].insert;
+
if (char === '@' && (oldText.endsWith(' ') || oldText === '')) {
- dispatch(openMention({ docId }));
+ await dispatch(openMention({ docId }));
}
+
if (char === '/') {
dispatch(
slashCommandActions.openSlashCommand({
@@ -42,15 +44,13 @@ const updateNodeDeltaAfterThunk = createAsyncThunk(
if (deleteOps.length === 1) {
if (deleteText === '@') {
- dispatch(closeMention({ docId }));
+ await dispatch(closeMention({ docId }));
}
+
if (deleteText === '/') {
- dispatch(
- slashCommandActions.closeSlashCommand(docId)
- );
+ dispatch(slashCommandActions.closeSlashCommand(docId));
}
}
-
}
);
@@ -92,7 +92,7 @@ export const updateNodeDataThunk = createAsyncThunk<
void,
{
id: string;
- data: Partial<BlockData<any>>;
+ data: Partial<BlockData>;
controller: DocumentController;
}
>('document/updateNodeDataExceptDelta', async (payload, thunkAPI) => {
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/copy_paste.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/copy_paste.ts
index 1c7b7d10bf..97392462ff 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/copy_paste.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/copy_paste.ts
@@ -9,7 +9,7 @@ export const copyThunk = createAsyncThunk<
controller: DocumentController;
setClipboardData: (data: BlockCopyData) => void;
}
->('document/copy', async (payload, thunkAPI) => {
+>('document/copy', async () => {
// TODO: Migrate to Rust implementation.
});
@@ -29,6 +29,6 @@ export const pasteThunk = createAsyncThunk<
data: BlockCopyData;
controller: DocumentController;
}
->('document/paste', async (payload, thunkAPI) => {
+>('document/paste', async () => {
// TODO: Migrate to Rust implementation.
});
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/keydown.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/keydown.ts
index 343001d88e..449438b559 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/keydown.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/keydown.ts
@@ -71,7 +71,7 @@ export const backspaceDeleteActionForBlockThunk = createAsyncThunk(
length: 0,
};
- dispatch(
+ await dispatch(
setCursorRangeThunk({
docId,
blockId: caret.id,
@@ -115,7 +115,6 @@ export const enterActionForBlockThunk = createAsyncThunk(
);
});
const isDocumentTitle = !node.parent;
- let newLineId;
const delta = deltaOperator.getDeltaWithBlockId(node.id);
@@ -126,7 +125,7 @@ export const enterActionForBlockThunk = createAsyncThunk(
return;
}
- newLineId = await deltaOperator.splitText(
+ const newLineId = await deltaOperator.splitText(
{
id: node.id,
index: caret.index,
@@ -138,7 +137,7 @@ export const enterActionForBlockThunk = createAsyncThunk(
);
if (!newLineId) return;
- dispatch(
+ await dispatch(
setCursorRangeThunk({
docId,
blockId: newLineId,
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/mention.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/mention.ts
index 4ec94ea731..f9379a1b78 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/mention.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/mention.ts
@@ -70,11 +70,15 @@ export const formatMention = createAsyncThunk(
const nodeDelta = deltaOperator.getDeltaWithBlockId(blockId);
if (!nodeDelta) return;
- const diffDelta = new Delta().retain(index).delete(charLength).insert('@',{ mention: { type, [type]: value } });
+ const diffDelta = new Delta()
+ .retain(index)
+ .delete(charLength)
+ .insert('@', { mention: { type, [type]: value } });
const applyTextDeltaAction = deltaOperator.getApplyDeltaAction(blockId, diffDelta);
+
if (!applyTextDeltaAction) return;
await controller.applyActions([applyTextDeltaAction]);
- dispatch(
+ await dispatch(
setCursorRangeThunk({
docId,
blockId,
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/menu.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/menu.ts
index 7c75ea6a77..1f1f50321c 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/menu.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/menu.ts
@@ -1,15 +1,10 @@
import { createAsyncThunk } from '@reduxjs/toolkit';
-import { BlockData, BlockType } from '$app/interfaces/document';
+import { BlockType } from '$app/interfaces/document';
import { insertAfterNodeThunk } from '$app_reducers/document/async-actions/blocks';
import { DocumentController } from '$app/stores/effects/document/document_controller';
import { rangeActions, slashCommandActions } from '$app_reducers/document/slice';
-import { turnToBlockThunk } from '$app_reducers/document/async-actions/turn_to';
-import { blockConfig } from '$app/constants/document/config';
-import Delta, { Op } from 'quill-delta';
-import { getDeltaText } from '$app/utils/document/delta';
+import Delta from 'quill-delta';
import { RootState } from '$app/stores/store';
-import { DOCUMENT_NAME, RANGE_NAME } from '$app/constants/document/name';
-import { blockEditActions } from '$app_reducers/document/block_edit_slice';
import { BlockDeltaOperator } from '$app/utils/document/block_delta';
/**
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/range.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/range.ts
index fb980d16cd..14b8e1e00d 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/range.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/range.ts
@@ -156,7 +156,7 @@ export const deleteRangeAndInsertThunk = createAsyncThunk(
);
if (!id) return;
- dispatch(
+ await dispatch(
setCursorRangeThunk({
docId,
blockId: id,
@@ -211,7 +211,7 @@ export const deleteRangeAndInsertEnterThunk = createAsyncThunk(
);
if (!newLineId) return;
- dispatch(
+ await dispatch(
setCursorRangeThunk({
docId,
blockId: newLineId,
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/temporary.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/temporary.ts
index fbc33dc739..7864c66387 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/temporary.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/temporary.ts
@@ -1,7 +1,6 @@
import { createAsyncThunk } from '@reduxjs/toolkit';
import { RootState } from '$app/stores/store';
import { DOCUMENT_NAME, EQUATION_PLACEHOLDER, RANGE_NAME, TEMPORARY_NAME } from '$app/constants/document/name';
-import { getDeltaByRange, getDeltaText } from '$app/utils/document/delta';
import Delta from 'quill-delta';
import { TemporaryState, TemporaryType } from '$app/interfaces/document';
import { temporaryActions } from '$app_reducers/document/temporary_slice';
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/turn_to.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/turn_to.ts
index 18d368727b..dd66cfd2ab 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/turn_to.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/document/async-actions/turn_to.ts
@@ -20,7 +20,7 @@ import { DOCUMENT_NAME, RANGE_NAME } from '$app/constants/document/name';
*/
export const turnToBlockThunk = createAsyncThunk(
'document/turnToBlock',
- async (payload: { id: string; controller: DocumentController; type: BlockType; data: BlockData<any> }, thunkAPI) => {
+ async (payload: { id: string; controller: DocumentController; type: BlockType; data: BlockData }, thunkAPI) => {
const { id, controller, type, data } = payload;
const docId = controller.documentId;
const { dispatch, getState } = thunkAPI;
@@ -46,13 +46,13 @@ export const turnToBlockThunk = createAsyncThunk(
if (type === BlockType.EquationBlock) {
data.formula = deltaOperator.getDeltaText(delta);
- const block = newBlock<any>(type, parent.id, data);
+ const block = newBlock(type, parent.id, data);
insertActions.push(controller.getInsertAction(block, node.id));
caretId = block.id;
caretIndex = 0;
} else if (type === BlockType.DividerBlock) {
- const block = newBlock<any>(type, parent.id, data);
+ const block = newBlock(type, parent.id, data);
insertActions.push(controller.getInsertAction(block, node.id));
const nodeId = generateId();
@@ -97,7 +97,7 @@ export const turnToBlockThunk = createAsyncThunk(
// submit actions
await controller.applyActions([...insertActions, ...moveChildrenActions, deleteAction]);
- dispatch(
+ await dispatch(
setCursorRangeThunk({
docId,
blockId: caretId,
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/pages/async_actions.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/pages/async_actions.ts
index 08aed71990..901a7a65eb 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/pages/async_actions.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/pages/async_actions.ts
@@ -58,35 +58,17 @@ export const movePageThunk = createAsyncThunk(
}
);
-export const updatePageName = createAsyncThunk(
- 'pages/updateName',
- async (
- payload: {
- id: string;
- name: string;
- },
- thunkAPI
- ) => {
- const controller = new PageController(payload.id);
+export const updatePageName = createAsyncThunk('pages/updateName', async (payload: { id: string; name: string }) => {
+ const controller = new PageController(payload.id);
- await controller.updatePage({
- id: payload.id,
- name: payload.name,
- });
- }
-);
+ await controller.updatePage({
+ id: payload.id,
+ name: payload.name,
+ });
+});
-export const updatePageIcon = createAsyncThunk(
- 'pages/updateIcon',
- async (
- payload: {
- id: string;
- icon?: PageIcon;
- },
- thunkAPI
- ) => {
- const controller = new PageController(payload.id);
+export const updatePageIcon = createAsyncThunk('pages/updateIcon', async (payload: { id: string; icon?: PageIcon }) => {
+ const controller = new PageController(payload.id);
- await controller.updatePageIcon(payload.icon);
- }
-);
+ await controller.updatePageIcon(payload.icon);
+});
diff --git a/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/pages/slice.ts b/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/pages/slice.ts
index 1aa0c4aa79..5d7d63e003 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/pages/slice.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/stores/reducers/pages/slice.ts
@@ -88,8 +88,10 @@ export const pagesSlice = createSlice({
expandPage(state, action: PayloadAction<string>) {
const id = action.payload;
+
state.expandedIdMap[id] = true;
const ids = Object.keys(state.expandedIdMap).filter(id => state.expandedIdMap[id]);
+
storeExpandedPageIds(ids);
},
@@ -98,6 +100,7 @@ export const pagesSlice = createSlice({
state.expandedIdMap[id] = false;
const ids = Object.keys(state.expandedIdMap).filter(id => state.expandedIdMap[id]);
+
storeExpandedPageIds(ids);
},
},
diff --git a/frontend/appflowy_tauri/src/appflowy_app/utils/async_queue.ts b/frontend/appflowy_tauri/src/appflowy_app/utils/async_queue.ts
index a058032fed..7e673506de 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/utils/async_queue.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/utils/async_queue.ts
@@ -21,6 +21,10 @@ export class AsyncQueue<T = unknown> {
const item = this.queue.shift();
+ if (!item) {
+ return;
+ }
+
this.isProcessing = true;
const executeFn = async (item: T) => {
@@ -34,7 +38,7 @@ export class AsyncQueue<T = unknown> {
}
};
- executeFn(item!);
+ void executeFn(item);
}
private async processItem(item: T): Promise<void> {
diff --git a/frontend/appflowy_tauri/src/appflowy_app/utils/change_notifier.ts b/frontend/appflowy_tauri/src/appflowy_app/utils/change_notifier.ts
index df81d11c47..57d9f2a370 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/utils/change_notifier.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/utils/change_notifier.ts
@@ -12,6 +12,7 @@ export class ChangeNotifier<T> {
if (this.isUnsubscribe) {
return null;
}
+
return this.subject.asObservable();
}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/utils/document/action.ts b/frontend/appflowy_tauri/src/appflowy_app/utils/document/action.ts
index 8921e2b4d8..3152246999 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/utils/document/action.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/utils/document/action.ts
@@ -1,29 +1,14 @@
-import {
- BlockType,
- ControllerAction,
- DocumentState,
- NestedBlock,
- RangeState,
- RangeStatic,
- SplitRelationship,
-} from '$app/interfaces/document';
-import { getNextLineId, getPrevLineId, newBlock } from '$app/utils/document/block';
-import Delta from 'quill-delta';
-import { RootState } from '$app/stores/store';
+import { ControllerAction, DocumentState, RangeState, RangeStatic } from '$app/interfaces/document';
+import { getNextLineId, newBlock } from '$app/utils/document/block';
import { DocumentController } from '$app/stores/effects/document/document_controller';
-import { blockConfig } from '$app/constants/document/config';
import {
caretInBottomEdgeByDelta,
caretInTopEdgeByDelta,
- getAfterExtentDeltaByRange,
- getBeofreExtentDeltaByRange,
- getDeltaText,
getIndexRelativeEnter,
getLastLineIndex,
transformIndexToNextLine,
transformIndexToPrevLine,
} from '$app/utils/document/delta';
-import { DOCUMENT_NAME, RANGE_NAME } from '$app/constants/document/name';
import { BlockDeltaOperator } from '$app/utils/document/block_delta';
export function getMiddleIds(document: DocumentState, startId: string, endId: string) {
@@ -80,7 +65,7 @@ export function getLeftCaretByRange(rangeState: RangeState) {
}
export function getRightCaretByRange(rangeState: RangeState) {
- const { anchor, focus, ranges, caret } = rangeState;
+ const { anchor, focus, ranges } = rangeState;
if (!anchor || !focus) return;
const isForward = anchor.point.y < focus.point.y;
@@ -180,7 +165,7 @@ export function getDuplicateActions(
if (!node) return;
// duplicate new node
- const newNode = newBlock<any>(node.type, parentId, {
+ const newNode = newBlock(node.type, parentId, {
...node.data,
});
diff --git a/frontend/appflowy_tauri/src/appflowy_app/utils/document/block_delta.ts b/frontend/appflowy_tauri/src/appflowy_app/utils/document/block_delta.ts
index cef85413d8..4b10d9c9f6 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/utils/document/block_delta.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/utils/document/block_delta.ts
@@ -1,4 +1,4 @@
-import { BlockData, BlockType, DocumentState, NestedBlock, SplitRelationship } from '$app/interfaces/document';
+import { BlockData, BlockType, DocumentState, SplitRelationship } from '$app/interfaces/document';
import { generateId, getNextLineId, getPrevLineId } from '$app/utils/document/block';
import { DocumentController } from '$app/stores/effects/document/document_controller';
import Delta, { Op } from 'quill-delta';
@@ -92,7 +92,7 @@ export class BlockDeltaOperator {
parentId: string;
type: BlockType;
prevId: string | null;
- data?: BlockData<any>;
+ data?: BlockData;
}) => {
const externalId = generateId();
const block = {
diff --git a/frontend/appflowy_tauri/src/appflowy_app/utils/document/format.ts b/frontend/appflowy_tauri/src/appflowy_app/utils/document/format.ts
index d156b6a066..66fe95caaf 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/utils/document/format.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/utils/document/format.ts
@@ -24,5 +24,6 @@ export function parseFormat(e: KeyboardEvent | React.KeyboardEvent<HTMLDivElemen
} else if (isHotkey(Keyboard.keys.FORMAT.CODE, e)) {
return TextAction.Code;
}
+
return null;
}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/utils/document/node.ts b/frontend/appflowy_tauri/src/appflowy_app/utils/document/node.ts
index d50cb04b2b..5d7dc8a565 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/utils/document/node.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/utils/document/node.ts
@@ -25,8 +25,8 @@ export function findFirstTextNode(node: Node): Node | null {
const children = node.childNodes;
- for (let i = 0; i < children.length; i++) {
- const textNode = findFirstTextNode(children[i]);
+ for (const child of children) {
+ const textNode = findFirstTextNode(child);
if (textNode) {
return textNode;
diff --git a/frontend/appflowy_tauri/src/appflowy_app/utils/document/quill_editor.ts b/frontend/appflowy_tauri/src/appflowy_app/utils/document/quill_editor.ts
index e29c0fd72d..7b9690b894 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/utils/document/quill_editor.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/utils/document/quill_editor.ts
@@ -46,6 +46,7 @@ export function adaptDeltaForQuill(inputOps: Op[], isOutput = false): Op[] {
if (isOutput) {
const newText = text.slice(0, -1);
+
if (newText !== '') {
newOps[lastOpIndex] = { ...lastOp, insert: newText };
} else {
diff --git a/frontend/appflowy_tauri/src/appflowy_app/utils/document/slate_editor.ts b/frontend/appflowy_tauri/src/appflowy_app/utils/document/slate_editor.ts
index 2f8cfac126..619dcf06f0 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/utils/document/slate_editor.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/utils/document/slate_editor.ts
@@ -107,6 +107,7 @@ export function convertToSlateValue(delta: Delta): Descendant[] {
export function convertToDelta(slateValue: Descendant[]) {
const ops = (slateValue[0] as Element).children.map((child) => {
const { text, ...attributes } = child as Text;
+
return {
insert: text,
attributes,
diff --git a/frontend/appflowy_tauri/src/appflowy_app/utils/document/toolbar.ts b/frontend/appflowy_tauri/src/appflowy_app/utils/document/toolbar.ts
index 93546f33b2..fa8318ac42 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/utils/document/toolbar.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/utils/document/toolbar.ts
@@ -1,6 +1,7 @@
export function calcToolbarPosition(toolbarDom: HTMLDivElement, node: Element, container: HTMLDivElement) {
const domSelection = window.getSelection();
let domRange;
+
if (domSelection?.rangeCount === 0) {
return;
} else {
@@ -18,6 +19,7 @@ export function calcToolbarPosition(toolbarDom: HTMLDivElement, node: Element, c
const rightBound = containerRect.right;
const rightThreshold = 20;
+
if (left < leftBound) {
left = leftBound;
} else if (left + nodeRect.left + toolbarDom.offsetWidth > rightBound) {
diff --git a/frontend/appflowy_tauri/src/appflowy_app/utils/draggable.ts b/frontend/appflowy_tauri/src/appflowy_app/utils/draggable.ts
index e0769899ca..090ab871d7 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/utils/draggable.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/utils/draggable.ts
@@ -1,8 +1,6 @@
import { BlockDraggableType, DragInsertType } from '$app_reducers/block-draggable/slice';
import { findParent } from '$app/utils/document/node';
import { nanoid } from 'nanoid';
-import { getBlock } from '$app/components/document/_shared/SubscribeNode.hooks';
-import { blockConfig } from '$app/constants/document/config';
export function getDraggableIdByPoint(target: HTMLElement | null) {
let node = target;
diff --git a/frontend/appflowy_tauri/src/appflowy_app/utils/region_grid.ts b/frontend/appflowy_tauri/src/appflowy_app/utils/region_grid.ts
index 3922c67329..75129c3bea 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/utils/region_grid.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/utils/region_grid.ts
@@ -46,7 +46,7 @@ export class RegionGrid {
this.grid.set(key, []);
}
- this.grid.get(key)!.push(block);
+ this.grid.get(key)?.push(block);
}
}
@@ -58,6 +58,7 @@ export class RegionGrid {
if (this.hasBlock(block.id)) {
this.removeBlock(block);
}
+
this.addBlock(block);
}
diff --git a/frontend/appflowy_tauri/src/appflowy_app/utils/tool.ts b/frontend/appflowy_tauri/src/appflowy_app/utils/tool.ts
index de291b980d..3f408738de 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/utils/tool.ts
+++ b/frontend/appflowy_tauri/src/appflowy_app/utils/tool.ts
@@ -1,3 +1,5 @@
+/* eslint-disable @typescript-eslint/no-explicit-any */
+
export function debounce(fn: (...args: any[]) => void, delay: number) {
let timeout: NodeJS.Timeout;
const debounceFn = (...args: any[]) => {
@@ -17,7 +19,7 @@ export function debounce(fn: (...args: any[]) => void, delay: number) {
export function throttle<T extends (...args: any[]) => void = (...args: any[]) => void>(
fn: T,
delay: number,
- immediate = true,
+ immediate = true
): T {
let timeout: NodeJS.Timeout | null = null;
@@ -156,7 +158,7 @@ export function chunkArray<T>(array: T[], chunkSize: number) {
export function interval<T extends (...args: any[]) => any = (...args: any[]) => any>(
fn: T,
delay?: number,
- options?: { immediate?: boolean },
+ options?: { immediate?: boolean }
): T & { cancel: () => void } {
const { immediate = true } = options || {};
let intervalId: NodeJS.Timer | null = null;
diff --git a/frontend/appflowy_tauri/src/appflowy_app/views/DatabasePage.tsx b/frontend/appflowy_tauri/src/appflowy_app/views/DatabasePage.tsx
index 61f86d22f0..cb0dbd5ba0 100644
--- a/frontend/appflowy_tauri/src/appflowy_app/views/DatabasePage.tsx
+++ b/frontend/appflowy_tauri/src/appflowy_app/views/DatabasePage.tsx
@@ -1,5 +1,25 @@
-import { Database } from '../components/database';
+import { useParams } from 'react-router-dom';
+import { ViewIdProvider } from '$app/hooks';
+import { Database, DatabaseTitle, VerticalScrollElementProvider } from '../components/database';
+import { useRef } from 'react';
export const DatabasePage = () => {
- return <Database />;
+ const viewId = useParams().id;
+
+ const ref = useRef<HTMLDivElement>(null);
+
+ if (!viewId) {
+ return null;
+ }
+
+ return (
+ <div className="h-full overflow-y-auto" ref={ref}>
+ <VerticalScrollElementProvider value={ref}>
+ <ViewIdProvider value={viewId}>
+ <DatabaseTitle />
+ <Database />
+ </ViewIdProvider>
+ </VerticalScrollElementProvider>
+ </div>
+ );
};