Skip to content

Commit b25e673

Browse files
authored
Merge pull request #23 from keepsimpleio/dev
Hotfix: Longevity loading state for russian pages
2 parents adb711e + dca2e9a commit b25e673

3 files changed

Lines changed: 60 additions & 14 deletions

File tree

src/components/longevity/WhyDoThisTooltip/WhyDoThisTooltip.module.scss

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
.whyDoThisTooltip {
2-
background-image: url('/keepsimple_/assets/longevity/habits/what-is-this-bg.webp');
3-
background-size: contain;
42
width: 700px;
53
height: 100%;
6-
background-repeat: no-repeat;
74
z-index: 999;
85
padding-bottom: 20px;
6+
position: relative;
97

8+
.img {
9+
position: absolute;
10+
}
1011
.heading {
1112
padding-top: 20px;
1213
padding-left: 20px;
@@ -34,6 +35,8 @@
3435
.content {
3536
padding-left: 20px;
3637
padding-top: 12px;
38+
z-index: 55;
39+
position: relative;
3740

3841
p {
3942
width: 337px;
@@ -45,11 +48,13 @@
4548

4649
@media (max-width: 956px) {
4750
.whyDoThisTooltip {
48-
background-image: unset;
4951
width: unset;
5052
height: unset;
5153
padding-bottom: unset;
5254

55+
.img {
56+
display: none;
57+
}
5358
.heading {
5459
padding-top: 0;
5560
padding-left: 0;

src/components/longevity/WhyDoThisTooltip/WhyDoThisTooltip.tsx

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,59 @@ import Heading from '@components/Heading';
55
import { WhyDoThisTooltipProps } from './WhyDoThisTooltip.types';
66

77
import styles from './WhyDoThisTooltip.module.scss';
8+
import Image from 'next/image';
89

910
const WhyDoThisTooltip: FC<WhyDoThisTooltipProps> = ({
1011
whatDamagesText,
1112
headline,
1213
locale,
1314
}) => {
15+
// TODO: This is very temporary workaround for strapi data
16+
const looksLikeHtml = (s: string) => /<\/?[a-z][\s\S]*>/i.test(s);
17+
const escapeHtml = (s: string) =>
18+
s
19+
.replace(/&/g, '&amp;')
20+
.replace(/</g, '&lt;')
21+
.replace(/>/g, '&gt;')
22+
.replace(/"/g, '&quot;')
23+
.replace(/'/g, '&#039;');
24+
25+
const textToHtml = (input: string) => {
26+
let s = escapeHtml(input);
27+
28+
s = s.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>');
29+
30+
const paragraphs = s
31+
.split(/\n\s*\n/)
32+
.map(p => p.trim())
33+
.filter(Boolean);
34+
35+
return paragraphs.map(p => `<p>${p.replace(/\n/g, '<br />')}</p>`).join('');
36+
};
37+
function RichText({ value }: { value?: string | null }) {
38+
if (!value) return null;
39+
40+
const html = looksLikeHtml(value) ? value : textToHtml(value);
41+
42+
return (
43+
<div
44+
dangerouslySetInnerHTML={{ __html: html }}
45+
className={styles.content}
46+
/>
47+
);
48+
}
49+
1450
return (
1551
<div className={styles.whyDoThisTooltip}>
1652
<div>
53+
<Image
54+
src={'/keepsimple_/assets/longevity/habits/what-is-this-bg.webp'}
55+
alt="Background"
56+
width={700}
57+
height={300}
58+
priority
59+
className={styles.img}
60+
/>
1761
{headline && (
1862
<Heading
1963
text={headline ? headline : ''}
@@ -23,10 +67,7 @@ const WhyDoThisTooltip: FC<WhyDoThisTooltipProps> = ({
2367
className={styles.heading}
2468
/>
2569
)}
26-
<div
27-
dangerouslySetInnerHTML={{ __html: whatDamagesText || '' }}
28-
className={styles.content}
29-
/>
70+
<RichText value={whatDamagesText} />
3071
</div>
3172
</div>
3273
);

src/pages/_app.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ function App({ Component, pageProps: { session, ...pageProps } }: TApp) {
224224
}
225225
}, [accountData?.id, accountData?.createdAt]);
226226

227-
const clean = (url: string) =>
228-
url.split('?')[0].split('#')[0].replace(/\/+$/, '');
229-
const isLongevityUrl = (url: string) =>
230-
clean(url).startsWith(longevityBaseUrl);
227+
const isLongevityUrl = (url: string) => {
228+
const normalizedUrl = url.split('?')[0].split('#')[0].replace(/\/+$/, '');
229+
return normalizedUrl.startsWith(longevityBaseUrl);
230+
};
231231

232232
useEffect(() => {
233233
const onStart = (url: string) => {
@@ -273,8 +273,8 @@ function App({ Component, pageProps: { session, ...pageProps } }: TApp) {
273273
}, []);
274274

275275
const isLongevityNow = isLongevityUrl(router.asPath);
276-
const overlayOn =
277-
isLongevityNow && (routeLoading || !heroReady || !videosReady);
276+
//TODO: Fix heroReady logic
277+
const overlayOn = isLongevityNow && (routeLoading || !videosReady);
278278

279279
return (
280280
<SessionProvider session={session}>

0 commit comments

Comments
 (0)