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

Always show right panel after setting a card #7544

Merged
merged 3 commits into from
Jan 14, 2022
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
26 changes: 22 additions & 4 deletions src/stores/right-panel/RightPanelStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export default class RightPanelStore extends ReadyWatchingStore {
// This function behaves as following:
// Update state: if the same phase is send but with a state
// Set right panel and erase history: if a "different to the current" phase is send (with or without a state)
// If the right panel is set, this function also shows the right panel.
const redirect = this.getVerificationRedirect(card);
const targetPhase = redirect?.phase ?? card.phase;
const cardState = redirect?.state ?? (Object.keys(card.state ?? {}).length === 0 ? null : card.state);
Expand All @@ -153,18 +154,22 @@ export default class RightPanelStore extends ReadyWatchingStore {
hist[hist.length - 1].state = cardState;
this.emitAndUpdateSettings();
return;
}

if (targetPhase !== this.currentCard?.phase) {
} else if (targetPhase !== this.currentCard?.phase) {
// Set right panel and erase history.
this.show();
this.setRightPanelCache({ phase: targetPhase, state: cardState ?? {} }, rId);
} else {
this.show();
this.emitAndUpdateSettings();
}
}

public setCards(cards: IRightPanelCard[], allowClose = true, roomId: string = null) {
// This function sets the history of the right panel and shows the right panel if not already visible.
const rId = roomId ?? this.viewedRoomId;
const history = cards.map(c => ({ phase: c.phase, state: c.state ?? {} }));
this.byRoom[rId] = { history, isOpen: true };
this.show();
this.emitAndUpdateSettings();
}

Expand All @@ -173,6 +178,7 @@ export default class RightPanelStore extends ReadyWatchingStore {
allowClose = true,
roomId: string = null,
) {
// This function appends a card to the history and shows the right panel if now already visible.
const rId = roomId ?? this.viewedRoomId;
const redirect = this.getVerificationRedirect(card);
const targetPhase = redirect?.phase ?? card.phase;
Expand All @@ -194,7 +200,7 @@ export default class RightPanelStore extends ReadyWatchingStore {
isOpen: !allowClose,
};
}

this.show();
this.emitAndUpdateSettings();
}

Expand All @@ -215,6 +221,18 @@ export default class RightPanelStore extends ReadyWatchingStore {
this.emitAndUpdateSettings();
}

public show() {
if (!this.isOpenForRoom) {
this.togglePanel();
}
}

public hide() {
if (this.isOpenForRoom) {
this.togglePanel();
}
}

// Private
private loadCacheFromSettings() {
const room = this.mxClient?.getRoom(this.viewedRoomId);
Expand Down