fixing up and finishing the api sside histories
This commit is contained in:
parent
6355e86777
commit
13fb4db1d1
@ -27,11 +27,9 @@ const defaults = {
|
||||
};
|
||||
|
||||
export async function postNewPage() {
|
||||
return fetch(`${apiUrl}/page/new`, {
|
||||
return shoofetch(`${apiUrl}/page/new`, {
|
||||
method: 'POST',
|
||||
...defaults
|
||||
}).then((res) => res.json())
|
||||
.then((data) => data.id)
|
||||
})
|
||||
}
|
||||
|
||||
export async function fetchPageList() {
|
||||
|
@ -17,10 +17,10 @@ function Landing() {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const makeNewPage = useMutation({ // for changing the value when we're done with it
|
||||
mutationFn: () => postNewPage()
|
||||
.catch((error) => { console.log("got an error", error.json()) }),
|
||||
mutationFn: () => postNewPage(),
|
||||
onSettled: async (data, error, variables) => {
|
||||
// Invalidate and navigate to the new page
|
||||
console.log(data, error, variables);
|
||||
await queryClient.invalidateQueries({ queryKey: ['pages'] });
|
||||
navigate(`/${data}/edit`);
|
||||
},
|
||||
|
@ -5,8 +5,7 @@ const { circular } = require('graphology-layout');
|
||||
function graphFromList(allTheStuff) {
|
||||
const graph = new graphology.Graph();
|
||||
for (const {number, html} of allTheStuff) {
|
||||
|
||||
graph.addNode(number);
|
||||
if (!graph.hasNode(number)) graph.addNode(number);
|
||||
}
|
||||
|
||||
for (const {number, html} of allTheStuff) {
|
||||
|
@ -9,9 +9,19 @@ const { loginRequired } = require('../authStuff.js');
|
||||
const showdown = require('showdown');
|
||||
const converter = new showdown.Converter();
|
||||
|
||||
const pageListQuery = db.prepare(`
|
||||
select p.number, p.title, p.time
|
||||
from pages p
|
||||
where time >= (
|
||||
select max(s.time)
|
||||
from pages s
|
||||
where s.number = p.number
|
||||
)
|
||||
order by p.time desc
|
||||
`);
|
||||
app.get('/pages', (req, res) => {
|
||||
try {
|
||||
const pages = db.prepare('select number, title from pages').all();
|
||||
const pages = pageListQuery.all();
|
||||
res.status(200).json(pages);
|
||||
} catch (error) {
|
||||
res.status(500).json({"error": error});
|
||||
@ -20,11 +30,11 @@ app.get('/pages', (req, res) => {
|
||||
|
||||
app.post('/page/new', loginRequired, (req, res) => {
|
||||
try {
|
||||
const maxPageNumber = db.prepare('select max(number) from pages').get()
|
||||
console.log('maxPageNumber is ', maxPageNumber);
|
||||
const newPage = db.prepare('insert into pages (title, description, author) values (?, ?, ?) returning number')
|
||||
.get("new page", "this page is new!", req.session.userId);
|
||||
res.status(200).json(newPage);
|
||||
const maxPageNumber = db.prepare('select max(number) as maximum from pages').get()
|
||||
const newPageNumber = maxPageNumber.maximum + 1;
|
||||
const newPage = db.prepare('insert into pages (number, title, description, author) values (?, ?, ?, ?) returning number')
|
||||
.get(newPageNumber, "new page", "this page is new!", req.session.userId);
|
||||
res.status(200).json(newPageNumber);
|
||||
} catch (error) {
|
||||
res.status(500).json({"error": error});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user