the-forest/client/node_modules/.cache/babel-loader/447d8904773e5d6917207a4371d60f4bb371d07850829763372035fc9e70d158.json

1 line
10 KiB
JSON
Raw Normal View History

2024-09-17 20:35:18 -04:00
{"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 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: 66,\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: 68,\n columnNumber: 13\n }, this)\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 67,\n columnNumber: 11\n }, this), /*#__PURE__*/_jsxDEV(\"div\", {\n className: \"Page-contents\",\n children: /*#__PURE__*/_jsxDEV(\"pre\", {\n contentEditable: \"true\",\n children: text_of_page\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 71,\n columnNumber: 13\n }, this)\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 70,\n columnNumber: 11\n }, this), /*#__PURE__*/_jsxDEV(\"button\", {\n type: \"submit\",\n children: \"Submit!\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 73,\n columnNumber: 11\n }, this)]\n }, void 0, true, {\n fileName: _jsxFileName,\n lineNumber: 65,\n columnNumber: 9\n }, this)\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 64,\n columnNumber: 7\n }, this)\n }, void 0, false, {\n fileN