Make confirmation popup more stylish

This commit is contained in:
SleeplessOne1917 2024-04-13 18:55:56 -04:00
parent 3cae1b5a23
commit 0413fd6c37
2 changed files with 84 additions and 6 deletions

View file

@ -15,11 +15,26 @@ import { Theme } from "./theme";
import AnonymousGuard from "../common/anonymous-guard";
import { destroyTippy, setupTippy } from "../../tippy";
import { adultConsentLocalStorageKey } from "../../config";
import AdultConsentModal from "../common/adult-consent-modal";
export class App extends Component<any, any> {
interface AppState {
showAdultConsentModal: boolean;
}
function handleAdultConsent(i: App) {
localStorage.setItem(adultConsentLocalStorageKey, "true");
i.setState({ showAdultConsentModal: false });
}
export class App extends Component<any, AppState> {
private isoData: IsoDataOptionalSite = setIsoData(this.context);
private readonly mainContentRef: RefObject<HTMLElement>;
private readonly rootRef = createRef<HTMLDivElement>();
state: AppState = {
showAdultConsentModal: false,
};
constructor(props: any, context: any) {
super(props, context);
this.mainContentRef = createRef();
@ -32,11 +47,7 @@ export class App extends Component<any, any> {
siteRes?.site_view.site.content_warning &&
!(siteRes?.my_user || localStorage.getItem(adultConsentLocalStorageKey))
) {
if (confirm(siteRes.site_view.site.content_warning)) {
localStorage.setItem(adultConsentLocalStorageKey, "true");
} else {
history.back();
}
this.setState({ showAdultConsentModal: true });
}
setupTippy(this.rootRef);
@ -129,6 +140,14 @@ export class App extends Component<any, any> {
</div>
<Footer site={siteRes} />
</div>
{siteRes?.site_view.site.content_warning && (
<AdultConsentModal
contentWarning={siteRes.site_view.site.content_warning}
show={this.state.showAdultConsentModal}
onBack={history.back}
onContinue={linkEvent(this, handleAdultConsent)}
/>
)}
</Provider>
</>
);

View file

@ -0,0 +1,59 @@
import { Component, LinkedEvent, RefObject, createRef } from "inferno";
import { modalMixin } from "../mixins/modal-mixin";
interface AdultConsentModalProps {
contentWarning: string;
show: boolean;
onContinue: LinkedEvent<any, Event> | null;
onBack: () => void;
}
@modalMixin
export default class AdultConsentModal extends Component<
AdultConsentModalProps,
any
> {
readonly modalDivRef: RefObject<HTMLDivElement> = createRef();
readonly continueButtonRef: RefObject<HTMLButtonElement> = createRef();
render() {
const { contentWarning, onContinue, onBack } = this.props;
return (
<div
className="modal fade"
id="adultConsentModal"
tabIndex={-1}
aria-hidden
aria-label="Content warning"
data-bs-backdrop="static"
ref={this.modalDivRef}
>
<div className="modal-dialog modal-fullscreen-sm-down">
<div className="modal-content">
<div className="modal-body text-center align-middle text-body">
{contentWarning}
</div>
<footer className="modal-footer">
<button
type="button"
className="btn btn-success"
onClick={onContinue}
ref={this.continueButtonRef}
>
Continue
</button>
<button type="button" className="btn btn-danger" onClick={onBack}>
Go back
</button>
</footer>
</div>
</div>
</div>
);
}
handleShow() {
this.continueButtonRef.current?.focus();
}
}