Fix redirect problems on product switch (#972)
Co-authored-by: Hossein <hahmadia@users.noreply.github.com>
This commit is contained in:
parent
a8b0f68e1e
commit
f983a59973
1 changed files with 17 additions and 20 deletions
|
@ -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(() => {
|
||||
|
|
Loading…
Reference in a new issue