1
1
'use client' ;
2
2
import React from 'react' ;
3
- import { BoardDetails } from '@/app/lib/types' ;
4
- import { HOLD_STATE_MAP , LitUpHoldsMap } from '../board-renderer/types' ;
3
+ import { BoardDetails , BoardName , HoldCode , HoldFilterKey , HoldState } from '@/app/lib/types' ;
4
+ import { HOLD_STATE_MAP , LitupHold , LitUpHoldsMap } from '../board-renderer/types' ;
5
5
import BoardRenderer from '../board-renderer/board-renderer' ;
6
6
import { useUISearchParams } from '@/app/components/queue-control/ui-searchparams-provider' ;
7
7
import { Select } from 'antd' ;
8
8
9
- export type HoldCode = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 42 | 43 | 44 | 45 | 12 | 13 | 14 | 15 ;
10
- export type BoardName = 'tension' | 'kilter' ;
11
- export type HoldState = 'STARTING' | 'HAND' | 'FOOT' | 'FINISH' | 'OFF' | 'ANY' | 'NOT' ;
12
-
13
9
interface ClimbHoldSearchFormProps {
14
10
boardDetails : BoardDetails ;
15
11
}
@@ -31,31 +27,32 @@ const ClimbHoldSearchForm: React.FC<ClimbHoldSearchFormProps> = ({ boardDetails
31
27
32
28
const handleHoldClick = ( holdId : number ) => {
33
29
const stateCode = getStateCode ( selectedState , boardDetails . board_name as BoardName ) ;
34
- const updates : Record < string , any > = { } ;
35
- const holdKey = `hold_${ holdId } ` ;
36
-
30
+ const updates : Record < string , HoldState | null > = { } ;
31
+ const holdKey : HoldFilterKey = `hold_${ holdId } ` ;
32
+ let displayInfo : LitupHold | null = null ;
37
33
// Handle ANY state (remove filter)
38
34
if ( selectedState === 'ANY' ) {
39
35
updates [ holdKey ] = 'ANY' ;
40
36
}
41
37
// Handle NOT state
42
38
else if ( selectedState === 'NOT' ) {
43
39
updates [ holdKey ] = 'NOT' ;
44
- }
45
- // Handle other states
46
- else {
47
- //@ts -expect-error fix later
40
+ } else {
48
41
const currentValue = uiSearchParams [ holdKey ] ;
49
42
if ( currentValue === stateCode ?. toString ( ) ) {
50
- updates [ holdKey ] = undefined ;
51
- } else {
52
- updates [ holdKey ] = stateCode ;
43
+ updates [ holdKey ] = null ;
44
+ } else if ( stateCode !== null ) {
45
+ const stateInfo = HOLD_STATE_MAP [ boardDetails . board_name ] [ stateCode ] ;
46
+ const holdState : HoldState = stateInfo . name ;
47
+ updates [ holdKey ] = holdState ;
53
48
}
54
49
}
55
-
50
+
56
51
// Handle mirrored hold
57
52
const hold = boardDetails . holdsData . find ( ( h ) => h . id === holdId ) ;
58
53
if ( hold ?. mirroredHoldId ) {
54
+ //TODO: When on a board with mirrored holds, we should search an OR for the
55
+ // two possible hold ids
59
56
const mirrorKey = `hold_${ hold . mirroredHoldId } ` ;
60
57
updates [ mirrorKey ] = updates [ holdKey ] ;
61
58
}
@@ -68,42 +65,45 @@ const ClimbHoldSearchForm: React.FC<ClimbHoldSearchFormProps> = ({ boardDetails
68
65
delete newSelectedHolds [ hold . mirroredHoldId ] ;
69
66
}
70
67
} else {
71
- let displayInfo ;
72
68
if ( selectedState === 'NOT' ) {
73
69
displayInfo = {
74
70
state : 'NOT' ,
75
71
color : '#FF0000' , // Red color for NOT state
72
+ displayColor : '#FF0000' , // Red color for NOT state
76
73
} ;
77
74
} else if ( selectedState === 'ANY' ) {
78
75
displayInfo = {
79
76
state : 'ANY' ,
80
- color : '#b76e79' ,
77
+ color : '#00CCCC' ,
78
+ displayColor : '#00CCCC' ,
81
79
} ;
82
80
} else if ( stateCode !== null ) {
81
+ // This branch is needed for when adding search by foot/hand/etc
83
82
const stateInfo = HOLD_STATE_MAP [ boardDetails . board_name as BoardName ] [ stateCode ] ;
84
83
displayInfo = {
85
84
state : stateInfo . name ,
86
- color : stateInfo . displayColor || stateInfo . color ,
85
+ color : stateInfo . color ,
86
+ displayColor : stateInfo . displayColor || stateInfo . color ,
87
87
} ;
88
88
}
89
+
89
90
90
91
if ( displayInfo ) {
91
- //@ts -expect-error cbf
92
- newSelectedHolds [ holdId ] = displayInfo ;
92
+ if ( ! newSelectedHolds [ holdId ] || newSelectedHolds [ holdId ] . state !== displayInfo . state ) {
93
+ newSelectedHolds [ holdId ] = displayInfo ;
94
+ } else {
95
+ delete newSelectedHolds [ holdId ] ;
96
+ }
93
97
}
94
98
}
95
99
96
100
updateFilters ( {
97
- //@ts -expect-error will fix later
98
101
holdsFilter : newSelectedHolds ,
99
102
} ) ;
100
103
} ;
101
104
102
105
const clearAllHolds = ( ) => {
103
- const updates : Record < string , undefined > = { } ;
104
-
105
106
updateFilters ( {
106
- //@ts -expect-error
107
107
holdsFilter : { } ,
108
108
} ) ;
109
109
} ;
0 commit comments