Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2837 from matrix-org/travis/breadcrumbs/persist
Browse files Browse the repository at this point in the history
Persist breadcrumb state between sessions
  • Loading branch information
turt2live authored Mar 28, 2019
2 parents 1ae429f + f73556d commit 92c9954
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/components/views/rooms/RoomBreadcrumbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ 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() {
Expand All @@ -42,13 +59,17 @@ export default class RoomBreadcrumbs extends React.Component {

componentDidUpdate() {
const rooms = this.state.rooms.slice();

if (rooms.length) {
const {room, animated} = rooms[0];
if (!animated) {
rooms[0] = {room, animated: true};
setTimeout(() => this.setState({rooms}), 0);
}
}

const roomStr = JSON.stringify(rooms.map((r) => r.room.roomId));
localStorage.setItem("mx_breadcrumb_rooms", roomStr);
}

onAction(payload) {
Expand Down

0 comments on commit 92c9954

Please sign in to comment.