mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: remove try catch for global error boundary
This commit is contained in:
parent
37a6b54e82
commit
68bfa0b9cd
@ -5,7 +5,7 @@ import { IPage, pagesActions } from '../../../stores/reducers/pages/slice';
|
|||||||
import { ViewLayoutPB } from '@/services/backend';
|
import { ViewLayoutPB } from '@/services/backend';
|
||||||
import { AppBackendService } from '../../../stores/effects/folder/app/app_bd_svc';
|
import { AppBackendService } from '../../../stores/effects/folder/app/app_bd_svc';
|
||||||
import { WorkspaceBackendService } from '../../../stores/effects/folder/workspace/workspace_bd_svc';
|
import { WorkspaceBackendService } from '../../../stores/effects/folder/workspace/workspace_bd_svc';
|
||||||
import { useError } from '../../error/Error.hooks';
|
|
||||||
import { AppObserver } from '../../../stores/effects/folder/app/app_observer';
|
import { AppObserver } from '../../../stores/effects/folder/app/app_observer';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { INITIAL_FOLDER_HEIGHT, PAGE_ITEM_HEIGHT } from '../../_shared/constants';
|
import { INITIAL_FOLDER_HEIGHT, PAGE_ITEM_HEIGHT } from '../../_shared/constants';
|
||||||
@ -32,9 +32,6 @@ export const useFolderEvents = (folder: IFolder, pages: IPage[]) => {
|
|||||||
const appBackendService = new AppBackendService(folder.id);
|
const appBackendService = new AppBackendService(folder.id);
|
||||||
const workspaceBackendService = new WorkspaceBackendService(workspace.id || '');
|
const workspaceBackendService = new WorkspaceBackendService(workspace.id || '');
|
||||||
|
|
||||||
// Error
|
|
||||||
const error = useError();
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
void appObserver.subscribe({
|
void appObserver.subscribe({
|
||||||
onAppChanged: (change) => {
|
onAppChanged: (change) => {
|
||||||
@ -85,12 +82,8 @@ export const useFolderEvents = (folder: IFolder, pages: IPage[]) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const changeFolderTitle = async (newTitle: string) => {
|
const changeFolderTitle = async (newTitle: string) => {
|
||||||
try {
|
await appBackendService.update({ name: newTitle });
|
||||||
await appBackendService.update({ name: newTitle });
|
appDispatch(foldersActions.renameFolder({ id: folder.id, newTitle }));
|
||||||
appDispatch(foldersActions.renameFolder({ id: folder.id, newTitle }));
|
|
||||||
} catch (e: any) {
|
|
||||||
error.showError(e?.message);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const closeRenamePopup = () => {
|
const closeRenamePopup = () => {
|
||||||
@ -99,24 +92,16 @@ export const useFolderEvents = (folder: IFolder, pages: IPage[]) => {
|
|||||||
|
|
||||||
const deleteFolder = async () => {
|
const deleteFolder = async () => {
|
||||||
closePopup();
|
closePopup();
|
||||||
try {
|
await appBackendService.delete();
|
||||||
await appBackendService.delete();
|
appDispatch(foldersActions.deleteFolder({ id: folder.id }));
|
||||||
appDispatch(foldersActions.deleteFolder({ id: folder.id }));
|
|
||||||
} catch (e: any) {
|
|
||||||
error.showError(e?.message);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const duplicateFolder = async () => {
|
const duplicateFolder = async () => {
|
||||||
closePopup();
|
closePopup();
|
||||||
try {
|
const newApp = await workspaceBackendService.createApp({
|
||||||
const newApp = await workspaceBackendService.createApp({
|
name: folder.title,
|
||||||
name: folder.title,
|
});
|
||||||
});
|
appDispatch(foldersActions.addFolder({ id: newApp.id, title: folder.title }));
|
||||||
appDispatch(foldersActions.addFolder({ id: newApp.id, title: folder.title }));
|
|
||||||
} catch (e: any) {
|
|
||||||
error.showError(e?.message);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const closePopup = () => {
|
const closePopup = () => {
|
||||||
@ -126,77 +111,65 @@ export const useFolderEvents = (folder: IFolder, pages: IPage[]) => {
|
|||||||
|
|
||||||
const onAddNewDocumentPage = async () => {
|
const onAddNewDocumentPage = async () => {
|
||||||
closePopup();
|
closePopup();
|
||||||
try {
|
const newView = await appBackendService.createView({
|
||||||
const newView = await appBackendService.createView({
|
name: 'New Document 1',
|
||||||
name: 'New Document 1',
|
layoutType: ViewLayoutPB.Document,
|
||||||
layoutType: ViewLayoutPB.Document,
|
});
|
||||||
});
|
|
||||||
|
|
||||||
appDispatch(
|
appDispatch(
|
||||||
pagesActions.addPage({
|
pagesActions.addPage({
|
||||||
folderId: folder.id,
|
folderId: folder.id,
|
||||||
pageType: ViewLayoutPB.Document,
|
pageType: ViewLayoutPB.Document,
|
||||||
title: newView.name,
|
title: newView.name,
|
||||||
id: newView.id,
|
id: newView.id,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
setShowPages(true);
|
setShowPages(true);
|
||||||
|
|
||||||
navigate(`/page/document/${newView.id}`);
|
navigate(`/page/document/${newView.id}`);
|
||||||
} catch (e: any) {
|
|
||||||
error.showError(e?.message);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const onAddNewBoardPage = async () => {
|
const onAddNewBoardPage = async () => {
|
||||||
closePopup();
|
closePopup();
|
||||||
try {
|
const newView = await appBackendService.createView({
|
||||||
const newView = await appBackendService.createView({
|
name: 'New Board 1',
|
||||||
name: 'New Board 1',
|
layoutType: ViewLayoutPB.Board,
|
||||||
layoutType: ViewLayoutPB.Board,
|
});
|
||||||
});
|
|
||||||
|
|
||||||
setShowPages(true);
|
setShowPages(true);
|
||||||
|
|
||||||
appDispatch(
|
appDispatch(
|
||||||
pagesActions.addPage({
|
pagesActions.addPage({
|
||||||
folderId: folder.id,
|
folderId: folder.id,
|
||||||
pageType: ViewLayoutPB.Board,
|
pageType: ViewLayoutPB.Board,
|
||||||
title: newView.name,
|
title: newView.name,
|
||||||
id: newView.id,
|
id: newView.id,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
navigate(`/page/board/${newView.id}`);
|
navigate(`/page/board/${newView.id}`);
|
||||||
} catch (e: any) {
|
|
||||||
error.showError(e?.message);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const onAddNewGridPage = async () => {
|
const onAddNewGridPage = async () => {
|
||||||
closePopup();
|
closePopup();
|
||||||
try {
|
const newView = await appBackendService.createView({
|
||||||
const newView = await appBackendService.createView({
|
name: 'New Grid 1',
|
||||||
name: 'New Grid 1',
|
layoutType: ViewLayoutPB.Grid,
|
||||||
layoutType: ViewLayoutPB.Grid,
|
});
|
||||||
});
|
|
||||||
|
|
||||||
setShowPages(true);
|
setShowPages(true);
|
||||||
|
|
||||||
appDispatch(
|
appDispatch(
|
||||||
pagesActions.addPage({
|
pagesActions.addPage({
|
||||||
folderId: folder.id,
|
folderId: folder.id,
|
||||||
pageType: ViewLayoutPB.Grid,
|
pageType: ViewLayoutPB.Grid,
|
||||||
title: newView.name,
|
title: newView.name,
|
||||||
id: newView.id,
|
id: newView.id,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
navigate(`/page/grid/${newView.id}`);
|
navigate(`/page/grid/${newView.id}`);
|
||||||
} catch (e: any) {
|
|
||||||
error.showError(e?.message);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -1,23 +1,17 @@
|
|||||||
import { useAppDispatch, useAppSelector } from '../../../stores/store';
|
import { useAppDispatch, useAppSelector } from '../../../stores/store';
|
||||||
import { foldersActions } from '../../../stores/reducers/folders/slice';
|
import { foldersActions } from '../../../stores/reducers/folders/slice';
|
||||||
import { WorkspaceBackendService } from '../../../stores/effects/folder/workspace/workspace_bd_svc';
|
import { WorkspaceBackendService } from '../../../stores/effects/folder/workspace/workspace_bd_svc';
|
||||||
import { useError } from '../../error/Error.hooks';
|
|
||||||
|
|
||||||
export const useNewFolder = () => {
|
export const useNewFolder = () => {
|
||||||
const appDispatch = useAppDispatch();
|
const appDispatch = useAppDispatch();
|
||||||
const workspace = useAppSelector((state) => state.workspace);
|
const workspace = useAppSelector((state) => state.workspace);
|
||||||
const workspaceBackendService = new WorkspaceBackendService(workspace.id || '');
|
const workspaceBackendService = new WorkspaceBackendService(workspace.id || '');
|
||||||
const error = useError();
|
|
||||||
|
|
||||||
const onNewFolder = async () => {
|
const onNewFolder = async () => {
|
||||||
try {
|
const newApp = await workspaceBackendService.createApp({
|
||||||
const newApp = await workspaceBackendService.createApp({
|
name: 'New Folder 1',
|
||||||
name: 'New Folder 1',
|
});
|
||||||
});
|
appDispatch(foldersActions.addFolder({ id: newApp.id, title: newApp.name }));
|
||||||
appDispatch(foldersActions.addFolder({ id: newApp.id, title: newApp.name }));
|
|
||||||
} catch (e: any) {
|
|
||||||
error.showError(e?.message);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -13,7 +13,6 @@ export const usePageEvents = (page: IPage) => {
|
|||||||
const [activePageId, setActivePageId] = useState<string>('');
|
const [activePageId, setActivePageId] = useState<string>('');
|
||||||
const currentLocation = useLocation();
|
const currentLocation = useLocation();
|
||||||
const viewBackendService: ViewBackendService = new ViewBackendService(page.id);
|
const viewBackendService: ViewBackendService = new ViewBackendService(page.id);
|
||||||
const error = useError();
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const { pathname } = currentLocation;
|
const { pathname } = currentLocation;
|
||||||
@ -32,33 +31,21 @@ export const usePageEvents = (page: IPage) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const changePageTitle = async (newTitle: string) => {
|
const changePageTitle = async (newTitle: string) => {
|
||||||
try {
|
await viewBackendService.update({ name: newTitle });
|
||||||
await viewBackendService.update({ name: newTitle });
|
appDispatch(pagesActions.renamePage({ id: page.id, newTitle }));
|
||||||
appDispatch(pagesActions.renamePage({ id: page.id, newTitle }));
|
|
||||||
} catch (e: any) {
|
|
||||||
error.showError(e?.message);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const deletePage = async () => {
|
const deletePage = async () => {
|
||||||
closePopup();
|
closePopup();
|
||||||
try {
|
await viewBackendService.delete();
|
||||||
await viewBackendService.delete();
|
appDispatch(pagesActions.deletePage({ id: page.id }));
|
||||||
appDispatch(pagesActions.deletePage({ id: page.id }));
|
|
||||||
} catch (e: any) {
|
|
||||||
error.showError(e?.message);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const duplicatePage = () => {
|
const duplicatePage = () => {
|
||||||
closePopup();
|
closePopup();
|
||||||
try {
|
appDispatch(
|
||||||
appDispatch(
|
pagesActions.addPage({ id: nanoid(8), pageType: page.pageType, title: page.title, folderId: page.folderId })
|
||||||
pagesActions.addPage({ id: nanoid(8), pageType: page.pageType, title: page.title, folderId: page.folderId })
|
);
|
||||||
);
|
|
||||||
} catch (e: any) {
|
|
||||||
error.showError(e?.message);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const closePopup = () => {
|
const closePopup = () => {
|
||||||
|
@ -3,13 +3,12 @@ import { useAppDispatch, useAppSelector } from '../../stores/store';
|
|||||||
import { pagesActions } from '../../stores/reducers/pages/slice';
|
import { pagesActions } from '../../stores/reducers/pages/slice';
|
||||||
import { workspaceActions } from '../../stores/reducers/workspace/slice';
|
import { workspaceActions } from '../../stores/reducers/workspace/slice';
|
||||||
import { UserBackendService } from '../../stores/effects/user/user_bd_svc';
|
import { UserBackendService } from '../../stores/effects/user/user_bd_svc';
|
||||||
import { useError } from '../error/Error.hooks';
|
|
||||||
|
|
||||||
export const useWorkspace = () => {
|
export const useWorkspace = () => {
|
||||||
const currentUser = useAppSelector((state) => state.currentUser);
|
const currentUser = useAppSelector((state) => state.currentUser);
|
||||||
|
|
||||||
const appDispatch = useAppDispatch();
|
const appDispatch = useAppDispatch();
|
||||||
const error = useError();
|
|
||||||
const userBackendService: UserBackendService = new UserBackendService(currentUser.id || 0);
|
const userBackendService: UserBackendService = new UserBackendService(currentUser.id || 0);
|
||||||
|
|
||||||
const loadWorkspaceItems = async () => {
|
const loadWorkspaceItems = async () => {
|
||||||
@ -31,15 +30,11 @@ export const useWorkspace = () => {
|
|||||||
}
|
}
|
||||||
} catch (e1) {
|
} catch (e1) {
|
||||||
// create workspace for first start
|
// create workspace for first start
|
||||||
try {
|
const workspace = await userBackendService.createWorkspace({ name: 'New Workspace', desc: '' });
|
||||||
const workspace = await userBackendService.createWorkspace({ name: 'New Workspace', desc: '' });
|
appDispatch(workspaceActions.updateWorkspace({ id: workspace.id, name: workspace.name }));
|
||||||
appDispatch(workspaceActions.updateWorkspace({ id: workspace.id, name: workspace.name }));
|
|
||||||
|
|
||||||
appDispatch(foldersActions.clearFolders());
|
appDispatch(foldersActions.clearFolders());
|
||||||
appDispatch(pagesActions.clearPages());
|
appDispatch(pagesActions.clearPages());
|
||||||
} catch (e2: any) {
|
|
||||||
error.showError(e2?.message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user