{"ast":null,"code":"var _jsxFileName = \"/Users/shoofle/Projects/the-forest/src/PageView.jsx\",\n _s = $RefreshSig$();\nimport logo from './logo.svg';\nimport { queryClient, App } from './App.js';\nimport './App.css';\nimport { useQuery, useMutation } from '@tanstack/react-query';\nimport { useParams } from 'react-router-dom';\nimport { useRef } from 'react';\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 text_of_page,\n setBodyText\n } = useState(\"Nothing loaded yet\");\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 console.log(\"trying to mutate\");\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 // TODO: gett the value of the contenteditable block\n }]\n })\n }).then(res => console.log(\"tried to insert!\", res.json()));\n },\n onSuccess: () => {\n // Invalidate and refetch\n queryClient.invalidateQueries({\n queryKey: ['page', pagenumber]\n });\n }\n });\n function handleSubmit() {\n mutation.mutate();\n }\n if (isPending) return \"Loading...\";\n if (error) return \"Uh oh!\";\n setBodyText(data[2]);\n const [the_id, page_title, page_text] = data;\n return /*#__PURE__*/_jsxDEV(\"div\", {\n className: \"App\",\n children: /*#__PURE__*/_jsxDEV(\"form\", {\n onSubmit: handleSubmit,\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: 70,\n columnNumber: 11\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: 72,\n columnNumber: 13\n }, this)\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 71,\n columnNumber: 11\n }, this), /*#__PURE__*/_jsxDEV(\"div\", {\n className: \"Page-contents\",\n children: /*#__PURE__*/_jsxDEV(\"pre\", {\n contentEditable: \"true\",\n onChange: e => setBodyText(e.target.innerHTML),\n children: text_of_page\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 75,\n columnNumber: 13\n }, this)\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 74,\n columnNumber: 11\n }, this), /*#__PURE__*/_jsxDEV(\"button\", {\n type: \"submit\",\n children: \"Submit!\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 77,\n columnNumber: 11\n }, this)]\n }, void 0, true, {\n fileName: _jsxFileName,\n lineNumber: 69,\n columnNumber: 9\n }, this)\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 68,\n columnNumber: 7\n }, this)\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 67,\n columnNumber: 5\n }, this);\n}\n_s(PageView, \"f3oJ18zqvCEpM8p9pZdEevYwf2U=\", 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","queryClient","App","useQuery","useMutation","useParams","useRef","jsxDEV","_jsxDEV","url","setCurrentPage","row","console","log","PageView","_s","pagenumber","text_of_page","setBodyText","useState","isPending","error","data","queryKey","queryFn","fetch","method","headers","body","JSON","stringify","statements","q","params","then","res","json","results","rows","mutation","mutationFn","metthod","onSuccess","invalidateQueries","handleSubmit","mutate","the_id","page_title","page_text","className","children","onSubmit","src","alt","fileName","_jsxFileName","lineNumber","columnNumber","contentEditable","onChange","e","target","innerHTML","type","_c","$RefreshReg$"],"sources":["/Users/shoofle/Projects/the-forest/src/PageView.jsx"],"sourcesContent":["import logo from './logo.svg';\nimport { queryClient, App } from './App.js';\nimport './App.css';\nimport { useQuery, useMutation } from '@tanstack/react-query';\nimport { useParams } from 'react-router-dom';\nimport { useRef } from 'react';\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 { text_of_page, setBodyText } = useState(\"Nothing loaded yet\");\n\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 console.log(\"trying to mutate\");\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, // TODO: gett the value of the contenteditable block\n }]\n })\n }).then((res) => console.log(\"tried to insert!\", res.json()));\n },\n onSuccess: () => {\n // Invalidate and refetch\n queryClient.invalidateQueries({ queryKey: ['page', pagenumber] })\n },\n });\n\n function handleSubmit() {\n mutation.mutate();\n }\n\n if (isPending) return \"Loading...\";\n\n if (error) return \"Uh oh!\";\n\n setBodyText(data[2]);\n const [the_id, page_title, page_text] = data;\n\n return (\n
\n
\n
\n \"logo\"\n
\n

{the_id}. {page_title}

\n
\n
\n
 setBodyText(e.target.innerHTML)}>{text_of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