diff --git a/routes.js b/routes.js index c807cd5..88fadbb 100644 --- a/routes.js +++ b/routes.js @@ -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, diff --git a/views/search.pug b/views/search.pug index dd048b0..1abaab7 100644 --- a/views/search.pug +++ b/views/search.pug @@ -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