Remove unused packages and fix invariant violation on AsyncStore onNotReady (#9404)

* Remove traces of browser-request & mocha

* Remove unused matrix-react-test-utils

* Fix dispatcher invariant violation

* Add null-guard

* Improve types

* Fix null-guard

* Fix issue with authed users going directly to /#/login
This commit is contained in:
Michael Telatynski
2022-10-13 09:22:32 +01:00
committed by GitHub
parent 28bd58e551
commit 1800cb8c71
8 changed files with 34 additions and 57 deletions
+13 -7
View File
@@ -337,14 +337,19 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
// the old creds, but rather go straight to the relevant page
const firstScreen = this.screenAfterLogin ? this.screenAfterLogin.screen : null;
if (firstScreen === 'login' ||
firstScreen === 'register' ||
firstScreen === 'forgot_password') {
this.showScreenAfterLogin();
return;
const restoreSuccess = await this.loadSession();
if (restoreSuccess) {
return true;
}
return this.loadSession();
if (firstScreen === 'login' ||
firstScreen === 'register' ||
firstScreen === 'forgot_password'
) {
this.showScreenAfterLogin();
}
return false;
});
}
@@ -470,7 +475,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
return { serverConfig: props };
}
private loadSession() {
private loadSession(): Promise<boolean> {
// the extra Promise.resolve() ensures that synchronous exceptions hit the same codepath as
// asynchronous ones.
return Promise.resolve().then(() => {
@@ -490,6 +495,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
dis.dispatch({ action: "view_welcome_page" });
}
}
return loadedSession;
});
// Note we don't catch errors from this: we catch everything within
// loadSession as there's logic there to ask the user if they want
@@ -38,7 +38,7 @@ interface IProps {
interface IState {
searchQuery: string;
langs: string[];
langs: Awaited<ReturnType<typeof languageHandler.getAllLanguagesFromJson>>;
}
export default class LanguageDropdown extends React.Component<IProps, IState> {
@@ -60,7 +60,7 @@ export default class LanguageDropdown extends React.Component<IProps, IState> {
});
this.setState({ langs });
}).catch(() => {
this.setState({ langs: ['en'] });
this.setState({ langs: [{ value: 'en', label: "English" }] });
});
if (!this.props.value) {
@@ -83,7 +83,7 @@ export default class LanguageDropdown extends React.Component<IProps, IState> {
return <Spinner />;
}
let displayedLanguages;
let displayedLanguages: Awaited<ReturnType<typeof languageHandler.getAllLanguagesFromJson>>;
if (this.state.searchQuery) {
displayedLanguages = this.state.langs.filter((lang) => {
return languageMatchesSearchQuery(this.state.searchQuery, lang);
+3 -2
View File
@@ -154,9 +154,10 @@ export default class PipView extends React.Component<IProps, IState> {
public componentWillUnmount() {
LegacyCallHandler.instance.removeListener(LegacyCallHandlerEvent.CallChangeRoom, this.updateCalls);
LegacyCallHandler.instance.removeListener(LegacyCallHandlerEvent.CallState, this.updateCalls);
MatrixClientPeg.get().removeListener(CallEvent.RemoteHoldUnhold, this.onCallRemoteHold);
const cli = MatrixClientPeg.get();
cli?.removeListener(CallEvent.RemoteHoldUnhold, this.onCallRemoteHold);
RoomViewStore.instance.removeListener(UPDATE_EVENT, this.onRoomViewStoreUpdate);
const room = MatrixClientPeg.get().getRoom(this.state.viewedRoomId);
const room = cli?.getRoom(this.state.viewedRoomId);
if (room) {
WidgetLayoutStore.instance.off(WidgetLayoutStore.emissionForRoom(room), this.updateCalls);
}
+14 -7
View File
@@ -385,9 +385,11 @@ export function setMissingEntryGenerator(f: (value: string) => void) {
counterpart.setMissingEntryGenerator(f);
}
type Language = {
fileName: string;
label: string;
type Languages = {
[lang: string]: {
fileName: string;
label: string;
};
};
export function setLanguage(preferredLangs: string | string[]) {
@@ -401,7 +403,7 @@ export function setLanguage(preferredLangs: string | string[]) {
}
let langToUse: string;
let availLangs: { [lang: string]: Language };
let availLangs: Languages;
return getLangsJson().then((result) => {
availLangs = result;
@@ -438,9 +440,14 @@ export function setLanguage(preferredLangs: string | string[]) {
});
}
export function getAllLanguagesFromJson() {
type Language = {
value: string;
label: string;
};
export function getAllLanguagesFromJson(): Promise<Language[]> {
return getLangsJson().then((langsObject) => {
const langs = [];
const langs: Language[] = [];
for (const langKey in langsObject) {
if (langsObject.hasOwnProperty(langKey)) {
langs.push({
@@ -536,7 +543,7 @@ export function pickBestLanguage(langs: string[]): string {
return langs[0];
}
async function getLangsJson(): Promise<{ [lang: string]: Language }> {
async function getLangsJson(): Promise<Languages> {
let url: string;
if (typeof(webpackLangJsonUrl) === 'string') { // in Jest this 'url' isn't a URL, so just fall through
url = webpackLangJsonUrl;
+1 -1
View File
@@ -90,7 +90,7 @@ export class CallStore extends AsyncStoreWithClient<{}> {
}
this.callListeners.clear();
this.calls.clear();
this.activeCalls = new Set();
this._activeCalls.clear();
this.matrixClient.off(ClientEvent.Room, this.onRoom);
this.matrixClient.off(RoomStateEvent.Events, this.onRoomState);