@@ -91,46 +91,41 @@ const Shortcuts: React.FC = () => {
91
91
} , [ ] ) ;
92
92
93
93
const shortcutOptions = useMemo < [ string , ShortcutsItem | ShortcutsItem [ ] ] [ ] > ( ( ) => {
94
- let options ;
95
- if ( configs ?. shortcuts && configs ? .shortcuts ) {
96
- const formatConfig = Object . keys ( configs . shortcuts ) . map ( item => {
94
+ const options : [ string , ShortcutsItem | ShortcutsItem [ ] ] [ ] = [ ] ;
95
+ if ( configs && configs . shortcuts ) {
96
+ Object . keys ( configs . shortcuts ) . forEach ( item => {
97
97
if ( Object . keys ( DEFAULT_SHORTCUTS ) . includes ( item ) ) {
98
- return [ item , DEFAULT_SHORTCUTS [ item ] ] ;
99
- } else {
100
- // using | makes this fail in typecheck as [string] is no longer recognised?
101
- if ( configs . shortcuts && configs ?. shortcuts [ item ] ) {
102
- const customConfig = configs ?. shortcuts [ item ] ;
103
- const text = customConfig ?. text ;
104
- const start = dayjs ( customConfig ?. period ?. start ) ;
105
- const end = dayjs ( customConfig ?. period ?. end ) ;
106
- if (
107
- text &&
108
- start . isValid ( ) &&
109
- end . isValid ( ) &&
110
- ( start . isBefore ( end ) || start . isSame ( end ) )
111
- ) {
112
- return [
113
- item ,
114
- {
115
- text,
116
- period : {
117
- start : start . format ( DATE_FORMAT ) ,
118
- end : end . format ( DATE_FORMAT )
119
- }
120
- }
121
- ] ;
122
- } else {
123
- return undefined ;
124
- }
125
- }
126
- return undefined ;
98
+ options . push ( [ item , DEFAULT_SHORTCUTS [ item ] ] ) ;
127
99
}
128
100
} ) ;
129
- options = formatConfig ?. filter ( item => ! ! item ) ;
101
+ if ( configs . shortcuts . custom && configs . shortcuts . custom . length > 0 ) {
102
+ configs . shortcuts . custom . forEach ( customConfig => {
103
+ const text = customConfig . text ;
104
+ const start = dayjs ( customConfig . period . start ) ;
105
+ const end = dayjs ( customConfig . period . end ) ;
106
+ if (
107
+ text &&
108
+ start . isValid ( ) &&
109
+ end . isValid ( ) &&
110
+ ( start . isBefore ( end ) || start . isSame ( end ) )
111
+ ) {
112
+ options . push ( [
113
+ text ,
114
+ {
115
+ text,
116
+ period : {
117
+ start : start . format ( DATE_FORMAT ) ,
118
+ end : end . format ( DATE_FORMAT )
119
+ }
120
+ }
121
+ ] ) ;
122
+ }
123
+ } ) ;
124
+ }
130
125
} else {
131
- options = Object . entries ( DEFAULT_SHORTCUTS ) ;
126
+ return Object . entries ( DEFAULT_SHORTCUTS ) ;
132
127
}
133
- return options as [ string , ShortcutsItem | ShortcutsItem [ ] ] [ ] ;
128
+ return options ;
134
129
} , [ configs ] ) ;
135
130
136
131
const printItemText = useCallback ( ( item : ShortcutsItem ) => {
@@ -140,7 +135,7 @@ const Shortcuts: React.FC = () => {
140
135
return shortcutOptions ?. length ? (
141
136
< div className = "md:border-b mb-3 lg:mb-0 lg:border-r lg:border-b-0 border-gray-300 dark:border-gray-700 pr-1" >
142
137
< ul className = "w-full tracking-wide flex flex-wrap lg:flex-col pb-1 lg:pb-0" >
143
- { shortcutOptions ? .map ( ( [ key , item ] , index : number ) =>
138
+ { shortcutOptions . map ( ( [ key , item ] , index : number ) =>
144
139
Array . isArray ( item ) ? (
145
140
item . map ( ( item , index ) => (
146
141
< ItemTemplate key = { index } item = { item } >
0 commit comments