@@ -9,9 +9,10 @@ import { useTypedTranslationWith } from '../../../new-tab/app/types.js';
9
9
10
10
/**
11
11
* @import json from "../strings.json"
12
+ * @typedef {import('../../types/history.js').Range } Range
12
13
*/
13
14
14
- /** @type {Record<import('../../types/history.js'). Range, string> } */
15
+ /** @type {Record<Range, string> } */
15
16
const iconMap = {
16
17
all : 'icons/all.svg' ,
17
18
today : 'icons/today.svg' ,
@@ -23,11 +24,10 @@ const iconMap = {
23
24
friday : 'icons/day.svg' ,
24
25
saturday : 'icons/day.svg' ,
25
26
sunday : 'icons/day.svg' ,
26
- recentlyOpened : 'icons/closed.svg' ,
27
27
older : 'icons/older.svg' ,
28
28
} ;
29
29
30
- /** @type {Record<import('../../types/history.js'). Range, (t: (s: keyof json) => string) => string> } */
30
+ /** @type {Record<Range, (t: (s: keyof json) => string) => string> } */
31
31
const titleMap = {
32
32
all : ( t ) => t ( 'range_all' ) ,
33
33
today : ( t ) => t ( 'range_today' ) ,
@@ -39,33 +39,27 @@ const titleMap = {
39
39
friday : ( t ) => t ( 'range_friday' ) ,
40
40
saturday : ( t ) => t ( 'range_saturday' ) ,
41
41
sunday : ( t ) => t ( 'range_sunday' ) ,
42
- recentlyOpened : ( t ) => t ( 'range_recentlyOpened' ) ,
43
42
older : ( t ) => t ( 'range_older' ) ,
44
43
} ;
45
44
46
45
/**
47
46
* Renders a sidebar navigation component with links based on the provided ranges.
48
47
*
49
48
* @param {Object } props - The properties object.
50
- * @param {import('../../types/history.js'). Range[] } props.ranges - An array of range values used to generate navigation links.
49
+ * @param {import("@preact/signals").Signal< Range[]> } props.ranges - An array of range values used to generate navigation links.
51
50
*/
52
51
export function Sidebar ( { ranges } ) {
53
52
const { t } = useTypedTranslation ( ) ;
54
53
const search = useSearchContext ( ) ;
55
54
const current = useComputed ( ( ) => search . value . range ) ;
56
- const others = ranges . filter ( ( x ) => x === 'recentlyOpened' ) ;
57
- const main = ranges . filter ( ( x ) => x !== 'recentlyOpened' ) ;
58
55
return (
59
56
< div class = { styles . stack } >
60
57
< h1 class = { styles . pageTitle } > { t ( 'page_title' ) } </ h1 >
61
58
< nav class = { styles . nav } >
62
- { main . map ( ( range ) => {
59
+ { ranges . value . map ( ( range ) => {
63
60
return < Item range = { range } key = { range } current = { current } title = { titleMap [ range ] ( t ) } /> ;
64
61
} ) }
65
62
</ nav >
66
- { others . map ( ( range ) => {
67
- return < Item range = { range } key = { range } current = { current } title = { titleMap [ range ] ( t ) } /> ;
68
- } ) }
69
63
</ div >
70
64
) ;
71
65
}
@@ -74,16 +68,16 @@ export function Sidebar({ ranges }) {
74
68
* Renders an item component with additional properties and functionality.
75
69
*
76
70
* @param {Object } props
77
- * @param {import('../../types/history.js'). Range } props.range The range value used for filtering and identification.
71
+ * @param {Range } props.range The range value used for filtering and identification.
78
72
* @param {string } props.title The title or label of the item.
79
- * @param {import("@preact/signals").Signal<import('../../types/history.js'). Range|null> } props.current The current state object used to determine active item styling.
73
+ * @param {import("@preact/signals").Signal<Range|null> } props.current The current state object used to determine active item styling.
80
74
*/
81
75
function Item ( { range, title, current } ) {
82
76
const { t } = useTypedTranslationWith ( /** @type {json } */ ( { } ) ) ;
83
- const label = ( ( ) => {
77
+ const [ linkLabel , deleteLabel ] = ( ( ) => {
84
78
switch ( range ) {
85
79
case 'all' :
86
- return t ( 'show_history_all' ) ;
80
+ return [ t ( 'show_history_all' ) , t ( 'delete_history_all' ) ] ;
87
81
case 'today' :
88
82
case 'yesterday' :
89
83
case 'monday' :
@@ -93,22 +87,28 @@ function Item({ range, title, current }) {
93
87
case 'friday' :
94
88
case 'saturday' :
95
89
case 'sunday' :
96
- return t ( 'show_history_for' , { range } ) ;
90
+ return [ t ( 'show_history_for' , { range } ) , t ( 'delete_history_for' , { range } ) ] ;
97
91
case 'older' :
98
- return t ( 'show_history_older' ) ;
99
- case 'recentlyOpened' :
100
- return t ( 'show_history_closed' ) ;
92
+ return [ t ( 'show_history_older' ) , t ( 'delete_history_older' ) ] ;
101
93
}
102
94
} ) ( ) ;
103
95
return (
104
- < a href = "#" aria-label = { label } data-filter = { range } class = { cn ( styles . item , current . value === range && styles . active ) } >
105
- < span class = { styles . icon } >
106
- < img src = { iconMap [ range ] } />
107
- </ span >
108
- { title }
109
- < button class = { styles . delete } data-delete-range = { range } >
96
+ < div class = { styles . item } >
97
+ < a
98
+ href = "#"
99
+ aria-label = { linkLabel }
100
+ data-filter = { range }
101
+ class = { cn ( styles . link , current . value === range && styles . active ) }
102
+ tabindex = { 0 }
103
+ >
104
+ < span class = { styles . icon } >
105
+ < img src = { iconMap [ range ] } />
106
+ </ span >
107
+ { title }
108
+ </ a >
109
+ < button class = { styles . delete } data-delete-range = { range } aria-label = { deleteLabel } tabindex = { 0 } value = { range } >
110
110
< Trash />
111
111
</ button >
112
- </ a >
112
+ </ div >
113
113
) ;
114
114
}
0 commit comments