Skip to content

Commit 10404e6

Browse files
committed
Initial setup, adjust styles and prep for new data
1 parent 2de3f69 commit 10404e6

File tree

15 files changed

+182
-50
lines changed

15 files changed

+182
-50
lines changed

special-pages/pages/new-tab/app/components/Icons.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,3 +601,36 @@ export function CloseSmallIcon(props) {
601601
</svg>
602602
);
603603
}
604+
605+
/**
606+
* @param {import('preact').JSX.SVGAttributes<SVGSVGElement>} props
607+
*/
608+
export function NewBadgeIcon(props) {
609+
return (
610+
<svg xmlns="http://www.w3.org/2000/svg" width="42" height="16" viewBox="0 0 42 16" fill="none" {...props}>
611+
<path d="M0 3.99792C0 1.78879 1.79086 -0.0020752 4 -0.0020752H38C40.2091 -0.0020752 42 1.78879 42 3.99792V11.9979C42 14.2071 40.2091 15.9979 38 15.9979H4C1.79086 15.9979 0 14.2071 0 11.9979V3.99792Z" fill="#F9BE1A"/>
612+
<path d="M13.0913 9.1073H13.1812V3.94617H14.8032V12.0497H13.3999L9.64893 6.86707H9.55908V12.0497H7.93604V3.94617H9.35107L13.0913 9.1073Z" fill="black" fill-opacity="0.96"/>
613+
<path d="M22.144 5.3446H18.4722V7.29871H21.936V8.60144H18.4722V10.6512H22.144V12.0497H16.7759V3.94617H22.144V5.3446Z" fill="black" fill-opacity="0.96"/>
614+
<path d="M26.4663 9.73621H26.5562L28.0337 3.94617H29.4653L30.9702 9.73621H31.0601L32.312 3.94617H34.064L31.9136 12.0497H30.3247L28.7915 6.59167H28.7017L27.1851 12.0497H25.5854L23.4399 3.94617H25.2036L26.4663 9.73621Z" fill="black" fill-opacity="0.96"/>
615+
</svg>
616+
);
617+
}
618+
619+
/**
620+
* @param {import('preact').JSX.SVGAttributes<SVGSVGElement>} props
621+
*/
622+
export function InfoIcon(props) {
623+
return (
624+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none" {...props}>
625+
<path d="M8.48319 3.64453C7.73951 3.64453 7.28748 4.24239 7.28748 4.7965C7.28748 5.46726 7.79784 5.68599 8.24988 5.68599C9.08104 5.68599 9.43101 5.05897 9.43101 4.54861C9.43101 3.907 8.92064 3.64453 8.48319 3.64453Z" fill="black" fill-opacity="0.36"/>
626+
<path d="M8.91304 6.54504L7.08645 6.84036C7.03054 7.28244 6.95011 7.72956 6.86842 8.18373C6.71074 9.06033 6.54834 9.96319 6.54834 10.9066C6.54834 11.8434 7.10858 12.3547 7.99455 12.3547C9.00639 12.3547 9.17956 11.7196 9.21882 11.1442C8.37999 11.2659 8.19573 10.8873 8.33282 9.99619C8.46991 9.10509 8.91304 6.54504 8.91304 6.54504Z" fill="black" fill-opacity="0.36"/>
627+
<path
628+
fill-rule="evenodd"
629+
clip-rule="evenodd"
630+
d="M8 0C3.58172 0 0 3.58172 0 8C0 12.4183 3.58172 16 8 16C12.4183 16 16 12.4183 16 8C16 3.58172 12.4183 0 8 0ZM1.25 8C1.25 4.27208 4.27208 1.25 8 1.25C11.7279 1.25 14.75 4.27208 14.75 8C14.75 11.7279 11.7279 14.75 8 14.75C4.27208 14.75 1.25 11.7279 1.25 8Z"
631+
fill="black"
632+
fill-opacity="0.36"
633+
/>
634+
</svg>
635+
);
636+
}

special-pages/pages/new-tab/app/privacy-stats/components/PrivacyStats.module.css

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
display: flex;
33
align-items: center;
44
height: 24px;
5-
margin-bottom: 16px;
5+
margin-bottom: 36px;
66
position: relative;
7-
gap: 8px;
7+
gap: 2px;
8+
9+
&.noTrackers {
10+
margin-bottom: 12px;
11+
}
812
}
913

