Move no-op to breadcrumb store
parent
016710af6a
commit
2baa78d26b
|
@ -87,19 +87,13 @@ export default class RoomBreadcrumbs2 extends React.PureComponent<IProps, IState
|
||||||
|
|
||||||
private viewRoom = (room: Room, index: number) => {
|
private viewRoom = (room: Room, index: number) => {
|
||||||
Analytics.trackEvent("Breadcrumbs", "click_node", index);
|
Analytics.trackEvent("Breadcrumbs", "click_node", index);
|
||||||
// If we're rendering the first breadcrumb and this is it no-op
|
defaultDispatcher.dispatch({action: "view_room", room_id: room.roomId});
|
||||||
if (!this.state.skipFirst && index === 0) {
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
defaultDispatcher.dispatch({action: "view_room", room_id: room.roomId});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public render(): React.ReactElement {
|
public render(): React.ReactElement {
|
||||||
const tiles = BreadcrumbsStore.instance.rooms.map((r, i) => {
|
const tiles = BreadcrumbsStore.instance.rooms.map((r, i) => {
|
||||||
const roomTags = RoomListStore.instance.getTagsForRoom(r);
|
const roomTags = RoomListStore.instance.getTagsForRoom(r);
|
||||||
const roomTag = roomTags.includes(DefaultTagID.DM) ? DefaultTagID.DM : roomTags[0];
|
const roomTag = roomTags.includes(DefaultTagID.DM) ? DefaultTagID.DM : roomTags[0];
|
||||||
const anon = () => this.viewRoom(r, i);
|
|
||||||
return (
|
return (
|
||||||
<AccessibleTooltipButton
|
<AccessibleTooltipButton
|
||||||
className="mx_RoomBreadcrumbs2_crumb"
|
className="mx_RoomBreadcrumbs2_crumb"
|
||||||
|
|
|
@ -125,6 +125,7 @@ export class BreadcrumbsStore extends AsyncStoreWithClient<IState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async appendRoom(room: Room) {
|
private async appendRoom(room: Room) {
|
||||||
|
let updated = false;
|
||||||
const rooms = (this.state.rooms || []).slice(); // cheap clone
|
const rooms = (this.state.rooms || []).slice(); // cheap clone
|
||||||
|
|
||||||
// If the room is upgraded, use that room instead. We'll also splice out
|
// If the room is upgraded, use that room instead. We'll also splice out
|
||||||
|
@ -136,30 +137,42 @@ export class BreadcrumbsStore extends AsyncStoreWithClient<IState> {
|
||||||
// Take out any room that isn't the most recent room
|
// Take out any room that isn't the most recent room
|
||||||
for (let i = 0; i < history.length - 1; i++) {
|
for (let i = 0; i < history.length - 1; i++) {
|
||||||
const idx = rooms.findIndex(r => r.roomId === history[i].roomId);
|
const idx = rooms.findIndex(r => r.roomId === history[i].roomId);
|
||||||
if (idx !== -1) rooms.splice(idx, 1);
|
if (idx !== -1) {
|
||||||
|
rooms.splice(idx, 1);
|
||||||
|
updated = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the existing room, if it is present
|
// Remove the existing room, if it is present
|
||||||
const existingIdx = rooms.findIndex(r => r.roomId === room.roomId);
|
const existingIdx = rooms.findIndex(r => r.roomId === room.roomId);
|
||||||
if (existingIdx !== -1) {
|
|
||||||
rooms.splice(existingIdx, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Splice the room to the start of the list
|
// If we're focusing on the first room no-op
|
||||||
rooms.splice(0, 0, room);
|
if (existingIdx !== 0) {
|
||||||
|
if (existingIdx !== -1) {
|
||||||
|
rooms.splice(existingIdx, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Splice the room to the start of the list
|
||||||
|
rooms.splice(0, 0, room);
|
||||||
|
updated = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (rooms.length > MAX_ROOMS) {
|
if (rooms.length > MAX_ROOMS) {
|
||||||
// This looks weird, but it's saying to start at the MAX_ROOMS point in the
|
// This looks weird, but it's saying to start at the MAX_ROOMS point in the
|
||||||
// list and delete everything after it.
|
// list and delete everything after it.
|
||||||
rooms.splice(MAX_ROOMS, rooms.length - MAX_ROOMS);
|
rooms.splice(MAX_ROOMS, rooms.length - MAX_ROOMS);
|
||||||
|
updated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the breadcrumbs
|
|
||||||
await this.updateState({rooms});
|
if (updated) {
|
||||||
const roomIds = rooms.map(r => r.roomId);
|
// Update the breadcrumbs
|
||||||
if (roomIds.length > 0) {
|
await this.updateState({rooms});
|
||||||
await SettingsStore.setValue("breadcrumb_rooms", null, SettingLevel.ACCOUNT, roomIds);
|
const roomIds = rooms.map(r => r.roomId);
|
||||||
|
if (roomIds.length > 0) {
|
||||||
|
await SettingsStore.setValue("breadcrumb_rooms", null, SettingLevel.ACCOUNT, roomIds);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue