Skip to content

Commit eee3211

Browse files
Ascarbekqinluhe
andauthored
feat: nested views
* chore: remove folder code merge page and folder into navitem component * chore: test fix * fix: nav item expand fix * fix: unfold page and active page * fix: nav item click area fix * chore: remove old components * chore: remove old code * chore: cell controller reorganize * chore: nav item optimizations * fix: add async queue to fix data problem * chore: change semantics of new folder button * chore: move row methods to database controller --------- Co-authored-by: qinluhe <[email protected]>
1 parent 9834ecc commit eee3211

38 files changed

+776
-961
lines changed

frontend/appflowy_tauri/src/appflowy_app/components/_shared/EditRow/EditRow.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,15 @@ export const EditRow = ({
201201
}}
202202
className={`relative flex h-[90%] w-[70%] flex-col gap-8 rounded-xl bg-white `}
203203
>
204-
<div onClick={() => onCloseClick()} className={'absolute top-1 right-1'}>
204+
<div onClick={() => onCloseClick()} className={'absolute right-1 top-1'}>
205205
<button className={'block h-8 w-8 rounded-lg text-shade-2 hover:bg-main-secondary'}>
206206
<CloseSvg></CloseSvg>
207207
</button>
208208
</div>
209209

210210
<div className={'flex h-full'}>
211211
<div className={'flex h-full flex-1 flex-col border-r border-shade-6 pb-4 pt-6'}>
212-
<div className={'pl-12 pb-4'}>
212+
<div className={'pb-4 pl-12'}>
213213
<button className={'flex items-center gap-2 p-4'}>
214214
<i className={'h-5 w-5'}>
215215
<ImageSvg></ImageSvg>
@@ -229,7 +229,9 @@ export const EditRow = ({
229229
}`}
230230
>
231231
{cells
232-
.filter((cell) => databaseStore.fields[cell.cellIdentifier.fieldId].visible)
232+
.filter((cell) => {
233+
return databaseStore.fields[cell.cellIdentifier.fieldId]?.visible;
234+
})
233235
.map((cell, cellIndex) => (
234236
<EditCellWrapper
235237
index={cellIndex}

frontend/appflowy_tauri/src/appflowy_app/components/_shared/database-hooks/useDatabase.ts

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useState } from 'react';
1+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
22
import { DatabaseController } from '$app/stores/effects/database/database_controller';
33
import { databaseActions, DatabaseFieldMap, IDatabaseColumn } from '$app/stores/reducers/database/slice';
44
import { useAppDispatch } from '$app/stores/store';
@@ -8,6 +8,7 @@ import { RowInfo } from '$app/stores/effects/database/row/row_cache';
88
import { ViewLayoutPB } from '@/services/backend';
99
import { DatabaseGroupController } from '$app/stores/effects/database/group/group_controller';
1010
import { OnDragEndResponder } from 'react-beautiful-dnd';
11+
import { AsyncQueue } from '$app/utils/async_queue';
1112

1213
export const useDatabase = (viewId: string, type?: ViewLayoutPB) => {
1314
const dispatch = useAppDispatch();
@@ -24,25 +25,30 @@ export const useDatabase = (viewId: string, type?: ViewLayoutPB) => {
2425
return () => void c.dispose();
2526
}, [viewId]);
2627

27-
const loadFields = async (fieldInfos: readonly FieldInfo[]) => {
28-
const fields: DatabaseFieldMap = {};
29-
const columns: IDatabaseColumn[] = [];
30-
31-
for (const fieldInfo of fieldInfos) {
32-
const fieldPB = fieldInfo.field;
33-
columns.push({
34-
fieldId: fieldPB.id,
35-
sort: 'none',
36-
visible: fieldPB.visibility,
37-
});
38-
39-
const field = await loadField(viewId, fieldInfo, dispatch);
40-
fields[field.fieldId] = field;
41-
}
28+
const loadFields = useCallback(
29+
async (fieldInfos: readonly FieldInfo[]) => {
30+
const fields: DatabaseFieldMap = {};
31+
const columns: IDatabaseColumn[] = [];
32+
for (const fieldInfo of fieldInfos) {
33+
const fieldPB = fieldInfo.field;
34+
columns.push({
35+
fieldId: fieldPB.id,
36+
sort: 'none',
37+
visible: fieldPB.visibility,
38+
});
39+
40+
const field = await loadField(viewId, fieldInfo, dispatch);
41+
fields[field.fieldId] = field;
42+
}
43+
dispatch(databaseActions.updateFields({ fields }));
44+
dispatch(databaseActions.updateColumns({ columns }));
45+
},
46+
[viewId, dispatch]
47+
);
4248

43-
dispatch(databaseActions.updateFields({ fields }));
44-
dispatch(databaseActions.updateColumns({ columns }));
45-
};
49+
const queue = useMemo(() => {
50+
return new AsyncQueue<readonly FieldInfo[]>(loadFields);
51+
}, [loadFields]);
4652

4753
useEffect(() => {
4854
void (async () => {
@@ -53,7 +59,7 @@ export const useDatabase = (viewId: string, type?: ViewLayoutPB) => {
5359
setRows([...rowInfos]);
5460
},
5561
onFieldsChanged: (fieldInfos) => {
56-
void loadFields(fieldInfos);
62+
queue.enqueue(fieldInfos);
5763
},
5864
});
5965

@@ -76,7 +82,7 @@ export const useDatabase = (viewId: string, type?: ViewLayoutPB) => {
7682
return () => {
7783
void controller?.dispose();
7884
};
79-
}, [controller]);
85+
}, [controller, queue]);
8086

8187
const onNewRowClick = async (index: number) => {
8288
if (!groups) return;
@@ -95,15 +101,15 @@ export const useDatabase = (viewId: string, type?: ViewLayoutPB) => {
95101

96102
if (source.droppableId === destination?.droppableId) {
97103
// move inside the block (group)
98-
await controller.exchangeRow(
104+
await controller.exchangeGroupRow(
99105
group.rows[source.index].id,
100106
destination.droppableId,
101107
group.rows[destination.index].id
102108
);
103109
} else {
104110
// move to different block (group)
105111
if (!destination?.droppableId) return;
106-
await controller.moveRow(group.rows[source.index].id, destination.droppableId);
112+
await controller.moveGroupRow(group.rows[source.index].id, destination.droppableId);
107113
}
108114
};
109115

frontend/appflowy_tauri/src/appflowy_app/components/board/BoardCard.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { Draggable } from 'react-beautiful-dnd';
77
import { MouseEventHandler, useState } from 'react';
88
import { PopupWindow } from '$app/components/_shared/PopupWindow';
99
import { TrashSvg } from '$app/components/_shared/svg/TrashSvg';
10-
import { RowBackendService } from '$app/stores/effects/database/row/row_bd_svc';
1110
import { useTranslation } from 'react-i18next';
1211
import { useAppSelector } from '$app/stores/store';
1312

@@ -52,8 +51,7 @@ export const BoardCard = ({
5251

5352
const onDeleteRowClick = async () => {
5453
setShowCardPopup(false);
55-
const svc = new RowBackendService(viewId);
56-
await svc.deleteRow(rowInfo.row.id);
54+
await controller.deleteRow(rowInfo.row.id);
5755
};
5856

5957
return (
@@ -73,7 +71,7 @@ export const BoardCard = ({
7371
<div className={'flex flex-col gap-3'}>
7472
{cells
7573
.filter(
76-
(cell) => cell.fieldId !== groupByFieldId && databaseStore.fields[cell.cellIdentifier.fieldId].visible
74+
(cell) => cell.fieldId !== groupByFieldId && databaseStore.fields[cell.cellIdentifier.fieldId]?.visible
7775
)
7876
.map((cell, cellIndex) => (
7977
<BoardCell

frontend/appflowy_tauri/src/appflowy_app/components/layout/HeaderPanel/Breadcrumbs.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ShowMenuSvg } from '../../_shared/svg/ShowMenuSvg';
22
import { useEffect, useState } from 'react';
3-
import { useAppSelector } from '../../../stores/store';
3+
import { useAppSelector } from '$app/stores/store';
44
import { useLocation } from 'react-router-dom';
55

66
export const Breadcrumbs = ({ menuHidden, onShowMenuClick }: { menuHidden: boolean; onShowMenuClick: () => void }) => {
@@ -9,7 +9,6 @@ export const Breadcrumbs = ({ menuHidden, onShowMenuClick }: { menuHidden: boole
99
const [activePageId, setActivePageId] = useState<string>('');
1010
const currentLocation = useLocation();
1111
const pagesStore = useAppSelector((state) => state.pages);
12-
const foldersStore = useAppSelector((state) => state.folders);
1312

1413
useEffect(() => {
1514
const { pathname } = currentLocation;
@@ -20,10 +19,10 @@ export const Breadcrumbs = ({ menuHidden, onShowMenuClick }: { menuHidden: boole
2019

2120
useEffect(() => {
2221
const page = pagesStore.find((p) => p.id === activePageId);
23-
const folder = foldersStore.find((f) => f.id === page?.folderId);
24-
setFolderName(folder?.title ?? '');
22+
// const folder = foldersStore.find((f) => f.id === page?.parentPageId);
23+
// setFolderName(folder?.title ?? '');
2524
setPageName(page?.title ?? '');
26-
}, [pagesStore, foldersStore, activePageId]);
25+
}, [pagesStore, activePageId]);
2726

2827
return (
2928
<div className={'flex items-center'}>

frontend/appflowy_tauri/src/appflowy_app/components/layout/NavigationPanel/FolderItem.hooks.ts

Lines changed: 0 additions & 204 deletions
This file was deleted.

0 commit comments

Comments
 (0)