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

Commit

Permalink
Remember the last used server for room directory searches
Browse files Browse the repository at this point in the history
Signed-off-by: Šimon Brandner <[email protected]>
  • Loading branch information
SimonBrandner committed Jul 7, 2021
1 parent 1220ad3 commit b94dc2d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/components/structures/RoomDirectory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ import { ActionPayload } from "../../dispatcher/payloads";
const MAX_NAME_LENGTH = 80;
const MAX_TOPIC_LENGTH = 800;

const LAST_SERVER_KEY = "mx_last_room_directory_server";
const LAST_INSTANCE_KEY = "mx_last_room_directory_instance";

function track(action: string) {
Analytics.trackEvent('RoomDirectory', action);
}
Expand Down Expand Up @@ -150,8 +153,8 @@ export default class RoomDirectory extends React.Component<IProps, IState> {
publicRooms: [],
loading: true,
error: null,
instanceId: undefined,
roomServer: MatrixClientPeg.getHomeserverName(),
instanceId: localStorage.getItem(LAST_INSTANCE_KEY),
roomServer: localStorage.getItem(LAST_SERVER_KEY) || MatrixClientPeg.getHomeserverName(),
filterString: this.props.initialText || "",
selectedCommunityId,
communityName: null,
Expand Down Expand Up @@ -342,7 +345,7 @@ export default class RoomDirectory extends React.Component<IProps, IState> {
}
};

private onOptionChange = (server: string, instanceId?: string | symbol) => {
private onOptionChange = (server: string, instanceId?: string) => {
// clear next batch so we don't try to load more rooms
this.nextBatch = null;
this.setState({
Expand All @@ -360,6 +363,14 @@ export default class RoomDirectory extends React.Component<IProps, IState> {
// find the five gitter ones, at which point we do not want
// to render all those rooms when switching back to 'all networks'.
// Easiest to just blow away the state & re-fetch.

// We have to be careful here so that we don't set instanceId = "undefined"
localStorage.setItem(LAST_SERVER_KEY, server);
if (instanceId) {
localStorage.setItem(LAST_INSTANCE_KEY, instanceId);
} else {
localStorage.removeItem(LAST_INSTANCE_KEY);
}
};

private onFillRequest = (backwards: boolean) => {
Expand Down

0 comments on commit b94dc2d

Please sign in to comment.