mirror of
https://codeberg.org/tacerus/teddit.git
synced 2024-11-26 17:19: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) => {
|
app.get('/search', (req, res, next) => {
|
||||||
let q = req.query.q
|
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 restrict_sr = req.query.restrict_sr
|
||||||
let nsfw = req.query.nsfw
|
let nsfw = req.query.nsfw
|
||||||
let sortby = req.query.sort
|
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)
|
let processed_json = await processSearchResults(json, false, after, before, req.cookies)
|
||||||
return res.render('search', {
|
return res.render('search', {
|
||||||
json: processed_json,
|
json: processed_json,
|
||||||
|
no_query: false,
|
||||||
q: q,
|
q: q,
|
||||||
restrict_sr: restrict_sr,
|
restrict_sr: restrict_sr,
|
||||||
nsfw: nsfw,
|
nsfw: nsfw,
|
||||||
@ -318,6 +334,7 @@ module.exports = (app, redis, fetch, RedditAPI) => {
|
|||||||
(async () => {
|
(async () => {
|
||||||
let processed_json = await processSearchResults(json, true, after, before, req.cookies)
|
let processed_json = await processSearchResults(json, true, after, before, req.cookies)
|
||||||
return res.render('search', {
|
return res.render('search', {
|
||||||
|
no_query: false,
|
||||||
json: processed_json,
|
json: processed_json,
|
||||||
q: q,
|
q: q,
|
||||||
restrict_sr: restrict_sr,
|
restrict_sr: restrict_sr,
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
doctype html
|
doctype html
|
||||||
html
|
html
|
||||||
head
|
head
|
||||||
title search results for #{q}
|
if no_query
|
||||||
|
title search teddit
|
||||||
|
else
|
||||||
|
title search results for #{q}
|
||||||
include includes/head.pug
|
include includes/head.pug
|
||||||
body(class=""+ user_preferences.theme +"")
|
body(class=""+ user_preferences.theme +"")
|
||||||
include includes/topbar.pug
|
include includes/topbar.pug
|
||||||
@ -94,7 +97,7 @@ html
|
|||||||
option(value="all", selected="selected") all time
|
option(value="all", selected="selected") all time
|
||||||
input(type="submit", value="search")
|
input(type="submit", value="search")
|
||||||
#links.search
|
#links.search
|
||||||
if json.posts.length === 0
|
if json.posts.length === 0 && !no_query
|
||||||
p no results
|
p no results
|
||||||
else
|
else
|
||||||
each link in json.posts
|
each link in json.posts
|
||||||
|
Loading…
Reference in New Issue
Block a user