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