mirror of
https://codeberg.org/tacerus/teddit.git
synced 2024-11-26 09:09:27 +01:00
Do not run a search if only /search
is requested
This commit is contained in:
parent
f25fcc75ba
commit
3fdb74dd7b
17
routes.js
17
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,
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user