(state: QuestionBodyState, request: QuestionRequest)
| 256 | } |
| 257 | |
| 258 | export function questionSave(state: QuestionBodyState, request: QuestionRequest): QuestionStep { |
| 259 | const info = questionInfo(request, state) |
| 260 | if (!info) { |
| 261 | return { state } |
| 262 | } |
| 263 | |
| 264 | const value = questionInput(state).trim() |
| 265 | const prev = state.custom[state.tab] |
| 266 | if (!value) { |
| 267 | if (!prev) { |
| 268 | return { |
| 269 | state: questionSetEditing(state, false), |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | const next = questionStoreCustom(state, state.tab, "") |
| 274 | return { |
| 275 | state: questionSetEditing( |
| 276 | storeAnswers( |
| 277 | next, |
| 278 | state.tab, |
| 279 | (state.answers[state.tab] ?? []).filter((item) => item !== prev), |
| 280 | ), |
| 281 | false, |
| 282 | ), |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | if (info.multiple) { |
| 287 | const answers = [...(state.answers[state.tab] ?? [])] |
| 288 | if (prev) { |
| 289 | const idx = answers.indexOf(prev) |
| 290 | if (idx !== -1) { |
| 291 | answers.splice(idx, 1) |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | if (!answers.includes(value)) { |
| 296 | answers.push(value) |
| 297 | } |
| 298 | |
| 299 | const next = questionStoreCustom(state, state.tab, value) |
| 300 | return { |
| 301 | state: questionSetEditing(storeAnswers(next, state.tab, answers), false), |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | return questionPick(state, request, value, true) |
| 306 | } |
| 307 | |
| 308 | export function questionSubmit(request: QuestionRequest, state: QuestionBodyState): QuestionReply { |
| 309 | return { |
no test coverage detected