Open last boardView if not specified

This commit is contained in:
Chen-I Lim 2021-03-03 13:01:40 -08:00
parent 43c04fd32d
commit b87502e0a5

View file

@ -33,8 +33,20 @@ class BoardPage extends React.Component<Props, State> {
constructor(props: Props) {
super(props)
const queryString = new URLSearchParams(window.location.search)
const boardId = queryString.get('id') || ''
const viewId = queryString.get('v') || ''
let boardId = queryString.get('id') || ''
let viewId = queryString.get('v') || ''
if (!boardId) {
// Load last viewed boardView
boardId = localStorage.getItem('lastBoardId') || ''
viewId = localStorage.getItem('lastViewId') || ''
if (boardId) {
Utils.replaceUrlQueryParam('id', boardId)
}
if (viewId) {
Utils.replaceUrlQueryParam('v', viewId)
}
}
this.state = {
boardId,
@ -166,6 +178,9 @@ class BoardPage extends React.Component<Props, State> {
private async attachToBoard(boardId?: string, viewId = '') {
Utils.log(`attachToBoard: ${boardId}`)
localStorage.setItem('lastBoardId', boardId || '')
localStorage.setItem('lastViewId', viewId)
if (boardId) {
this.sync(boardId, viewId)
} else {
@ -290,6 +305,8 @@ class BoardPage extends React.Component<Props, State> {
}
showView(viewId: string, boardId: string = this.state.boardId): void {
localStorage.setItem('lastViewId', viewId)
if (this.state.boardTree && this.state.boardId === boardId) {
const newBoardTree = this.state.boardTree.copyWithView(viewId)
this.setState({boardTree: newBoardTree, viewId})