Skip to content
Permalink
Browse files

Add a new /:id/edit route that goes straight to editing a prefilled form

  • Loading branch information...
thesephist committed Jun 11, 2019
1 parent 8d05c6e commit af81c9fd3404b67fa380211d670a24e41b5b24b0
Showing with 32 additions and 4 deletions.
  1. +18 −1 src/main.js
  2. +14 −3 static/js/main.js
@@ -172,6 +172,23 @@ app.get('/:id/raw', async (req, res) => {
}
});

app.get('/:id/edit', async (req, res) => {
res.set('Content-Type', 'text/plain');

const rid = req.params.id;
try {
if (await storage.has(rid)) {
const record = await storage.get(rid);
res.redirect(302, `/#${record.id}`); // prefilled form
} else {
res.status(404);
res.send(`Record ${rid} does not exist.`);
}
} catch (e) {
console.error(e);
}
});

app.get('/:id/content', async (req, res) => {
res.set('Content-Type', 'application/json');

@@ -223,6 +240,6 @@ app.use('/static', express.static('static'));

app.listen(
Config.PORT,
_ => console.log(`Zone service running on :${Config.PORT}`)
() => console.log(`Zone service running on :${Config.PORT}`)
);

@@ -92,14 +92,16 @@
}
}

setPasswordGroupVisibility(false);
idInput.addEventListener('input', debounce(async () => {
const onIdInput = async () => {
const [showPasswordRequired, _] = [
await checkIfShouldShowPasswordRequired(),
await populateContentForExistingNote(),
];
setPasswordGroupVisibility(showPasswordRequired);
}, 400));
}

setPasswordGroupVisibility(false);
idInput.addEventListener('input', debounce(onIdInput, 400));
uriInput.addEventListener('input', () => {
userTypedInput = uriInput.value.length > 0;
});
@@ -115,5 +117,14 @@
}
document.getElementById('expandNoteButton').addEventListener('click', expandTextarea);

document.addEventListener('DOMContentLoaded', () => {
// allow for linus.zone/#<:slug> to go straight to editing
if (window.location.hash.length > 1) {
const noteToEdit = window.location.hash.substr(1);
idInput.value = noteToEdit;
onIdInput();
}
});

}());

0 comments on commit af81c9f

Please sign in to comment.
You can’t perform that action at this time.