From c8e42d61f510f224a7ba3ede37758057d712530f Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 27 Mar 2019 15:32:51 -0600 Subject: [PATCH 1/2] Persist breadcrumb state between sessions Fixes https://github.com/vector-im/riot-web/issues/8549 --- src/components/views/rooms/RoomBreadcrumbs.js | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/components/views/rooms/RoomBreadcrumbs.js b/src/components/views/rooms/RoomBreadcrumbs.js index d661d439bf..403c017edb 100644 --- a/src/components/views/rooms/RoomBreadcrumbs.js +++ b/src/components/views/rooms/RoomBreadcrumbs.js @@ -35,14 +35,32 @@ export default class RoomBreadcrumbs extends React.Component { componentWillMount() { this._dispatcherRef = dis.register(this.onAction); + + const roomStr = localStorage.getItem("mx_breadcrumb_rooms"); + if (roomStr) { + try { + const roomIds = JSON.parse(roomStr); + this.setState({ + rooms: roomIds.map((r) => { + return { + room: MatrixClientPeg.get().getRoom(r), + animated: false, + }; + }).filter((r) => r.room), + }); + } catch (e) { + console.error("Failed to parse breadcrumbs:", e); + } + } } componentWillUnmount() { dis.unregister(this._dispatcherRef); } - componentDidUpdate() { + componentDidUpdate(props, state) { const rooms = this.state.rooms.slice(); + if (rooms.length) { const {room, animated} = rooms[0]; if (!animated) { @@ -50,6 +68,9 @@ export default class RoomBreadcrumbs extends React.Component { setTimeout(() => this.setState({rooms}), 0); } } + + const roomStr = JSON.stringify(rooms.map((r) => r.room.roomId)); + localStorage.setItem("mx_breadcrumb_rooms", roomStr); } onAction(payload) { From f73556d27870f4f259e917d5f48c24e9e1b3070a Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 28 Mar 2019 09:52:12 -0600 Subject: [PATCH 2/2] Remove unnecessary params --- src/components/views/rooms/RoomBreadcrumbs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/rooms/RoomBreadcrumbs.js b/src/components/views/rooms/RoomBreadcrumbs.js index 403c017edb..27d0adbdfe 100644 --- a/src/components/views/rooms/RoomBreadcrumbs.js +++ b/src/components/views/rooms/RoomBreadcrumbs.js @@ -58,7 +58,7 @@ export default class RoomBreadcrumbs extends React.Component { dis.unregister(this._dispatcherRef); } - componentDidUpdate(props, state) { + componentDidUpdate() { const rooms = this.state.rooms.slice(); if (rooms.length) {