Merge pull request 'search_fix' (#164) from StevenNMeza/teddit:search_fix into main

Reviewed-on: https://codeberg.org/teddit/teddit/pulls/164
This commit is contained in:
teddit 2021-03-19 19:33:07 +01:00
commit dd47ee9e74
2 changed files with 17 additions and 2 deletions

View File

@ -719,6 +719,21 @@ module.exports = (app, redis, fetch, RedditAPI) => {
app.get('/r/:subreddit/search', (req, res, next) => {
let subreddit = req.params.subreddit
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: subreddit,
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

View File

@ -15,13 +15,13 @@ html
input(type="text", name="q", id="q", placeholder="search", value=""+ q +"")
div
label(for="restrict_sr") limit my search to r/#{subreddit}
if restrict_sr === 'on'
if !restrict_sr || restrict_sr === 'on'
input(type="checkbox", name="restrict_sr", id="restrict_sr", checked="checked")
else
input(type="checkbox", name="restrict_sr", id="restrict_sr")
div
label(for="nsfw") include NSFW results
if nsfw === 'on'
if !nsfw || nsfw === 'on'
input(type="checkbox", name="nsfw", id="nsfw", checked="checked")
else
input(type="checkbox", name="nsfw", id="nsfw")