Merge pull request #2837 from matrix-org/travis/breadcrumbs/persist
Persist breadcrumb state between sessions
This commit is contained in:
commit
92c99546f6
1 changed files with 21 additions and 0 deletions
|
@ -34,6 +34,23 @@ export default class RoomBreadcrumbs extends React.Component {
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
this._dispatcherRef = dis.register(this.onAction);
|
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() {
|
componentWillUnmount() {
|
||||||
|
@ -42,6 +59,7 @@ export default class RoomBreadcrumbs extends React.Component {
|
||||||
|
|
||||||
componentDidUpdate() {
|
componentDidUpdate() {
|
||||||
const rooms = this.state.rooms.slice();
|
const rooms = this.state.rooms.slice();
|
||||||
|
|
||||||
if (rooms.length) {
|
if (rooms.length) {
|
||||||
const {room, animated} = rooms[0];
|
const {room, animated} = rooms[0];
|
||||||
if (!animated) {
|
if (!animated) {
|
||||||
|
@ -49,6 +67,9 @@ export default class RoomBreadcrumbs extends React.Component {
|
||||||
setTimeout(() => this.setState({rooms}), 0);
|
setTimeout(() => this.setState({rooms}), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const roomStr = JSON.stringify(rooms.map((r) => r.room.roomId));
|
||||||
|
localStorage.setItem("mx_breadcrumb_rooms", roomStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
onAction(payload) {
|
onAction(payload) {
|
||||||
|
|
Loading…
Reference in a new issue