From 1b4903d73288e5ce077eef9316ab2fedb9a1d0d1 Mon Sep 17 00:00:00 2001 From: Matthias Camenzind Date: Thu, 18 Apr 2024 13:18:39 +0200 Subject: [PATCH] Blur SSR by default when content warning is set --- lemmy-translations | 2 +- src/assets/css/main.css | 4 --- src/server/utils/create-ssr-html.tsx | 19 +++++++++++ .../components/common/adult-consent-modal.tsx | 32 ++++++++++++------- 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/lemmy-translations b/lemmy-translations index d250d15f4..e78c744ab 160000 --- a/lemmy-translations +++ b/lemmy-translations @@ -1 +1 @@ -Subproject commit d250d15f4fbf3e1b9565529f7d0cea90c8270757 +Subproject commit e78c744abe5c3824f9ca7de7f1ee086468385ee0 diff --git a/src/assets/css/main.css b/src/assets/css/main.css index cc962abc2..a7d7e706b 100644 --- a/src/assets/css/main.css +++ b/src/assets/css/main.css @@ -461,7 +461,3 @@ br.big { .totp-link { width: fit-content; } - -#adultConsentModal { - backdrop-filter: blur(10px); -} diff --git a/src/server/utils/create-ssr-html.tsx b/src/server/utils/create-ssr-html.tsx index c47e1dae2..688b65aae 100644 --- a/src/server/utils/create-ssr-html.tsx +++ b/src/server/utils/create-ssr-html.tsx @@ -75,6 +75,20 @@ export async function createSsrHtml( .map(x => ``) .join(""); + // Blurring has to happen even if all style sheets fail to load. + const blurStyles = !site?.site_view.site.content_warning + ? "" + : ` + `; + return ` @@ -84,7 +98,12 @@ export async function createSsrHtml( const light = window.matchMedia("(prefers-color-scheme: light)").matches; document.documentElement.setAttribute("data-bs-theme", light ? "light" : "dark"); } + if (document.documentElement.hasAttribute("data-lemmy-blur")) { + const consent = localStorage.getItem("adult-consent") === "true"; + document.documentElement.setAttribute("data-lemmy-blur", consent ? "off" : "on"); + } + ${blurStyles} ${lazyScripts} diff --git a/src/shared/components/common/adult-consent-modal.tsx b/src/shared/components/common/adult-consent-modal.tsx index 30df04838..38ed259cc 100644 --- a/src/shared/components/common/adult-consent-modal.tsx +++ b/src/shared/components/common/adult-consent-modal.tsx @@ -4,7 +4,9 @@ import { adultConsentLocalStorageKey } from "../../config"; import { setIsoData } from "@utils/app"; import { IsoDataOptionalSite } from "../../interfaces"; import { mdToHtml } from "../../markdown"; -import { I18NextService, UserService } from "../../services"; +import { I18NextService } from "../../services"; +import { isBrowser } from "@utils/browser"; +import { Helmet } from "inferno-helmet"; interface AdultConsentModalProps { contentWarning: string; @@ -33,6 +35,13 @@ class AdultConsentModalInner extends Component { data-bs-backdrop="static" ref={this.modalDivRef} > +