()
| 4 | import { getPost } from './usePostHelpers'; |
| 5 | |
| 6 | function useThread() { |
| 7 | const { getCurrentPilePath } = usePilesContext(); |
| 8 | |
| 9 | const getThread = useCallback( |
| 10 | async (parentPostPath) => { |
| 11 | if (!parentPostPath) return; |
| 12 | let _thread = []; |
| 13 | const fullPath = getCurrentPilePath(parentPostPath); |
| 14 | const freshPost = await getPost(fullPath); |
| 15 | const replies = freshPost?.data?.replies || []; |
| 16 | _thread.push(freshPost); |
| 17 | |
| 18 | for (const replyPath of replies) { |
| 19 | const path = getCurrentPilePath(replyPath); |
| 20 | const reply = await getPost(path); |
| 21 | _thread.push(reply); |
| 22 | } |
| 23 | |
| 24 | return _thread; |
| 25 | }, |
| 26 | [getCurrentPilePath] |
| 27 | ); |
| 28 | |
| 29 | return { |
| 30 | getThread, |
| 31 | }; |
| 32 | } |
| 33 | |
| 34 | export default useThread; |
no test coverage detected