@@ -3,18 +3,11 @@ import type { Attempt } from "../schemas/attempt";
33import { Cell } from "../../ui/components/grid/cell" ;
44import { GridColumn } from "../../ui/components/grid/grid-column" ;
55import { HorizontalDivider } from "../../ui/components/grid/horizontal-divider" ;
6+ import { SymbolButton } from "../../ui/components/buttons/symbol-button" ;
67import { VerticalDivider } from "../../ui/components/grid/vertical-divider" ;
78import { cellCss } from "../../ui/css/cell-css" ;
89import { isDefined } from "remeda" ;
910
10- const sFirstColumn = cellCss ( {
11- extraPadding : "left" ,
12- } ) ;
13-
14- const sLastColumn = cellCss ( {
15- extraPadding : "right" ,
16- } ) ;
17-
1811const sValue = cellCss ( {
1912 mono : true ,
2013} ) ;
@@ -32,17 +25,21 @@ interface AttemptsTableProps {
3225 showTime ?: boolean ;
3326 showTrack ?: boolean ;
3427 limit ?: number ;
28+ onDelete ?: ( attempt : Attempt ) => void ;
3529}
3630
3731export const AttemptsTable : Component < AttemptsTableProps > = ( props ) => {
38- const GRID_COLUMNS = 16 ;
32+ const GRID_COLUMNS = 18 ;
3933 const GRID_SPLITS_COLUMNS = 7 ;
4034 const GRID_RESULT_COLUMNS = 3 ;
4135 const GRID_SEPARATION_THICKNESS = 2 ;
4236
4337 const showTime = createMemo ( ( ) => props . showTime ?? true ) ;
4438 const showTrack = createMemo ( ( ) => props . showTrack ?? true ) ;
45- const gridColumns = createMemo ( ( ) => GRID_COLUMNS - ( Number ( ! showTime ( ) ) + Number ( ! showTrack ( ) ) ) ) ;
39+ const showAction = createMemo ( ( ) => Boolean ( props . onDelete ) ) ;
40+ const gridColumns = createMemo (
41+ ( ) => GRID_COLUMNS - ( Number ( ! showTime ( ) ) + Number ( ! showTrack ( ) ) + 2 * Number ( ! showAction ( ) ) ) ,
42+ ) ;
4643
4744 const attempts = createMemo ( ( ) => props . attempts . slice ( 0 , props . limit ) ) ;
4845
@@ -54,7 +51,7 @@ export const AttemptsTable: Component<AttemptsTableProps> = (props) => {
5451 { ( attempt , aIndex ) => (
5552 < >
5653 < Show when = { aIndex ( ) % 7 === 0 } >
57- < Cell text = "Date" css = { [ sTitle , sInfo , sFirstColumn ] } />
54+ < Cell text = "Date" css = { [ sTitle , sInfo ] } />
5855 < Show when = { showTime ( ) } >
5956 < Cell text = "Time" css = { [ sTitle , sInfo ] } />
6057 </ Show >
@@ -73,11 +70,15 @@ export const AttemptsTable: Component<AttemptsTableProps> = (props) => {
7370 < VerticalDivider />
7471 < Cell text = "⏱️" css = { [ sTitle ] } />
7572 < VerticalDivider />
76- < Cell text = "️🟡" css = { [ sTitle , sLastColumn ] } />
73+ < Cell text = "️🟡" css = { [ sTitle ] } />
74+ < Show when = { showAction ( ) } >
75+ < VerticalDivider />
76+ < Cell text = "⚙️" />
77+ </ Show >
7778 < HorizontalDivider column = { gridColumns ( ) } thicknessFactor = { GRID_SEPARATION_THICKNESS } />
7879 </ Show >
7980
80- < Cell row = { attempt . rowSplits } text = { attempt . date } css = { [ sFirstColumn , sInfo ] } />
81+ < Cell row = { attempt . rowSplits } text = { attempt . date } css = { [ sInfo ] } />
8182 < Show when = { showTime ( ) } >
8283 < Cell row = { attempt . rowSplits } text = { attempt . datetime } css = { [ sInfo ] } />
8384 </ Show >
@@ -119,14 +120,20 @@ export const AttemptsTable: Component<AttemptsTableProps> = (props) => {
119120 < VerticalDivider row = { attempt . rowSplits } />
120121 < Switch >
121122 < Match when = { ! isDefined ( attempt . time ) && ! isDefined ( attempt . coins ) } >
122- < Cell column = { GRID_RESULT_COLUMNS } row = { attempt . rowSplits } css = { [ sLastColumn ] } />
123+ < Cell column = { GRID_RESULT_COLUMNS } row = { attempt . rowSplits } />
123124 </ Match >
124125 < Match when >
125126 < Cell row = { attempt . rowSplits } text = { attempt . time } css = { [ sValue ] } />
126127 < VerticalDivider row = { attempt . rowSplits } />
127- < Cell row = { attempt . rowSplits } text = { attempt . coins } css = { [ sValue , sLastColumn ] } />
128+ < Cell row = { attempt . rowSplits } text = { attempt . coins } css = { [ sValue ] } />
128129 </ Match >
129130 </ Switch >
131+ < Show when = { showAction ( ) } >
132+ < VerticalDivider row = { attempt . rowSplits } />
133+ < Cell row = { attempt . rowSplits } >
134+ < SymbolButton symbol = "🗑" onClick = { ( ) => props . onDelete ?.( attempt ) } > </ SymbolButton >
135+ </ Cell >
136+ </ Show >
130137 < HorizontalDivider column = { GRID_SPLITS_COLUMNS } />
131138 </ Show >
132139 </ >
@@ -136,7 +143,13 @@ export const AttemptsTable: Component<AttemptsTableProps> = (props) => {
136143 < Match when = { true } >
137144 < Cell column = { GRID_SPLITS_COLUMNS } row = { attempt . rowSplits } text = "Not even one split 😭" />
138145 < VerticalDivider row = { attempt . rowSplits } />
139- < Cell row = { attempt . rowSplits } column = { GRID_RESULT_COLUMNS } css = { [ sLastColumn ] } />
146+ < Cell row = { attempt . rowSplits } column = { GRID_RESULT_COLUMNS } css = { [ ] } />
147+ < Show when = { showAction ( ) } >
148+ < VerticalDivider row = { attempt . rowSplits } />
149+ < Cell row = { attempt . rowSplits } >
150+ < SymbolButton symbol = "🗑" onClick = { ( ) => props . onDelete ?.( attempt ) } > </ SymbolButton >
151+ </ Cell >
152+ </ Show >
140153 </ Match >
141154 </ Switch >
142155 < HorizontalDivider column = { gridColumns ( ) } thicknessFactor = { GRID_SEPARATION_THICKNESS } />
0 commit comments