Skip to content

Commit

Permalink
revert
Browse files Browse the repository at this point in the history
  • Loading branch information
shakyShane committed Jan 31, 2025
1 parent 478f3a1 commit c6adb56
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 68 deletions.
94 changes: 43 additions & 51 deletions special-pages/pages/new-tab/app/activity/ActivityProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,58 +95,50 @@ export function ActivityProvider(props) {
* @return {NormalizedActivity}
*/
function normalizeItems(prev, data) {
/** @type {Record<string, boolean>} */
const nextFavorites = {};
/** @type {Record<string, Item>} */
const nextItems = {};
/** @type {Record<string, HistoryEntry[]>} */
const nextHistory = {};
/** @type {Record<string, TrackingStatus>} */
const nextTrackingStatus = {};

for (const x of data.activity) {
nextFavorites[x.url] = x.favorite;
{
/** @type {Item} */
const next = {
etldPlusOne: x.etldPlusOne,
title: x.title,
url: x.url,
faviconMax: x.favicon?.maxAvailableSize ?? DDG_DEFAULT_ICON_SIZE,
favoriteSrc: x.favicon?.src,
trackersFound: x.trackersFound,
};
const differs = shallowDiffers(next, prev.items[x.url] || {});
nextItems[x.url] = differs ? next : prev.items[x.url] || {};
}

{
const differs = shallowDiffers(x.history, prev.history[x.url] || []);
nextHistory[x.url] = differs ? [...x.history] : prev.history[x.url] || [];
}

{
const prevItem = prev.trackingStatus[x.url] || {
totalCount: 0,
trackerCompanies: [],
};
const differs = shallowDiffers(x.trackingStatus.trackerCompanies, prevItem.trackerCompanies);
if (prevItem.totalCount !== x.trackingStatus.totalCount || differs) {
nextTrackingStatus[x.url] = {
totalCount: x.trackingStatus.totalCount,
trackerCompanies: [...x.trackingStatus.trackerCompanies],
};
} else {
nextTrackingStatus[x.url] = prevItem;
}
}
}

return {
favorites: nextFavorites,
items: nextItems,
history: nextHistory,
trackingStatus: nextTrackingStatus,
favorites: Object.fromEntries(
data.activity.map((x) => {
return [x.url, x.favorite];
}),
),
items: Object.fromEntries(
data.activity.map((x) => {
/** @type {Item} */
const next = {
etldPlusOne: x.etldPlusOne,
title: x.title,
url: x.url,
faviconMax: x.favicon?.maxAvailableSize ?? DDG_DEFAULT_ICON_SIZE,
favoriteSrc: x.favicon?.src,
trackersFound: x.trackersFound,
};
const differs = shallowDiffers(next, prev.items[x.url] || {});
return [x.url, differs ? next : prev.items[x.url] || {}];
}),
),
history: Object.fromEntries(
data.activity.map((x) => {
const differs = shallowDiffers(x.history, prev.history[x.url] || []);
return [x.url, differs ? [...x.history] : prev.history[x.url] || []];
}),
),
trackingStatus: Object.fromEntries(
data.activity.map((x) => {
const prevItem = prev.trackingStatus[x.url] || {
totalCount: 0,
trackerCompanies: [],
};
const differs = shallowDiffers(x.trackingStatus.trackerCompanies, prevItem.trackerCompanies);
if (prevItem.totalCount !== x.trackingStatus.totalCount || differs) {
const next = {
totalCount: x.trackingStatus.totalCount,
trackerCompanies: [...x.trackingStatus.trackerCompanies],
};
return [x.url, next];
}
return [x.url, prevItem];
}),
),
};
}

Expand Down
7 changes: 1 addition & 6 deletions special-pages/pages/new-tab/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,7 @@ export async function init(root, messaging, telemetry, baseEnvironment) {
.withPlatformName(baseEnvironment.injectName)
.withPlatformName(init.platform?.name)
.withPlatformName(baseEnvironment.urlParams.get('platform'))
.withFeatureState('customizerDrawer', init.settings?.customizerDrawer)
.withFeatureState(
'batchedActivityApi',
baseEnvironment.urlParams.get('activity.api') === 'batched' ? { state: 'enabled' } : { state: 'disabled' },
)
.withFeatureState('batchedActivityApi', init.platform.name === 'windows' ? { state: 'enabled' } : { state: 'disabled' });
.withFeatureState('customizerDrawer', init.settings?.customizerDrawer);

if (!window.__playwright_01) {
console.log('environment:', environment);
Expand Down
19 changes: 8 additions & 11 deletions special-pages/pages/new-tab/app/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,10 @@ export class Settings {
* @param {object} params
* @param {{name: 'macos' | 'windows'}} [params.platform]
* @param {{state: 'enabled' | 'disabled', autoOpen: boolean}} [params.customizerDrawer]
* @param {{state: 'enabled' | 'disabled'}} [params.batchedActivityApi]
*/
constructor({
platform = { name: 'macos' },
customizerDrawer = { state: 'disabled', autoOpen: false },
batchedActivityApi = { state: 'disabled' },
}) {
constructor({ platform = { name: 'macos' }, customizerDrawer = { state: 'disabled', autoOpen: false } }) {
this.platform = platform;
this.customizerDrawer = customizerDrawer;
this.batchedActivityApi = batchedActivityApi;
}

withPlatformName(name) {
Expand All @@ -28,17 +22,15 @@ export class Settings {
}

/**
* @param {(keyof import("../types/new-tab.js").NewTabPageSettings) | 'batchedActivityApi'} named
* @param {keyof import("../types/new-tab.js").NewTabPageSettings} named
* @param {{state: 'enabled' | 'disabled'} | null | undefined} settings
* @return {Settings}
*/
withFeatureState(named, settings) {
if (!settings) return this;
/** @type {(keyof import("../types/new-tab.js").NewTabPageSettings)[]} */
const valid = ['customizerDrawer'];
const other = ['batchedActivityApi'];

if (!valid.includes(/** @type {any} */ (named)) && !other.includes(named)) {
if (!valid.includes(named)) {
console.warn(`Excluding invalid feature key ${named}`);
return this;
}
Expand All @@ -51,4 +43,9 @@ export class Settings {
}
return this;
}

get batchedActivityApi() {
if (this.platform.name === 'windows') return { state: 'enabled' };
return { state: 'disabled' };
}
}

0 comments on commit c6adb56

Please sign in to comment.