Skip to content

Commit 9cd24f0

Browse files
committed
Address remaining screenshot issues
1 parent 32c1704 commit 9cd24f0

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { useEnv } from '../../../../../shared/components/EnvironmentProvider.js'
1717
import { useComputed } from '@preact/signals';
1818
import { ActivityItemAnimationWrapper } from './ActivityItemAnimationWrapper.js';
1919
import { useDocumentVisibility } from '../../../../../shared/components/DocumentVisibility.js';
20-
import { HistoryItems } from './HistoryItems.js';
20+
import { HistoryItems, HistoryItemsLegacy } from './HistoryItems.js';
2121
import { NormalizedDataContext, SignalStateProvider } from '../NormalizeDataProvider.js';
2222
import { ActivityInteractionsContext } from '../../burning/ActivityInteractionsContext.js';
2323
import { ProtectionsEmpty } from '../../protections/components/Protections.js';
@@ -154,6 +154,7 @@ const BurnableItem = memo(
154154
// @todo legacyProtections: Once all platforms are ready for the new
155155
// protections report we can use `ActivityItem`
156156
const ActivityItemComponent = shouldDisplayLegacyActivity ? ActivityItemLegacy : ActivityItem;
157+
const HistoryItemsComponent = shouldDisplayLegacyActivity ? HistoryItemsLegacy : HistoryItems;
157158

158159
return (
159160
<ActivityItemAnimationWrapper url={id}>
@@ -174,7 +175,7 @@ const BurnableItem = memo(
174175
) : (
175176
<TrackerStatus id={id} trackersFound={item.value.trackersFound} />
176177
)}
177-
<HistoryItems id={id} />
178+
<HistoryItemsComponent id={id} />
178179
</ActivityItemComponent>
179180
</ActivityItemAnimationWrapper>
180181
);
@@ -203,6 +204,7 @@ const RemovableItem = memo(
203204
// @todo legacyProtections: Once all platforms are ready for the new
204205
// protections report we can use `ActivityItem`
205206
const ActivityItemComponent = shouldDisplayLegacyActivity ? ActivityItemLegacy : ActivityItem;
207+
const HistoryItemsComponent = shouldDisplayLegacyActivity ? HistoryItemsLegacy : HistoryItems;
206208

207209
return (
208210
<ActivityItemComponent
@@ -222,7 +224,7 @@ const RemovableItem = memo(
222224
) : (
223225
<TrackerStatus id={id} trackersFound={item.value.trackersFound} />
224226
)}
225-
<HistoryItems id={id} />
227+
<HistoryItemsComponent id={id} />
226228
</ActivityItemComponent>
227229
);
228230
},

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useContext, useState } from 'preact/hooks';
33
import { NormalizedDataContext } from '../NormalizeDataProvider.js';
44
import { useComputed } from '@preact/signals';
55
import styles from './Activity.module.css';
6+
import stylesLegacy from './ActivityLegacy.module.css';
67
import { ChevronSmall } from '../../components/Icons.js';
78
import { h } from 'preact';
89

@@ -45,6 +46,40 @@ export function HistoryItems({ id }) {
4546
);
4647
}
4748

49+
// @todo legacyProtections: Remove `HistoryItemsLegacy` once all platforms
50+
// support the new UI
51+
52+
/**
53+
* @param {object} props
54+
* @param {string} props.id
55+
*/
56+
export function HistoryItemsLegacy({ id }) {
57+
const { activity } = useContext(NormalizedDataContext);
58+
const history = useComputed(() => activity.value.history[id]);
59+
const [expansion, setExpansion] = useState(/** @type {Expansion} */ ('collapsed'));
60+
const max = Math.min(history.value.length, MAX_SHOW_AMOUNT);
61+
const min = Math.min(MIN_SHOW_AMOUNT, max);
62+
const current = expansion === 'collapsed' ? min : max;
63+
64+
function onClick(event) {
65+
const btn = event.target?.closest('button[data-action]');
66+
if (btn?.dataset.action === 'hide') {
67+
setExpansion('collapsed');
68+
} else if (btn?.dataset.action === 'show') {
69+
setExpansion('expanded');
70+
}
71+
}
72+
73+
return (
74+
<ul class={stylesLegacy.history} onClick={onClick}>
75+
{history.value.slice(0, current).map((item, index) => {
76+
const isLast = index === current - 1;
77+
return <HistoryItem key={item.url + item.title} item={item} isLast={isLast} current={current} min={min} max={max} />;
78+
})}
79+
</ul>
80+
);
81+
}
82+
4883
/**
4984
* Renders a history item with relevant details such as title, time, and optional show/hide button.
5085
*

0 commit comments

Comments
 (0)