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 1 commit
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
23 changes: 22 additions & 1 deletion src/components/views/rooms/RoomBreadcrumbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,42 @@ 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) {
turt2live marked this conversation as resolved.
Show resolved Hide resolved
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