(index: number)
| 335 | }, |
| 336 | |
| 337 | deleteSession(index: number) { |
| 338 | const deletingLastSession = get().sessions.length === 1; |
| 339 | const deletedSession = get().sessions.at(index); |
| 340 | |
| 341 | if (!deletedSession) return; |
| 342 | |
| 343 | const sessions = get().sessions.slice(); |
| 344 | sessions.splice(index, 1); |
| 345 | |
| 346 | const currentIndex = get().currentSessionIndex; |
| 347 | let nextIndex = Math.min( |
| 348 | currentIndex - Number(index < currentIndex), |
| 349 | sessions.length - 1, |
| 350 | ); |
| 351 | |
| 352 | if (deletingLastSession) { |
| 353 | nextIndex = 0; |
| 354 | sessions.push(createEmptySession()); |
| 355 | } |
| 356 | |
| 357 | // for undo delete action |
| 358 | const restoreState = { |
| 359 | currentSessionIndex: get().currentSessionIndex, |
| 360 | sessions: get().sessions.slice(), |
| 361 | }; |
| 362 | |
| 363 | set(() => ({ |
| 364 | currentSessionIndex: nextIndex, |
| 365 | sessions, |
| 366 | })); |
| 367 | |
| 368 | showToast( |
| 369 | Locale.Home.DeleteToast, |
| 370 | { |
| 371 | text: Locale.Home.Revert, |
| 372 | onClick() { |
| 373 | set(() => restoreState); |
| 374 | }, |
| 375 | }, |
| 376 | 5000, |
| 377 | ); |
| 378 | }, |
| 379 | |
| 380 | currentSession() { |
| 381 | let index = get().currentSessionIndex; |
nothing calls this directly
no test coverage detected