1014
.headingIcon {
@@ -13,7 +17,7 @@
1317
position: relative;
1418
display: flex;
1519
align-items: center;
16-
justify-content: center;
20+
justify-content: left;
1721
padding-top: 0.5px;
1822

1923
img {
@@ -26,13 +30,18 @@
2630
font-size: var(--title-3-em-font-size);
2731
font-weight: var(--title-3-em-font-weight);
2832
line-height: var(--title-3-em-line-height);
29-
flex: 1;
33+
flex: 0 0 auto;
34+
margin-right: 6px;
3035
}
3136

3237
.widgetExpander {
3338
position: relative;
39+
flex: 1;
3440

3541
& [aria-controls] {
42+
background-color: var(--ntp-widget-expander-bg);
43+
width: 24px;
44+
height: 24px;
3645
position: absolute;
3746
top: 50%;
3847
transform: translateY(-50%);
@@ -46,17 +55,31 @@
4655
}
4756
}
4857

58+
.counterContainer {
59+
display: flex;
60+
gap: 24px;
61+
}
62+
4963
.counter {
5064
display: flex;
5165
flex-direction: column;
5266
gap: 4px;
67+
padding-right: 38px;
5368
}
5469

5570
.title {
71+
color: var(--ntp-text-muted);
5672
grid-area: title;
57-
font-size: var(--title-2-font-size);
58-
font-weight: var(--title-2-font-weight);
59-
line-height: var(--title-2-line-height);
73+
font-size: var(--title-3-em-font-size);
74+
font-weight: 400;
75+
line-height: 28px;
76+
77+
& span {
78+
color: var(--ntp-text-primary);
79+
display: block;
80+
font-size: 40px;
81+
padding-bottom: 6px;
82+
}
6083
}
6184

6285
.subtitle {

special-pages/pages/new-tab/app/privacy-stats/strings.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
"note": "Placeholder to indicate that no tracking activity was blocked in the last 7 days"
1717
},
1818
"stats_countBlockedSingular": {
19-
"title": "1 tracking attempt blocked",
19+
"title": "Tracking attempt blocked",
2020
"note": "The main headline indicating that a single tracker was blocked"
2121
},
2222
"stats_countBlockedPlural": {
23-
"title": "{count} tracking attempts blocked",
23+
"title": "Tracking attempts blocked",
2424
"note": "The main headline indicating that more than 1 attempt has been blocked. Eg: '2 tracking attempts blocked'"
2525
},
2626
"stats_noActivityAdsAndTrackers": {
@@ -32,13 +32,21 @@
3232
"note": "Placeholder to indicate that no ads or tracking activity was blocked in the last 7 days"
3333
},
3434
"stats_countBlockedAdsAndTrackersSingular": {
35-
"title": "<b>1</b> advertising & tracking attempt blocked",
35+
"title": "advertising & tracking attempt blocked",
3636
"note": "The main headline indicating that a single ad or tracking attempt was blocked"
3737
},
3838
"stats_countBlockedAdsAndTrackersPlural": {
39-
"title": "<b>{count}</b> advertising & tracking attempts blocked",
39+
"title": "advertising & tracking attempts blocked",
4040
"note": "The main headline indicating that more than 1 ad or tracking attempt has been blocked. Eg: '2 advertising & tracking attempts blocked"
4141
},
42+
"stats_totalCookiePopUpsBlockedSingular": {
43+
"title": "Cookie pop-up blocked",
44+
"note": "The heading indicating that a single cookie pop-up was handled by the CPM"
45+
},
46+
"stats_totalCookiePopUpsBlockedPlural": {
47+
"title": "Cookie pop-ups blocked",
48+
"note": "The heading indicating multiple cookie pop-ups were handled by the CPM"
49+
},
4250
"stats_feedCountBlockedSingular": {
4351
"title": "1 attempt blocked by DuckDuckGo in the last 7 days",
4452
"note": "A summary description of how many tracking attempts where blocked, when only one exists."

special-pages/pages/new-tab/app/protections/components/Protections.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ import { useTypedTranslationWith } from '../../types.js';
2222
* @param {(feed: ProtectionsConfig['feed']) => void} props.setFeed
2323
* @param {import("preact").ComponentChild} [props.children]
2424
* @param {()=>void} props.toggle
25+
* @param {import("@preact/signals").Signal<number>} props.totalCookiePopUpsBlockedSignal
2526
*/
26-
export function Protections({ expansion = 'expanded', children, blockedCountSignal, feed, toggle, setFeed }) {
27+
export function Protections({ expansion = 'expanded', children, blockedCountSignal, feed, toggle, setFeed, totalCookiePopUpsBlockedSignal }) {
2728
const WIDGET_ID = useId();
2829
const TOGGLE_ID = useId();
2930

@@ -42,6 +43,7 @@ export function Protections({ expansion = 'expanded', children, blockedCountSign
4243
expansion={expansion}
4344
canExpand={true}
4445
buttonAttrs={attrs}
46+
totalCookiePopUpsBlockedSignal={totalCookiePopUpsBlockedSignal}
4547
/>
4648
<ProtectionsBody feed={feed} setFeed={setFeed} id={WIDGET_ID} expansion={expansion}>
4749
{children}

special-pages/pages/new-tab/app/protections/components/Protections.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
}
4545

4646
.block {
47-
margin-top: 24px;
47+
margin-top: 32px;
4848
}
4949
.empty {
5050
color: var(--ntp-text-muted);

special-pages/pages/new-tab/app/protections/components/ProtectionsConsumer.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useContext } from 'preact/hooks';
2-
import { ProtectionsContext, useBlockedCount } from './ProtectionsProvider.js';
2+
import { ProtectionsContext, useBlockedCount, useCookiePopUpsBlockedCount } from './ProtectionsProvider.js';
33
import { h } from 'preact';
44
import { Protections } from './Protections.js';
55
import { ActivityProvider } from '../../activity/ActivityProvider.js';
@@ -40,13 +40,18 @@ export function ProtectionsConsumer() {
4040
function ProtectionsReadyState({ data, config }) {
4141
const { toggle, setFeed } = useContext(ProtectionsContext);
4242
const blockedCountSignal = useBlockedCount(data.totalCount);
43+
const totalCookiePopUpsBlockedSignal = useCookiePopUpsBlockedCount(
44+
data.totalCookiePopUpsBlocked
45+
);
46+
4347
return (
4448
<Protections
4549
blockedCountSignal={blockedCountSignal}
4650
expansion={config.expansion}
4751
toggle={toggle}
4852
feed={config.feed}
4953
setFeed={setFeed}
54+
totalCookiePopUpsBlockedSignal={totalCookiePopUpsBlockedSignal}
5055
>
5156
{config.feed === 'activity' && (
5257
<ActivityProvider>

special-pages/pages/new-tab/app/protections/components/ProtectionsHeading.js

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import { useTypedTranslationWith } from '../../types.js';
2-
import { useState } from 'preact/hooks';
32
import styles from '../../privacy-stats/components/PrivacyStats.module.css';
43
import { ShowHideButtonCircle } from '../../components/ShowHideButton.jsx';
54
import cn from 'classnames';
65
import { h } from 'preact';
7-
import { useAdBlocking } from '../../settings.provider.js';
8-
import { Trans } from '../../../../../shared/components/TranslationsProvider.js';
9-
import { getLocalizedNumberFormatter } from '../../../../../shared/utils.js';
10-
import { useLocale } from '../../../../../shared/components/EnvironmentProvider.js';
6+
import { InfoIcon, NewBadgeIcon } from '../../components/Icons.js';
117

128
/**
139
* @import enStrings from "../strings.json"
@@ -20,33 +16,33 @@ import { useLocale } from '../../../../../shared/components/EnvironmentProvider.
2016
* @param {boolean} props.canExpand
2117
* @param {() => void} props.onToggle
2218
* @param {import('preact').ComponentProps<'button'>} [props.buttonAttrs]
19+
* @param {import("@preact/signals").Signal<number>} props.totalCookiePopUpsBlockedSignal
2320
*/
24-
export function ProtectionsHeading({ expansion, canExpand, blockedCountSignal, onToggle, buttonAttrs = {} }) {
21+
export function ProtectionsHeading({ expansion, canExpand, blockedCountSignal, onToggle, buttonAttrs = {}, totalCookiePopUpsBlockedSignal }) {
2522
const { t } = useTypedTranslationWith(/** @type {Strings} */ ({}));
26-
const locale = useLocale();
27-
const [formatter] = useState(() => getLocalizedNumberFormatter(locale));
28-
const adBlocking = useAdBlocking();
29-
const blockedCount = blockedCountSignal.value;
30-
const none = blockedCount === 0;
31-
const some = blockedCount > 0;
32-
const alltime = formatter.format(blockedCount);
23+
const totalTrackersBlocked = blockedCountSignal.value;
24+
const totalCookiePopUpsBlocked = totalCookiePopUpsBlockedSignal.value;
3325

34-
let alltimeTitle;
35-
if (blockedCount === 1) {
36-
alltimeTitle = adBlocking ? t('stats_countBlockedAdsAndTrackersSingular') : t('stats_countBlockedSingular');
37-
} else {
38-
alltimeTitle = adBlocking
39-
? t('stats_countBlockedAdsAndTrackersPlural', { count: alltime })
40-
: t('stats_countBlockedPlural', { count: alltime });
41-
}
26+
// @todo jingram get these values from native
27+
const isCpmEnabled = true; // Is Cookie pop-up protection in app
28+
const shouldShowCookiePopUpsBlocked = true; // from ProtectionsConfig
29+
30+
const trackersBlockedHeading = totalTrackersBlocked === 1
31+
? t('stats_countBlockedSingular')
32+
: t('stats_countBlockedPlural')
33+
34+
const cookiePopUpsBlockedHeading = totalCookiePopUpsBlocked === 1
35+
? t('stats_totalCookiePopUpsBlockedSingular')
36+
: t('stats_totalCookiePopUpsBlockedPlural')
4237

4338
return (
4439
<div class={styles.heading} data-testid="ProtectionsHeading">
45-
<div class={styles.control}>
40+
<div class={cn(styles.control, totalTrackersBlocked === 0 && styles.noTrackers)}>
4641
<span class={styles.headingIcon}>
4742
<img src={'./icons/Shield-Check-Color-16.svg'} alt="Privacy Shield" />
4843
</span>
4944
<h2 class={styles.caption}>{t('protections_menuTitle')}</h2>
45+
<InfoIcon class={styles.infoIcon}/>
5046
{canExpand && (
5147
<span class={styles.widgetExpander}>
5248
<ShowHideButtonCircle
@@ -61,15 +57,33 @@ export function ProtectionsHeading({ expansion, canExpand, blockedCountSignal, o
6157
</span>
6258
)}
6359
</div>
64-
<div class={styles.counter}>
65-
{none && <h3 class={styles.title}>{t('protections_noRecent')}</h3>}
66-
{some && (
60+
<div class={styles.counterContainer}>
61+
{/* Total Trackers Blocked */}
62+
<div class={styles.counter}>
63+
{totalTrackersBlocked === 0 && (
64+
<h3 class={styles.title}>{t('protections_noRecent')}</h3>
65+
)}
66+
{totalTrackersBlocked > 0 && (
6767
<h3 class={styles.title}>
68-
{' '}
69-
<Trans str={alltimeTitle} values={{ count: alltime }} />
68+
<span>{totalTrackersBlocked}</span>
69+
{trackersBlockedHeading}
7070
</h3>
71+
)}
72+
</div>
73+
74+
{/* Total Cookie Pop-Ups Blocked */}
75+
{/* Rules: Display CPM stats when Cookie Pop-Up Protection is
76+
enabled AND both `totalTrackersBlocked` and
77+
`totalCookiePopUpsBlocked` are at least 1 */}
78+
{(shouldShowCookiePopUpsBlocked && isCpmEnabled && totalTrackersBlocked > 0 && totalCookiePopUpsBlocked > 0) && (
79+
<div class={styles.counter}>
80+
<h3 class={styles.title}>
81+
<span>{totalCookiePopUpsBlocked}</span>
82+
{cookiePopUpsBlockedHeading}
83+
</h3>
84+
<NewBadgeIcon />
85+
</div>
7186
)}
72-
<p class={cn(styles.subtitle, styles.indented)}>{t('stats_feedCountBlockedPeriod')}</p>
7387
</div>
7488
</div>
7589
);

special-pages/pages/new-tab/app/protections/components/ProtectionsProvider.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,20 @@ export function useBlockedCount(initial) {
104104
});
105105
return signal;
106106
}
107+
108+
/**
109+
* @param {number} initial
110+
* @return {import("@preact/signals").Signal<number>}
111+
*/
112+
export function useCookiePopUpsBlockedCount(initial) {
113+
const service = useService();
114+
const signal = useSignal(initial);
115+
116+
useSignalEffect(() => {
117+
return service.current?.onData((evt) => {
118+
signal.value = evt.data.totalCookiePopUpsBlocked;
119+
});
120+
});
121+
122+
return signal;
123+
}

special-pages/pages/new-tab/app/protections/mocks/protections.mocks.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
export const protectionsMocks = {
66
empty: {
77
totalCount: 0,
8+
totalCookiePopUpsBlocked: 0,
89
},
910
few: {
1011
totalCount: 86,
12+
totalCookiePopUpsBlocked: 23,
1113
},
1214
many: {
1315
totalCount: 1_000_020,
16+
totalCookiePopUpsBlocked: 5_432,
1417
},
1518
};

special-pages/pages/new-tab/app/protections/protections.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ title: Protections Report
2929
- returns {@link "NewTab Messages".ProtectionsData}
3030
```json
3131
{
32-
"totalCount": 84
32+
"totalCount": 84,
33+
"totalCookiePopUpsBlocked": 23
3334
}
3435
```
3536

0 commit comments

Comments
 (0)