MCPcopy Create free account
hub / github.com/code100x/daily-code / fetchData

Function fetchData

apps/web/components/admin/CompleteTrackCard.tsx:48–80  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

46
47 useEffect(() => {
48 const fetchData = async () => {
49 try {
50 const response = await fetch(`/api/AddTracks`, {
51 method: "POST",
52 headers: {
53 "Content-Type": "application/json",
54 },
55 body: JSON.stringify({ notionId }),
56 });
57 if (response.ok) {
58 const data: { notionDocId: string; title: string }[] = await response.json();
59
60 const dbData: { problem: Prisma.ProblemCreateManyInput; sortingOrder: number }[] = [];
61
62 for (let i = 0; i < data.length; i++) {
63 let problem = {
64 id: `${TrackData.trackTitle.replace(/[^a-zA-Z0-9]/g, "-")}-${i + 1}`,
65 notionDocId: data[i]?.notionDocId!,
66 title: data[i]?.title!,
67 description: data[i]?.title!,
68 type: ProblemType.Blog,
69 };
70 dbData.push({ problem, sortingOrder: data.length - i });
71 }
72
73 setProblems(dbData);
74 } else {
75 throw new Error("Failed to fetch data");
76 }
77 } catch (error) {
78 console.error("Error fetching data:", error);
79 }
80 };
81
82 if (notionId) {
83 fetchData();

Callers 1

CompleteTrackCardFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected