MCPcopy Create free account
hub / github.com/tiann/hapi / toggleOption

Function toggleOption

web/src/components/ToolCard/AskUserQuestionFooter.tsx:216–242  ·  view source on GitHub ↗
(qIdx: number, optIdx: number)

Source from the content-addressed store, hash-verified

214 }
215
216 const toggleOption = (qIdx: number, optIdx: number) => {
217 const q = questions[qIdx]
218 if (!q) return
219 haptic.selection()
220
221 setSelectedByQuestion((prevSelected) => {
222 const nextSelected = prevSelected.slice()
223 const cur = new Set(nextSelected[qIdx] ?? [])
224 if (q.multiSelect) {
225 if (cur.has(optIdx)) cur.delete(optIdx)
226 else cur.add(optIdx)
227 nextSelected[qIdx] = Array.from(cur).sort((a, b) => a - b)
228 return nextSelected
229 }
230
231 nextSelected[qIdx] = [optIdx]
232 return nextSelected
233 })
234
235 if (!q.multiSelect) {
236 setOtherSelectedByQuestion((prevOther) => {
237 const nextOther = prevOther.slice()
238 nextOther[qIdx] = false
239 return nextOther
240 })
241 }
242 }
243
244 const toggleOther = (qIdx: number) => {
245 const q = questions[qIdx]

Callers 1

AskUserQuestionFooterFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected