{"ast":null,"code":"var _jsxFileName = \"/Users/shoofle/Projects/the-forest/src/PageView.jsx\",\n _s = $RefreshSig$();\nimport logo from './logo.svg';\nimport './App.css';\nimport { useQuery, useMutation } from '@tanstack/react-query';\nimport { useParams } from 'react-router-dom';\nimport { jsxDEV as _jsxDEV } from \"react/jsx-dev-runtime\";\nconst url = \"http://127.0.0.1:8000\";\nfunction setCurrentPage(row) {\n console.log(\"\" + row[0] + \" \" + row[1] + \" \" + row[2]);\n}\nfunction PageView() {\n _s();\n const {\n pagenumber\n } = useParams();\n const {\n isPending,\n error,\n data\n } = useQuery({\n queryKey: ['page', pagenumber],\n queryFn: () => fetch(url, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json'\n },\n body: JSON.stringify({\n statements: [{\n q: 'select * from pages where id=@val',\n params: {\n 'val': pagenumber\n }\n }]\n })\n }).then(res => res.json()).then(data => data[0].results.rows[0])\n });\n const mutation = useMutation({\n mutationFn: () => {\n if (isPending || error) return;\n return fetch(url, {\n metthod: 'POST',\n headers: {\n 'Content-Type': 'application/json'\n },\n body: JSON.stringify({\n statements: [{\n q: 'replace into pages (id, title, description) values (?, ?, ?)',\n params: data\n }]\n })\n });\n },\n onSuccess: () => {\n // Invalidate and refetch\n queryClient.invalidateQueries({\n queryKey: ['page', pagenumber]\n });\n }\n });\n if (isPending) return \"Loading...\";\n if (error) return \"Uh oh!\";\n const [the_id, page_title, page_text] = data;\n return /*#__PURE__*/_jsxDEV(\"div\", {\n className: \"App\",\n children: /*#__PURE__*/_jsxDEV(\"header\", {\n className: \"App-header\",\n children: [/*#__PURE__*/_jsxDEV(\"img\", {\n src: logo,\n className: \"App-logo\",\n alt: \"logo\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 59,\n columnNumber: 9\n }, this), /*#__PURE__*/_jsxDEV(\"div\", {\n className: \"Page-title\",\n children: /*#__PURE__*/_jsxDEV(\"h3\", {\n children: [the_id, \". \", page_title]\n }, void 0, true, {\n fileName: _jsxFileName,\n lineNumber: 61,\n columnNumber: 11\n }, this)\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 60,\n columnNumber: 9\n }, this), /*#__PURE__*/_jsxDEV(\"div\", {\n className: \"Page-contents\",\n children: /*#__PURE__*/_jsxDEV(\"pre\", {\n contenteditable: \"true\",\n children: page_text\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 64,\n columnNumber: 11\n }, this)\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 63,\n columnNumber: 9\n }, this)]\n }, void 0, true, {\n fileName: _jsxFileName,\n lineNumber: 58,\n columnNumber: 7\n }, this)\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 57,\n columnNumber: 5\n }, this);\n}\n_s(PageView, \"3Rz8iwWZfM7jQJQjiSWERZDbLq0=\", false, function () {\n return [useParams, useQuery, useMutation];\n});\n_c = PageView;\nexport default PageView;\nvar _c;\n$RefreshReg$(_c, \"PageView\");","map":{"version":3,"names":["logo","useQuery","useMutation","useParams","jsxDEV","_jsxDEV","url","setCurrentPage","row","console","log","PageView","_s","pagenumber","isPending","error","data","queryKey","queryFn","fetch","method","headers","body","JSON","stringify","statements","q","params","then","res","json","results","rows","mutation","mutationFn","metthod","onSuccess","queryClient","invalidateQueries","the_id","page_title","page_text","className","children","src","alt","fileName","_jsxFileName","lineNumber","columnNumber","contenteditable","_c","$RefreshReg$"],"sources":["/Users/shoofle/Projects/the-forest/src/PageView.jsx"],"sourcesContent":["import logo from './logo.svg';\nimport './App.css';\nimport { useQuery, useMutation } from '@tanstack/react-query'\nimport { useParams } from 'react-router-dom'\n\nconst url = \"http://127.0.0.1:8000\"\n\nfunction setCurrentPage(row) {\n console.log(\"\" + row[0] + \" \" + row[1] + \" \" + row[2]);\n}\n\nfunction PageView() {\n const { pagenumber } = useParams();\n const { isPending, error, data } = useQuery({\n queryKey: ['page', pagenumber],\n queryFn: () =>\n fetch(url, {\n method: 'POST',\n headers: {'Content-Type': 'application/json'},\n body: JSON.stringify({\n statements: [{\n q: 'select * from pages where id=@val',\n params: {'val': pagenumber}\n }]\n })\n }).then((res) => res.json())\n .then((data) => data[0].results.rows[0])\n })\n\n const mutation = useMutation({\n mutationFn: () => {\n if (isPending || error) return;\n return fetch(url, {\n metthod: 'POST',\n headers: {'Content-Type': 'application/json'},\n body: JSON.stringify({\n statements: [{\n q: 'replace into pages (id, title, description) values (?, ?, ?)',\n params: data,\n }]\n })\n })\n },\n onSuccess: () => {\n // Invalidate and refetch\n queryClient.invalidateQueries({ queryKey: ['page', pagenumber] })\n },\n });\n\n if (isPending) return \"Loading...\";\n\n if (error) return \"Uh oh!\";\n\n const [the_id, page_title, page_text] = data;\n\n return (\n
{page_text}\n