(page: number)
| 39 | }; |
| 40 | |
| 41 | const fetchPage = async (page: number) => { |
| 42 | const { data: documents, error } = await supabase.rpc("get_sections", { |
| 43 | _limit: PAGE_SIZE, |
| 44 | _offset: (page - 1) * PAGE_SIZE, |
| 45 | }); |
| 46 | |
| 47 | if (error) { |
| 48 | console.error(error); |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | if (!documents?.length) return; |
| 53 | |
| 54 | const newDocuments: Document[] = []; |
| 55 | |
| 56 | for (const document of documents) { |
| 57 | try { |
| 58 | const documentRowIds = document.ids.split(","); |
| 59 | const { data: documentChunks } = await supabase |
| 60 | .from("doc_chunks") |
| 61 | .select("*") |
| 62 | .in("id", documentRowIds); |
| 63 | |
| 64 | if (documentChunks?.length) { |
| 65 | newDocuments.push({ |
| 66 | docChunks: documentChunks, |
| 67 | pageName: document.result_page_title, |
| 68 | sectionName: document.result_section_title, |
| 69 | createdAt: document.latest_created_at, |
| 70 | url: document.result_page_url, |
| 71 | }); |
| 72 | } |
| 73 | } catch (error) { |
| 74 | console.error(error); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | setDocs(newDocuments); |
| 79 | }; |
| 80 | |
| 81 | const refreshPage = async () => { |
| 82 | await fetchPage(docPage); |
no outgoing calls
no test coverage detected