(next: boolean = false)
| 226 | }, []); |
| 227 | |
| 228 | async function loadMore(next: boolean = false) { |
| 229 | if (isInfiniteScrollLoading || isScrolling) return; |
| 230 | try { |
| 231 | setInfiniteScrollLoading(true); |
| 232 | const data = await api.findTopics({ |
| 233 | channelId: currentChannel.id, |
| 234 | sentAt: new Date(topics[0].sentAt), |
| 235 | accountId: currentCommunity.id, |
| 236 | }); |
| 237 | if (data) { |
| 238 | if (next) { |
| 239 | setThreads((threads) => [...threads, ...data.threads]); |
| 240 | setTopics((topics) => [...topics, ...data.topics]); |
| 241 | } else { |
| 242 | setThreads((threads) => [...data.threads, ...threads]); |
| 243 | setTopics((topics) => [...data.topics, ...topics]); |
| 244 | } |
| 245 | } |
| 246 | setIsScrolling(true); |
| 247 | setInfiniteScrollLoading(false); |
| 248 | } catch (err) { |
| 249 | setError({ ...error }); |
| 250 | setInfiniteScrollLoading(false); |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | const debouncedGetReadStatus = useCallback(debounce(api.getReadStatus), []); |
| 255 |
nothing calls this directly
no test coverage detected