@@ -6,14 +6,15 @@ import { useTypedTranslation } from '../types.js';
66import { Trash } from '../icons/Trash.js' ;
77import { useTypedTranslationWith } from '../../../new-tab/app/types.js' ;
88import { useQueryContext , useQueryDispatch } from '../global/Providers/QueryProvider.js' ;
9- import { useHistoryServiceDispatch , useResultsData } from '../global/Providers/HistoryServiceProvider.js' ;
9+ import { useHistoryServiceDispatch } from '../global/Providers/HistoryServiceProvider.js' ;
1010
1111/**
1212 * @import json from "../strings.json"
1313 * @typedef {import('../../types/history.js').Range } Range
14+ * @typedef {import('../../types/history.js').RangeId } RangeId
1415 */
1516
16- /** @type {Record<Range , string> } */
17+ /** @type {Record<RangeId , string> } */
1718const iconMap = {
1819 all : 'icons/all.svg' ,
1920 today : 'icons/today.svg' ,
@@ -28,7 +29,7 @@ const iconMap = {
2829 older : 'icons/older.svg' ,
2930} ;
3031
31- /** @type {Record<Range , (t: (s: keyof json) => string) => string> } */
32+ /** @type {Record<RangeId , (t: (s: keyof json) => string) => string> } */
3233const titleMap = {
3334 all : ( t ) => t ( 'range_all' ) ,
3435 today : ( t ) => t ( 'range_today' ) ,
@@ -53,13 +54,11 @@ export function Sidebar({ ranges }) {
5354 const { t } = useTypedTranslation ( ) ;
5455 const search = useQueryContext ( ) ;
5556 const current = useComputed ( ( ) => search . value . range ) ;
56- const results = useResultsData ( ) ;
57- const count = useComputed ( ( ) => results . value . items . length ) ;
5857 const dispatch = useQueryDispatch ( ) ;
5958 const historyServiceDispatch = useHistoryServiceDispatch ( ) ;
6059
6160 /**
62- * @param {Range } range
61+ * @param {RangeId } range
6362 */
6463 function onClick ( range ) {
6564 if ( range === 'all' ) {
@@ -69,7 +68,7 @@ export function Sidebar({ ranges }) {
6968 }
7069 }
7170 /**
72- * @param {Range } range
71+ * @param {RangeId } range
7372 */
7473 function onDelete ( range ) {
7574 historyServiceDispatch ( { kind : 'delete-range' , value : range } ) ;
@@ -80,7 +79,18 @@ export function Sidebar({ ranges }) {
8079 < h1 class = { styles . pageTitle } > { t ( 'page_title' ) } </ h1 >
8180 < nav class = { styles . nav } >
8281 { ranges . value . map ( ( range ) => {
83- return < Item onClick = { onClick } onDelete = { onDelete } current = { current } range = { range } ranges = { ranges } count = { count } /> ;
82+ console . log ( range . id , range . count ) ;
83+ return (
84+ < Item
85+ key = { range . id }
86+ onClick = { onClick }
87+ onDelete = { onDelete }
88+ current = { current }
89+ range = { range . id }
90+ count = { range . count }
91+ ranges = { ranges }
92+ />
93+ ) ;
8494 } ) }
8595 </ nav >
8696 </ div >
@@ -91,12 +101,12 @@ export function Sidebar({ ranges }) {
91101 * A component that renders a list item with optional delete actions and a link.
92102 *
93103 * @param {Object } props
94- * @param {import('@preact/signals').ReadonlySignal<Range |null> } props.current The current selection with a value property.
95- * @param {Range } props.range The range represented by this item.
96- * @param {(range: Range ) => void } props.onClick Callback function triggered when the range is clicked.
97- * @param {(range: Range ) => void } props.onDelete Callback function triggered when the delete action is clicked.
104+ * @param {import('@preact/signals').ReadonlySignal<RangeId |null> } props.current The current selection with a value property.
105+ * @param {RangeId } props.range The range represented by this item.
106+ * @param {(range: RangeId ) => void } props.onClick Callback function triggered when the range is clicked.
107+ * @param {(range: RangeId ) => void } props.onDelete Callback function triggered when the delete action is clicked.
98108 * @param {import("@preact/signals").Signal<Range[]> } props.ranges
99- * @param {import('@preact/signals').ReadonlySignal< number> } props.count The count value associated with the ranges.
109+ * @param {number } props.count The count value associated with the ranges.
100110 */
101111function Item ( { current, range, onClick, onDelete, ranges, count } ) {
102112 const { t } = useTypedTranslation ( ) ;
@@ -124,46 +134,27 @@ function Item({ current, range, onClick, onDelete, ranges, count }) {
124134 </ span >
125135 { titleMap [ range ] ( t ) }
126136 </ button >
127- { range === 'all' && < DeleteAllButton onClick = { onDelete } ariaLabel = { buttonLabel } range = { range } ranges = { ranges } count = { count } /> }
128- { range !== 'all' && < DeleteButton onClick = { ( ) => onDelete ( range ) } label = { buttonLabel } range = { range } /> }
137+ < DeleteAllButton onClick = { onDelete } ariaLabel = { buttonLabel } range = { range } ranges = { ranges } count = { count } />
129138 </ div >
130139 ) ;
131140}
132141
133- /**
134- * @param {Object } props
135- * @param {Range } props.range The range value used for filtering and identification.
136- * @param {string } props.label The title or label of the item.
137- * @param {(range: MouseEvent)=>void } props.onClick
138- */
139- function DeleteButton ( { range, onClick, label } ) {
140- return (
141- < button class = { styles . delete } onClick = { onClick } aria-label = { label } tabindex = { 0 } value = { range } >
142- < Trash />
143- </ button >
144- ) ;
145- }
146-
147142/**
148143 * The 'Delete' button for the 'all' range. This is a separate component because it contains
149144 * logic that's only relevant to this row item.
150145 *
151146 * @param {Object } props - The properties passed to the component.
152- * @param {Range } props.range - The range value used for filtering and identification.
147+ * @param {RangeId } props.range - The range value used for filtering and identification.
153148 * @param {import('@preact/signals').Signal<Range[]> } props.ranges - A signal containing an array of range values used for navigation.
154149 * @param {string } props.ariaLabel - The accessible label for the delete button.
155- * @param {(evt: Range ) => void } props.onClick - The callback function triggered on button click.
156- * @param {import('@preact/signals').Signal< number> } props.count - A signal representing the count of items in the range.
150+ * @param {(evt: RangeId ) => void } props.onClick - The callback function triggered on button click.
151+ * @param {number } props.count - A signal representing the count of items in the range.
157152 */
158153function DeleteAllButton ( { range, ranges, onClick, ariaLabel, count } ) {
159154 const { t } = useTypedTranslationWith ( /** @type {json } */ ( { } ) ) ;
160155
161- const ariaDisabled = useComputed ( ( ) => {
162- return count . value === 0 && ranges . value . length === 1 ? 'true' : 'false' ;
163- } ) ;
164- const buttonTitle = useComputed ( ( ) => {
165- return count . value === 0 && ranges . value . length === 1 ? t ( 'delete_none' ) : '' ;
166- } ) ;
156+ const ariaDisabled = count === 0 ? 'true' : 'false' ;
157+ const buttonTitle = count === 0 ? t ( 'delete_none' ) : '' ;
167158
168159 return (
169160 < button
@@ -186,7 +177,7 @@ function DeleteAllButton({ range, ranges, onClick, ariaLabel, count }) {
186177}
187178
188179/**
189- * @param {Range } range
180+ * @param {RangeId } range
190181 * @return {{linkLabel: string, buttonLabel: string} }
191182 */
192183function labels ( range , t ) {
0 commit comments