Do not run a search if only /search is requested

This commit is contained in:
StevenNMeza 2021-01-07 13:18:39 +01:00
parent f25fcc75ba
commit 3fdb74dd7b
2 changed files with 22 additions and 2 deletions

View File

@ -33,6 +33,21 @@ module.exports = (app, redis, fetch, RedditAPI) => {
app.get('/search', (req, res, next) => {
let q = req.query.q
if (typeof q === "undefined") {
return res.render('search', {
json: { posts: [] },
no_query: true,
q: '',
restrict_sr: undefined,
nsfw: undefined,
subreddit: 'all',
sortby: undefined,
past: undefined,
user_preferences: req.cookies
})
}
let restrict_sr = req.query.restrict_sr
let nsfw = req.query.nsfw
let sortby = req.query.sort
@ -289,6 +304,7 @@ module.exports = (app, redis, fetch, RedditAPI) => {
let processed_json = await processSearchResults(json, false, after, before, req.cookies)
return res.render('search', {
json: processed_json,
no_query: false,
q: q,
restrict_sr: restrict_sr,
nsfw: nsfw,
@ -318,6 +334,7 @@ module.exports = (app, redis, fetch, RedditAPI) => {
(async () => {
let processed_json = await processSearchResults(json, true, after, before, req.cookies)
return res.render('search', {
no_query: false,
json: processed_json,
q: q,
restrict_sr: restrict_sr,

View File

@ -1,7 +1,10 @@
doctype html
html
head
title search results for #{q}
if no_query
title search teddit
else
title search results for #{q}
include includes/head.pug
body(class=""+ user_preferences.theme +"")
include includes/topbar.pug
@ -94,7 +97,7 @@ html
option(value="all", selected="selected") all time
input(type="submit", value="search")
#links.search
if json.posts.length === 0
if json.posts.length === 0 && !no_query
p no results
else
each link in json.posts