Little bug fixes and improvements

* Improved html treatment on quizs
* Redirect to home when quiz does not exist
* Show quiz send confirm message only when form validated
This commit is contained in:
Niko 2022-03-09 00:05:53 +01:00
parent 058826feaa
commit a0050ded4a
3 changed files with 10 additions and 5 deletions

View File

@ -16,8 +16,8 @@ module.exports = {
})
apex.net.actor.get.splice(apex.net.actor.get.length-1, 0,
async (req, res, next) => {
res.locals.apex.target
.manuallyApprovesFollowers = true
if (res.locals.apex.target !== undefined)
res.locals.apex.target.manuallyApprovesFollowers = true
next()
})
},

View File

@ -22,7 +22,8 @@ module.exports = {
html2text: (html) => {
html = decodeURIComponent(html)
html = html.replaceAll('&gt;','>').replaceAll('&lt;','<')
.replaceAll('&quot;','"').replaceAll('&amp;','&')
.replaceAll('&quot;','"').replaceAll('&apos;', "'")
.replaceAll('&amp;','&')
html = html.replaceAll(/<br\s+?\/?>/g, '<br>')
html = html.replaceAll('</p>', '\n')
html = html.replaceAll('<br>', '\n')

View File

@ -24,6 +24,8 @@ app.pages.quiz = {
const onDataLoaded = async function(json) {
await app.template.loadMany(['quiz.index', 'quiz.item']);
if (json.from === undefined)
return hashredir();
page().data = json;
page().paint(json);
if (getNormalizedURI() === app.vars.app_dir &&
@ -39,6 +41,8 @@ app.pages.quiz = {
},
paint: function(json) {
json = json || page().data;
if (json.from === undefined)
return hashredir();
if (json.from.props.age === undefined)
json.from.props.age = '??';
if (json.from.props.gender === undefined)
@ -168,8 +172,6 @@ app.pages.quiz = {
});
},
send: async function() {
if (!await app.toast.infoConfirm(s('app.confirm.crush_send_quiz')))
return false;
const form = document.querySelector('form#quiz');
var data = { quiz_id: page().data.id };
for (var i = 0; i < page().data.content.length; i++) {
@ -179,6 +181,8 @@ app.pages.quiz = {
return app.toast.error(s('app.error.must_fill_quiz'));
data[key] = value;
}
if (!await app.toast.infoConfirm(s('app.confirm.crush_send_quiz')))
return false;
http.post('/api/v1/me/quizs', data, function(json) {
if (json.error !== undefined)
app.toast.error(app.strings.app.error[json.error]);