Skip to content

Commit 747bd3a

Browse files
committed
More SR fixes, closes #1445
1 parent b5fc937 commit 747bd3a

File tree

6 files changed

+53
-14
lines changed

6 files changed

+53
-14
lines changed

special-pages/pages/new-tab/app/activity/components/Activity.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { memo } from 'preact/compat';
55
import { ActivityApiContext, ActivityContext, ActivityProvider, SignalStateContext, SignalStateProvider } from '../ActivityProvider.js';
66
import { useTypedTranslationWith } from '../../types.js';
77
import { useVisibility } from '../../widget-list/widget-config.provider.js';
8-
import { useDocumentVisibility } from '../../utils.js';
8+
import { useOnMiddleClick, useDocumentVisibility } from '../../utils.js';
99
import { useCustomizer } from '../../customizer/components/CustomizerMenu.js';
1010
import { useBatchedActivityApi, usePlatformName } from '../../settings.provider.js';
1111
import { ActivityHeading } from '../../privacy-stats/components/PrivacyStats.js';
@@ -42,6 +42,9 @@ function ActivityConfigured({ expansion, toggle }) {
4242
const { activity } = useContext(SignalStateContext);
4343
const { didClick } = useContext(ActivityApiContext);
4444

45+
const ref = useRef(/** @type {HTMLUListElement|null} */ (null));
46+
useOnMiddleClick(ref, didClick);
47+
4548
const count = useComputed(() => {
4649
return activity.value.totalTrackers;
4750
});
@@ -200,7 +203,7 @@ function TrackerStatus({ id, trackersFound }) {
200203
const { t } = useTypedTranslationWith(/** @type {enStrings} */ ({}));
201204
const { activity } = useContext(SignalStateContext);
202205
const status = useComputed(() => activity.value.trackingStatus[id]);
203-
const other = status.value.trackerCompanies.length - DDG_MAX_TRACKER_ICONS;
206+
const other = status.value.trackerCompanies.slice(DDG_MAX_TRACKER_ICONS - 1);
204207
// const { env } = useEnv();
205208
// if (env === 'development') {
206209
// console.groupCollapsed(`trackingStatus ${id}`);
@@ -209,14 +212,21 @@ function TrackerStatus({ id, trackersFound }) {
209212
// console.groupEnd();
210213
// }
211214

212-
const companyIconsMax = other === 0 ? DDG_MAX_TRACKER_ICONS : DDG_MAX_TRACKER_ICONS - 1;
213-
const icons = useComputed(() => {
214-
return status.value.trackerCompanies.slice(0, companyIconsMax).map((item, index) => {
215-
return <CompanyIcon displayName={item.displayName} key={item} />;
216-
});
215+
const companyIconsMax = other.length === 0 ? DDG_MAX_TRACKER_ICONS : DDG_MAX_TRACKER_ICONS - 1;
216+
217+
const icons = status.value.trackerCompanies.slice(0, companyIconsMax).map((item, index) => {
218+
return <CompanyIcon displayName={item.displayName} key={item} />;
217219
});
218220

219-
const otherIcon = other > 0 ? <span class={styles.otherIcon}>+{other + 1}</span> : null;
221+
let otherIcon = null;
222+
if (other.length > 0) {
223+
const title = other.map((item) => item.displayName).join('\n');
224+
otherIcon = (
225+
<span title={title} class={styles.otherIcon}>
226+
+{other.length}
227+
</span>
228+
);
229+
}
220230

221231
if (status.value.totalCount === 0) {
222232
if (trackersFound) return <p>{t('activity_no_trackers_blocked')}</p>;

special-pages/pages/new-tab/app/activity/integration-tests/activity.spec.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,18 @@ test.describe('activity widget', () => {
165165
});
166166
test('fetches the minimal amount initially, and then chunks', async ({ page }, workerInfo) => {
167167
const ntp = NewtabPage.create(page, workerInfo);
168-
const widget = new ActivityPage(page, ntp);
168+
const widget = new ActivityPage(page, ntp).withEntries(200);
169169
const batching = new BatchingPage(page, ntp, widget);
170170
await ntp.reducedMotion();
171-
await ntp.openPage({ additional: { feed: 'activity', 'activity.api': 'batched', platform: 'windows', activity: '200' } });
171+
await ntp.openPage({
172+
additional: { feed: 'activity', 'activity.api': 'batched', platform: 'windows', activity: widget.entries },
173+
});
172174
await batching.fetchedRows(5);
173175
await widget.hasRows(5);
174176
await batching.triggerNext();
175177
await widget.hasRows(15);
176178
await batching.triggerNext();
179+
await page.waitForTimeout(100);
177180
await widget.hasRows(25);
178181
});
179182
test('patching in place', async ({ page }, workerInfo) => {

special-pages/pages/new-tab/app/activity/mocks/activity.mock-transport.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ export function activityMockTransport() {
8888

8989
if (sub === 'activity_onDataPatch') {
9090
/** @type {any} */ (window).af = {
91+
gen(count) {
92+
return generateSampleData(count);
93+
},
9194
patchAddBack(count) {
9295
const len = dataset.activity.length;
9396
const all = generateSampleData(200);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const CompanyIcon = memo(
3333
: `./company-icons/${firstChar}.svg`;
3434

3535
return (
36-
<span className={styles.icon}>
36+
<span className={styles.icon} title={displayName}>
3737
<img src={src} alt={''} class={styles.companyImgIcon} data-loaded="true" />
3838
</span>
3939
);

special-pages/pages/new-tab/app/favorites/components/Favorites.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { TileRow } from './TileRow.js';
1212
import { FavoritesContext } from './FavoritesProvider.js';
1313
import { CustomizerContext, CustomizerThemesContext } from '../../customizer/CustomizerProvider.js';
1414
import { signal, useComputed } from '@preact/signals';
15-
import { eventToTarget, useDocumentVisibility } from '../../utils.js';
15+
import { eventToTarget, useOnMiddleClick, useDocumentVisibility } from '../../utils.js';
1616

1717
/**
1818
* @typedef {import('../../../types/new-tab.js').Expansion} Expansion
@@ -153,14 +153,17 @@ function VirtualizedGridRows({ WIDGET_ID, rowHeight, favorites, expansion, openF
153153
? rowHeight
154154
: rows.length * rowHeight;
155155

156+
const clickHandler = getOnClickHandler(openFavorite, platformName);
157+
useOnMiddleClick(safeAreaRef, clickHandler);
158+
156159
return (
157160
<div
158161
className={styles.grid}
159162
style={{ height: containerHeight + 'px' }}
160163
id={WIDGET_ID}
161164
ref={safeAreaRef}
162165
onContextMenu={getContextMenuHandler(openContextMenu)}
163-
onClick={getOnClickHandler(openFavorite, platformName)}
166+
onClick={clickHandler}
164167
>
165168
{rows.length === 0 && <TileRow key={'empty-rows'} items={[]} topOffset={0} add={add} visibility={'visible'} />}
166169
{rows.length > 0 && <Inner rows={rows} safeAreaRef={safeAreaRef} rowHeight={rowHeight} add={add} />}

special-pages/pages/new-tab/app/utils.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export function eventToTarget(event, platformName) {
7070
const isControlClick = platformName === 'macos' ? event.metaKey : event.ctrlKey;
7171
if (isControlClick) {
7272
return 'new-tab';
73-
} else if (event.shiftKey) {
73+
} else if (event.shiftKey || event.button === 1 /* middle click */) {
7474
return 'new-window';
7575
}
7676
return 'same-tab';
@@ -95,3 +95,23 @@ export function useDocumentVisibility() {
9595

9696
return documentVisibility;
9797
}
98+
99+
/**
100+
* Custom hook to handle middle click event on an element. This is required because Preact doens't support the auxclick event.
101+
* @param {import('preact').RefObject<HTMLElement>} ref - The ref of the element to attach the event listener to.
102+
* @param {Function} handler - The function to execute on the middle click event.
103+
*/
104+
export function useOnMiddleClick(ref, handler) {
105+
useEffect(() => {
106+
const element = ref.current;
107+
if (!element) return;
108+
109+
const handleAuxClick = (event) => event.button === 1 /* middle button */ && handler(event);
110+
111+
element.addEventListener('auxclick', handleAuxClick);
112+
113+
return () => {
114+
element.removeEventListener('auxclick', handleAuxClick);
115+
};
116+
}, [ref, handler]);
117+
}

0 commit comments

Comments
 (0)