MCPcopy
hub / github.com/UdaraJay/Pile / useThread

Function useThread

src/renderer/hooks/useThread.js:6–32  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4import { getPost } from './usePostHelpers';
5
6function 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
34export default useThread;

Callers 1

index.jsxFile · 0.85

Calls 3

usePilesContextFunction · 0.90
getPostFunction · 0.90
getCurrentPilePathFunction · 0.85

Tested by

no test coverage detected