@@ -10,7 +10,7 @@ import {
10
10
SegmentType
11
11
} from './segments'
12
12
import {
13
- EditSegment ,
13
+ EditSegmentIcon ,
14
14
useSegmentPrefetch ,
15
15
useSegmentsListQuery
16
16
} from './segments-dropdown'
@@ -22,16 +22,16 @@ import { rootRoute } from '../router'
22
22
import { FilterPillsList } from '../nav-menu/filter-pills-list'
23
23
import classNames from 'classnames'
24
24
import {
25
- EyeSlashIcon ,
26
- EyeIcon ,
27
25
XMarkIcon ,
28
- CheckIcon ,
29
26
ChevronUpIcon ,
30
- ChevronDownIcon
31
- } from '@heroicons/react/24/solid'
27
+ ChevronDownIcon ,
28
+ TrashIcon ,
29
+ CheckIcon
30
+ } from '@heroicons/react/24/outline'
32
31
import { FilterPill } from '../nav-menu/filter-pill'
33
32
import { Filter } from '../query'
34
33
import { SegmentAuthorship } from './segment-authorship'
34
+ import { SegmentExpandedLocationState } from './segment-expanded-context'
35
35
36
36
const buttonClass =
37
37
'h-12 text-md font-medium py-2 px-3 rounded border dark:border-gray-100 dark:text-gray-100'
@@ -282,38 +282,9 @@ export const UpdateSegmentModal = ({
282
282
)
283
283
}
284
284
285
- const ExpandSegmentButton = ( {
286
- className,
287
- onClick,
288
- onMouseEnter,
289
- expanded
290
- } : {
291
- className ?: string
292
- onClick : ( ) => Promise < void >
293
- onMouseEnter ?: ( ) => Promise < void >
294
- expanded : boolean
295
- } ) => {
296
- return (
297
- < button
298
- className = { classNames (
299
- 'flex w-5 h-5 items-center justify-center fill-current hover:fill-indigo-600 ' ,
300
- className
301
- ) }
302
- onClick = { onClick }
303
- onMouseEnter = { onMouseEnter }
304
- >
305
- { expanded ? (
306
- < ChevronUpIcon className = "block w-4 h-4" />
307
- ) : (
308
- < ChevronDownIcon className = "block w-4 h-4" />
309
- ) }
310
- </ button >
311
- )
312
- }
313
285
const SegmentRow = ( {
314
286
id,
315
287
name,
316
- // type,
317
288
toggleSelected,
318
289
selected
319
290
} : SavedSegment & { toggleSelected : ( ) => void ; selected : boolean } ) => {
@@ -322,44 +293,53 @@ const SegmentRow = ({
322
293
id
323
294
} )
324
295
const [ segmentDataVisible , setSegmentDataVisible ] = useState ( false )
296
+ const toggleSegmentDataVisible = useCallback ( async ( ) => {
297
+ setSegmentDataVisible ( ( currentVisible ) => {
298
+ if ( currentVisible ) {
299
+ return false
300
+ }
301
+ fetchSegment ( )
302
+ return true
303
+ } )
304
+ } , [ fetchSegment ] )
325
305
return (
326
306
< div
327
- className = "grid grid-cols-[1fr_20px_20px ] shadow rounded bg-white dark:bg-gray-900 text-gray-700 dark:text-gray-300 text-sm py-3 px-3 transition-all"
307
+ className = "grid grid-cols-[1fr_20px ] shadow rounded bg-white dark:bg-gray-900 text-gray-700 dark:text-gray-300 text-sm py-3 px-3 transition-all"
328
308
onMouseEnter = { prefetchSegment }
329
309
>
330
- { /* <button className="block" onClick={toggleSelected}>
331
- {selected && <CheckIcon className="block w-4 h-4" />}
332
- </button> */ }
333
- < div
310
+ < button
311
+ className = "group flex justify-between text-left"
312
+ onClick = { toggleSegmentDataVisible }
313
+ >
314
+ < div
315
+ className = { classNames (
316
+ 'cursor-pointer break-all' ,
317
+ selected && 'font-extrabold'
318
+ ) }
319
+ >
320
+ { name }
321
+ </ div >
322
+ < div className = "flex w-5 h-5 items-center" >
323
+ { segmentDataVisible ? (
324
+ < ChevronUpIcon className = "block w-4 h-4" />
325
+ ) : (
326
+ < ChevronDownIcon className = "block w-4 h-4 opacity-0 group-hover:opacity-100 transition-opacity" />
327
+ ) }
328
+ </ div >
329
+ </ button >
330
+
331
+ < button
332
+ className = "flex items-center justify-center w-5 h-5 group"
333
+ title = { selected ? 'Unselect segment' : 'Select segment' }
334
334
onClick = { toggleSelected }
335
- className = { classNames (
336
- 'cursor-pointer break-all' ,
337
- selected && 'font-extrabold'
338
- ) }
339
335
>
340
- { name }
341
- { /* <span>{' · '}</span> */ }
342
- { /* <span className="text-[10px] leading">
343
- {{ personal: 'personal', site: 'site' }[type]}
344
- </span> */ }
345
- </ div >
346
- < ExpandSegmentButton
347
- className = ""
348
- expanded = { segmentDataVisible }
349
- onClick = {
350
- segmentDataVisible
351
- ? async ( ) => setSegmentDataVisible ( false )
352
- : async ( ) => {
353
- setSegmentDataVisible ( true )
354
- fetchSegment ( )
355
- }
356
- }
357
- />
358
- < EditSegment
359
- onClick = { async ( ) => {
360
- expandSegment ( data ?? ( await fetchSegment ( ) ) )
361
- } }
362
- />
336
+ < CheckIcon
337
+ className = { classNames (
338
+ 'w-4 h-4 block opacity-0 transition-opacity' ,
339
+ selected ? 'opacity-100' : 'opacity-30 group-hover:opacity-100'
340
+ ) }
341
+ />
342
+ </ button >
363
343
364
344
{ segmentDataVisible && (
365
345
< div className = "col-span-full mt-3" >
@@ -376,7 +356,35 @@ const SegmentRow = ({
376
356
) : (
377
357
'loading'
378
358
) }
379
- < SegmentAuthorship { ...data } className = "mt-3 text-xs" />
359
+ { ! ! data && < SegmentAuthorship { ...data } className = "mt-3 text-xs" /> }
360
+ < div className = "col-span-full mt-3 flex gap-x-4 gap-y-2 flex-wrap" >
361
+ < button
362
+ className = "flex gap-x-1 text-sm items-center hover:text-indigo-600 fill-current hover:fill-indigo-600"
363
+ onClick = { async ( ) => {
364
+ expandSegment ( data ?? ( await fetchSegment ( ) ) )
365
+ } }
366
+ >
367
+ < EditSegmentIcon className = "block h-4 w-4" />
368
+ Edit segment
369
+ </ button >
370
+ < AppNavigationLink
371
+ className = "flex gap-x-1 text-sm items-center hover:text-indigo-600 fill-current hover:fill-indigo-600"
372
+ path = { rootRoute . path }
373
+ search = { ( s ) => s }
374
+ state = {
375
+ {
376
+ expandedSegment : data ,
377
+ modal : 'delete'
378
+ } as SegmentExpandedLocationState
379
+ }
380
+ // onClick={async () => {
381
+ // expandSegment(data ?? (await fetchSegment()))
382
+ // }}
383
+ >
384
+ < TrashIcon className = "block h-4 w-4" />
385
+ Delete segment
386
+ </ AppNavigationLink >
387
+ </ div >
380
388
</ div >
381
389
) }
382
390
</ div >
@@ -473,46 +481,22 @@ export const AllSegmentsModal = () => {
473
481
/>
474
482
) ) }
475
483
{ segments ?. length && sliceEnd < segments . length && (
476
- < button onClick = { showMore } className = "button self-center " >
484
+ < button onClick = { showMore } className = "button self-center mt-1 " >
477
485
Show more
478
486
</ button >
479
487
) }
480
488
</ >
481
489
) ) }
482
490
{ ! personalSegments ?. length && ! siteSegments ?. length && (
483
- < span >
484
- No segments found.{ ' ' }
485
- { /* {!!search?.trim().length && (
486
- <button
487
- className="inline cursor-pointer hover:text-indigo-700 dark:hover:text-indigo-500"
488
- onClick={() => setSearch('')}
489
- >
490
- {'Clear search to see all.'}
491
- </button>
492
- )} */ }
493
- </ span >
491
+ < span > No segments found.</ span >
494
492
) }
495
493
</ div >
496
- { /* <div className="my-4 border-b border-gray-300"></div> */ }
497
494
498
495
< div className = "mt-4" >
499
496
< h2 className = "text-l font-bold dark:text-gray-100" > Selected filter</ h2 >
500
497
501
498
{ ! ! data && ! ! proposedSegmentFilter && (
502
499
< div className = "mt-2 justify-self-start" >
503
- { /* <FilterPillsList
504
- className="flex-wrap"
505
- direction="horizontal"
506
- pills={proposedSegmentFilter[2].map((c) => ({
507
- children: styledFilterText(labelsForProposedSegmentFilter, [
508
- proposedSegmentFilter[0],
509
- proposedSegmentFilter[1],
510
- [c]
511
- ]),
512
- plainText: 'hi',
513
- interactive: false
514
- }))}
515
- /> */ }
516
500
< FilterPill
517
501
interactive = { false }
518
502
plainText = { plainFilterText (
0 commit comments