diff --git a/webapp/src/pages/boardPage.tsx b/webapp/src/pages/boardPage.tsx index 808275271..4b03fd138 100644 --- a/webapp/src/pages/boardPage.tsx +++ b/webapp/src/pages/boardPage.tsx @@ -64,39 +64,36 @@ const BoardPage = (props: Props) => { } }, []) - useEffect(() => { - if (!match.params.boardId) { - // Load last viewed boardView - const boardId = localStorage.getItem('lastBoardId') || undefined - const viewId = localStorage.getItem('lastViewId') || undefined - if (boardId) { - const newPath = generatePath(match.path, {...match.params, boardId, viewId}) - history.replace(newPath) - } - } - }, []) - useEffect(() => { const boardId = match.params.boardId const viewId = match.params.viewId - Utils.log(`attachToBoard: ${boardId}`) - if (boardId && !viewId && boardViews.length > 0) { - const newPath = generatePath(match.path, {...match.params, boardId, viewId: boardViews[0].id}) - history.replace(newPath) + if (!boardId) { + // Load last viewed boardView + const lastBoardId = localStorage.getItem('lastBoardId') || undefined + const lastViewId = localStorage.getItem('lastViewId') || undefined + if (lastBoardId) { + let newPath = generatePath(match.path, {...match.params, boardId: lastBoardId}) + if (lastViewId) { + newPath = generatePath(match.path, {...match.params, boardId: lastBoardId, viewId: lastViewId}) + } + history.replace(newPath) + return + } + return } - const view = boardViews.find((v) => v.id === viewId) - if (!view && boardViews.length > 0) { + Utils.log(`attachToBoard: ${boardId}`) + if (!viewId && boardViews.length > 0) { const newPath = generatePath(match.path, {...match.params, boardId, viewId: boardViews[0].id}) history.replace(newPath) return } localStorage.setItem('lastBoardId', boardId || '') - localStorage.setItem('lastViewId', view?.id || '') + localStorage.setItem('lastViewId', viewId || '') dispatch(setCurrentBoard(boardId || '')) - dispatch(setCurrentView(view?.id || '')) + dispatch(setCurrentView(viewId || '')) }, [match.params.boardId, match.params.viewId, history, boardViews]) useEffect(() => {