mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-25 22:01:13 +00:00
Add go-back redirect countdown
This commit is contained in:
parent
b6d7efd8ae
commit
42bc4ab7d3
2 changed files with 45 additions and 12 deletions
|
@ -11,6 +11,7 @@ interface AdultConsentModalProps {
|
||||||
show: boolean;
|
show: boolean;
|
||||||
onContinue: LinkedEvent<any, Event> | null;
|
onContinue: LinkedEvent<any, Event> | null;
|
||||||
onBack: LinkedEvent<any, Event> | null;
|
onBack: LinkedEvent<any, Event> | null;
|
||||||
|
redirectCountdown: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
@modalMixin
|
@modalMixin
|
||||||
|
@ -19,7 +20,8 @@ class AdultConsentModalInner extends Component<AdultConsentModalProps, any> {
|
||||||
readonly continueButtonRef = createRef<HTMLButtonElement>();
|
readonly continueButtonRef = createRef<HTMLButtonElement>();
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { contentWarning, onContinue, onBack } = this.props;
|
const { contentWarning, onContinue, onBack, redirectCountdown } =
|
||||||
|
this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
@ -36,15 +38,21 @@ class AdultConsentModalInner extends Component<AdultConsentModalProps, any> {
|
||||||
data-bs-backdrop="static"
|
data-bs-backdrop="static"
|
||||||
>
|
>
|
||||||
<div className="modal-content">
|
<div className="modal-content">
|
||||||
<header className="modal-header">
|
<header className="modal-header text-center">
|
||||||
<h3 className="modal-title">Content Warning</h3>
|
<h3 className="modal-title">Content Warning</h3>
|
||||||
</header>
|
</header>
|
||||||
<div
|
{redirectCountdown === Infinity ? (
|
||||||
className="modal-body text-center align-middle text-body"
|
<div
|
||||||
dangerouslySetInnerHTML={mdToHtml(contentWarning, () =>
|
className="modal-body text-center align-middle text-body"
|
||||||
this.forceUpdate(),
|
dangerouslySetInnerHTML={mdToHtml(contentWarning, () =>
|
||||||
)}
|
this.forceUpdate(),
|
||||||
/>
|
)}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<div className="modal-body text-center align-middle text-body">
|
||||||
|
Alright 👍. Sending you back in {redirectCountdown}.
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<footer className="modal-footer">
|
<footer className="modal-footer">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
@ -71,15 +79,24 @@ class AdultConsentModalInner extends Component<AdultConsentModalProps, any> {
|
||||||
|
|
||||||
interface AdultConsentModalState {
|
interface AdultConsentModalState {
|
||||||
show: boolean;
|
show: boolean;
|
||||||
|
redirectCountdown: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleAdultConsent(i: AdultConsentModal) {
|
function handleAdultConsent(i: AdultConsentModal) {
|
||||||
localStorage.setItem(adultConsentLocalStorageKey, "true");
|
localStorage.setItem(adultConsentLocalStorageKey, "true");
|
||||||
i.setState({ show: false });
|
i.setState({ show: false });
|
||||||
|
location.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleAdultConsentGoBack(i: AdultConsentModal) {
|
function handleAdultConsentGoBack(i: AdultConsentModal) {
|
||||||
i.context.router.history.back();
|
i.setState({ redirectCountdown: 5 });
|
||||||
|
|
||||||
|
i.redirectTimeout = setInterval(() => {
|
||||||
|
i.setState(prev => ({
|
||||||
|
...prev,
|
||||||
|
redirectCountdown: prev.redirectCountdown - 1,
|
||||||
|
}));
|
||||||
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class AdultConsentModal extends Component<
|
export default class AdultConsentModal extends Component<
|
||||||
|
@ -87,11 +104,13 @@ export default class AdultConsentModal extends Component<
|
||||||
AdultConsentModalState
|
AdultConsentModalState
|
||||||
> {
|
> {
|
||||||
private isoData: IsoDataOptionalSite = setIsoData(this.context);
|
private isoData: IsoDataOptionalSite = setIsoData(this.context);
|
||||||
|
redirectTimeout: NodeJS.Timeout;
|
||||||
state: AdultConsentModalState = {
|
state: AdultConsentModalState = {
|
||||||
show: false,
|
show: false,
|
||||||
|
redirectCountdown: Infinity,
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount(): void {
|
componentDidMount() {
|
||||||
const siteRes = this.isoData.site_res;
|
const siteRes = this.isoData.site_res;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
@ -105,11 +124,24 @@ export default class AdultConsentModal extends Component<
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidUpdate() {
|
||||||
|
if (this.state.redirectCountdown === 0) {
|
||||||
|
this.context.router.history.back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
clearInterval(this.redirectTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const { redirectCountdown, show } = this.state;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AdultConsentModalInner
|
<AdultConsentModalInner
|
||||||
contentWarning={this.props.contentWarning}
|
contentWarning={this.props.contentWarning}
|
||||||
show={this.state.show}
|
show={show}
|
||||||
|
redirectCountdown={redirectCountdown}
|
||||||
onBack={linkEvent(this, handleAdultConsentGoBack)}
|
onBack={linkEvent(this, handleAdultConsentGoBack)}
|
||||||
onContinue={linkEvent(this, handleAdultConsent)}
|
onContinue={linkEvent(this, handleAdultConsent)}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import { SiteResponse } from "lemmy-js-client";
|
import { SiteResponse } from "lemmy-js-client";
|
||||||
import { adultConsentLocalStorageKey } from "../../config";
|
import { adultConsentLocalStorageKey } from "../../config";
|
||||||
import { UserService } from "../../services";
|
import { UserService } from "../../services";
|
||||||
|
import { isBrowser } from "@utils/browser";
|
||||||
|
|
||||||
export default function shouldBlurNsfw(siteRes?: SiteResponse) {
|
export default function shouldBlurNsfw(siteRes?: SiteResponse) {
|
||||||
return siteRes?.site_view.site.content_warning
|
return siteRes?.site_view.site.content_warning
|
||||||
? !(
|
? !(
|
||||||
localStorage.getItem(adultConsentLocalStorageKey) ||
|
(isBrowser() && localStorage.getItem(adultConsentLocalStorageKey)) ||
|
||||||
UserService.Instance.myUserInfo
|
UserService.Instance.myUserInfo
|
||||||
)
|
)
|
||||||
: UserService.Instance.myUserInfo?.local_user_view.local_user.blur_nsfw;
|
: UserService.Instance.myUserInfo?.local_user_view.local_user.blur_nsfw;
|
||||||
|
|
Loading…
Reference in a new issue