mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-12-23 03:11:25 +00:00
Make confirmation popup more stylish
This commit is contained in:
parent
3cae1b5a23
commit
0413fd6c37
2 changed files with 84 additions and 6 deletions
|
@ -15,11 +15,26 @@ import { Theme } from "./theme";
|
||||||
import AnonymousGuard from "../common/anonymous-guard";
|
import AnonymousGuard from "../common/anonymous-guard";
|
||||||
import { destroyTippy, setupTippy } from "../../tippy";
|
import { destroyTippy, setupTippy } from "../../tippy";
|
||||||
import { adultConsentLocalStorageKey } from "../../config";
|
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 isoData: IsoDataOptionalSite = setIsoData(this.context);
|
||||||
private readonly mainContentRef: RefObject<HTMLElement>;
|
private readonly mainContentRef: RefObject<HTMLElement>;
|
||||||
private readonly rootRef = createRef<HTMLDivElement>();
|
private readonly rootRef = createRef<HTMLDivElement>();
|
||||||
|
|
||||||
|
state: AppState = {
|
||||||
|
showAdultConsentModal: false,
|
||||||
|
};
|
||||||
|
|
||||||
constructor(props: any, context: any) {
|
constructor(props: any, context: any) {
|
||||||
super(props, context);
|
super(props, context);
|
||||||
this.mainContentRef = createRef();
|
this.mainContentRef = createRef();
|
||||||
|
@ -32,11 +47,7 @@ export class App extends Component<any, any> {
|
||||||
siteRes?.site_view.site.content_warning &&
|
siteRes?.site_view.site.content_warning &&
|
||||||
!(siteRes?.my_user || localStorage.getItem(adultConsentLocalStorageKey))
|
!(siteRes?.my_user || localStorage.getItem(adultConsentLocalStorageKey))
|
||||||
) {
|
) {
|
||||||
if (confirm(siteRes.site_view.site.content_warning)) {
|
this.setState({ showAdultConsentModal: true });
|
||||||
localStorage.setItem(adultConsentLocalStorageKey, "true");
|
|
||||||
} else {
|
|
||||||
history.back();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setupTippy(this.rootRef);
|
setupTippy(this.rootRef);
|
||||||
|
@ -129,6 +140,14 @@ export class App extends Component<any, any> {
|
||||||
</div>
|
</div>
|
||||||
<Footer site={siteRes} />
|
<Footer site={siteRes} />
|
||||||
</div>
|
</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>
|
</Provider>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
59
src/shared/components/common/adult-consent-modal.tsx
Normal file
59
src/shared/components/common/adult-consent-modal.tsx
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue