(qIdx: number, optIdx: number)
| 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] |
no outgoing calls
no test coverage detected