mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-28 23:31:14 +00:00
Merge branch 'main' into fix_security_link
This commit is contained in:
commit
23e3bfcf02
4 changed files with 20 additions and 22 deletions
|
@ -1 +1 @@
|
||||||
Subproject commit 21b8e8d9d380bef6c39b6b06fc9563d3fedf2ab6
|
Subproject commit 6fe83fe9c0bfdf8bcee6e2528e4420fabd582b8b
|
|
@ -21,12 +21,15 @@ interface TotpModalProps {
|
||||||
interface TotpModalState {
|
interface TotpModalState {
|
||||||
totp: string;
|
totp: string;
|
||||||
qrCode?: string;
|
qrCode?: string;
|
||||||
|
pending: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TOTP_LENGTH = 6;
|
const TOTP_LENGTH = 6;
|
||||||
|
|
||||||
async function handleSubmit(i: TotpModal, totp: string) {
|
async function handleSubmit(i: TotpModal, totp: string) {
|
||||||
|
i.setState({ pending: true });
|
||||||
const successful = await i.props.onSubmit(totp);
|
const successful = await i.props.onSubmit(totp);
|
||||||
|
i.setState({ pending: false });
|
||||||
|
|
||||||
if (!successful) {
|
if (!successful) {
|
||||||
i.setState({ totp: "" });
|
i.setState({ totp: "" });
|
||||||
|
@ -74,6 +77,7 @@ export default class TotpModal extends Component<
|
||||||
modal: Modal;
|
modal: Modal;
|
||||||
state: TotpModalState = {
|
state: TotpModalState = {
|
||||||
totp: "",
|
totp: "",
|
||||||
|
pending: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(props: TotpModalProps, context: any) {
|
constructor(props: TotpModalProps, context: any) {
|
||||||
|
@ -131,7 +135,7 @@ export default class TotpModal extends Component<
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { type, secretUrl, onClose } = this.props;
|
const { type, secretUrl, onClose } = this.props;
|
||||||
const { totp } = this.state;
|
const { totp, pending } = this.state;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
@ -203,11 +207,20 @@ export default class TotpModal extends Component<
|
||||||
ref={this.inputRef}
|
ref={this.inputRef}
|
||||||
enterKeyHint="done"
|
enterKeyHint="done"
|
||||||
value={totp}
|
value={totp}
|
||||||
|
disabled={pending}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<footer className="modal-footer">
|
<footer className="modal-footer">
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
className="btn btn-success"
|
||||||
|
form="totp-form"
|
||||||
|
disabled={totp.length !== TOTP_LENGTH || pending}
|
||||||
|
>
|
||||||
|
{I18NextService.i18n.t("submit")}
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="btn btn-danger"
|
className="btn btn-danger"
|
||||||
|
|
|
@ -446,7 +446,7 @@ export class Search extends Component<any, SearchState> {
|
||||||
q: query,
|
q: query,
|
||||||
};
|
};
|
||||||
resolveObjectResponse =
|
resolveObjectResponse =
|
||||||
await HttpService.silent_client.resolveObject(resolveObjectForm);
|
await HttpService.client.resolveObject(resolveObjectForm);
|
||||||
|
|
||||||
// If we return this object with a state of failed, the catch-all-handler will redirect
|
// If we return this object with a state of failed, the catch-all-handler will redirect
|
||||||
// to an error page, so we ignore it by covering up the error with the empty state.
|
// to an error page, so we ignore it by covering up the error with the empty state.
|
||||||
|
@ -981,7 +981,7 @@ export class Search extends Component<any, SearchState> {
|
||||||
if (myAuth()) {
|
if (myAuth()) {
|
||||||
this.setState({ resolveObjectRes: LOADING_REQUEST });
|
this.setState({ resolveObjectRes: LOADING_REQUEST });
|
||||||
this.setState({
|
this.setState({
|
||||||
resolveObjectRes: await HttpService.silent_client.resolveObject({
|
resolveObjectRes: await HttpService.client.resolveObject({
|
||||||
q,
|
q,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
import { getHttpBase } from "@utils/env";
|
import { getHttpBase } from "@utils/env";
|
||||||
import { LemmyHttp } from "lemmy-js-client";
|
import { LemmyHttp } from "lemmy-js-client";
|
||||||
import { toast } from "../toast";
|
|
||||||
import { I18NextService } from "./I18NextService";
|
|
||||||
|
|
||||||
export const EMPTY_REQUEST = {
|
export const EMPTY_REQUEST = {
|
||||||
state: "empty",
|
state: "empty",
|
||||||
|
@ -49,7 +47,7 @@ export type WrappedLemmyHttp = WrappedLemmyHttpClient & {
|
||||||
class WrappedLemmyHttpClient {
|
class WrappedLemmyHttpClient {
|
||||||
rawClient: LemmyHttp;
|
rawClient: LemmyHttp;
|
||||||
|
|
||||||
constructor(client: LemmyHttp, silent = false) {
|
constructor(client: LemmyHttp) {
|
||||||
this.rawClient = client;
|
this.rawClient = client;
|
||||||
|
|
||||||
for (const key of Object.getOwnPropertyNames(
|
for (const key of Object.getOwnPropertyNames(
|
||||||
|
@ -65,10 +63,6 @@ class WrappedLemmyHttpClient {
|
||||||
state: !(res === undefined || res === null) ? "success" : "empty",
|
state: !(res === undefined || res === null) ? "success" : "empty",
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (!silent) {
|
|
||||||
console.error(`API error: ${error}`);
|
|
||||||
toast(I18NextService.i18n.t(error), "danger");
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
state: "failed",
|
state: "failed",
|
||||||
err: error,
|
err: error,
|
||||||
|
@ -80,23 +74,18 @@ class WrappedLemmyHttpClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function wrapClient(client: LemmyHttp, silent = false) {
|
export function wrapClient(client: LemmyHttp) {
|
||||||
// unfortunately, this verbose cast is necessary
|
// unfortunately, this verbose cast is necessary
|
||||||
return new WrappedLemmyHttpClient(
|
return new WrappedLemmyHttpClient(client) as unknown as WrappedLemmyHttp;
|
||||||
client,
|
|
||||||
silent,
|
|
||||||
) as unknown as WrappedLemmyHttp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class HttpService {
|
export class HttpService {
|
||||||
static #_instance: HttpService;
|
static #_instance: HttpService;
|
||||||
#silent_client: WrappedLemmyHttp;
|
|
||||||
#client: WrappedLemmyHttp;
|
#client: WrappedLemmyHttp;
|
||||||
|
|
||||||
private constructor() {
|
private constructor() {
|
||||||
const lemmyHttp = new LemmyHttp(getHttpBase());
|
const lemmyHttp = new LemmyHttp(getHttpBase());
|
||||||
this.#client = wrapClient(lemmyHttp);
|
this.#client = wrapClient(lemmyHttp);
|
||||||
this.#silent_client = wrapClient(lemmyHttp, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static get #Instance() {
|
static get #Instance() {
|
||||||
|
@ -106,8 +95,4 @@ export class HttpService {
|
||||||
public static get client() {
|
public static get client() {
|
||||||
return this.#Instance.#client;
|
return this.#Instance.#client;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static get silent_client() {
|
|
||||||
return this.#Instance.#silent_client;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue