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

Persist breadcrumb state between sessions #2837

Merged
merged 2 commits into from
Mar 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/components/views/rooms/RoomBreadcrumbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,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 @@ -43,13 +60,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