()
| 424 | } |
| 425 | |
| 426 | static async requeryChannels() { |
| 427 | try { |
| 428 | const [response, ids] = await Promise.all([ |
| 429 | request( |
| 430 | `${host}/api/channels/channels/?${API.lastQueryParams.toString()}` |
| 431 | ), |
| 432 | API.getAllChannelIds(API.lastQueryParams), |
| 433 | ]); |
| 434 | |
| 435 | useChannelsTableStore |
| 436 | .getState() |
| 437 | .queryChannels(response, API.lastQueryParams); |
| 438 | useChannelsTableStore.getState().setAllQueryIds(ids); |
| 439 | |
| 440 | return response; |
| 441 | } catch (e) { |
| 442 | // Handle invalid page error by resetting to page 1 and retrying |
| 443 | if (e.body?.detail === 'Invalid page.') { |
| 444 | const currentPagination = useChannelsTableStore.getState().pagination; |
| 445 | |
| 446 | // Only retry if we're not already on page 1 |
| 447 | if (currentPagination.pageIndex > 0) { |
| 448 | // Reset to page 1 |
| 449 | useChannelsTableStore.getState().setPagination({ |
| 450 | ...currentPagination, |
| 451 | pageIndex: 0, |
| 452 | }); |
| 453 | |
| 454 | // Update params to page 1 and retry |
| 455 | const newParams = new URLSearchParams(API.lastQueryParams); |
| 456 | newParams.set('page', '1'); |
| 457 | API.lastQueryParams = newParams; |
| 458 | |
| 459 | const [response, ids] = await Promise.all([ |
| 460 | request(`${host}/api/channels/channels/?${newParams.toString()}`), |
| 461 | API.getAllChannelIds(newParams), |
| 462 | ]); |
| 463 | |
| 464 | useChannelsTableStore.getState().queryChannels(response, newParams); |
| 465 | useChannelsTableStore.getState().setAllQueryIds(ids); |
| 466 | |
| 467 | return response; |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | errorNotification('Failed to fetch channels', e); |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | static async getAllChannelIds(params = new URLSearchParams()) { |
| 476 | try { |
no test coverage detected