selfhostable, read-only reddit client
16
fork

Configure Feed

Select the types of activity you want to include in your feed.

add post search,

also fix filters, combine old and new parse logic

Akshay 3e3778dd e3b13422

+25 -34
+19 -26
src/routes/index.js
··· 112 112 if (!req.query || !req.query.q) { 113 113 res.render("sub-search", { user: req.user }); 114 114 } else { 115 - const { q, options } = req.query.q.split(/\s+/).reduce( 116 - (acc, word) => { 117 - if (word.startsWith("+")) { 118 - acc.options.push(word.slice(1)); 119 - } else { 120 - acc.q += `${word} `; 121 - } 122 - return acc; 123 - }, 124 - { options: [], q: "" }, 125 - ); 126 - 115 + const { q, options } = parseQuery(req.query.q); 127 116 const { items, after } = await G.searchSubreddits(q, { 128 - include_over_18: options.includes("nsfw"), 117 + include_over_18: (options.nsfw ?? "no") === "yes", 129 118 }); 130 119 const subs = db 131 120 .query("SELECT subreddit FROM subscriptions WHERE user_id = $id") ··· 151 140 if (!req.query || !req.query.q) { 152 141 res.render("post-search", { user: req.user }); 153 142 } else { 154 - const { q, options } = req.query.q.split(/\s+/).reduce( 155 - (acc, word) => { 156 - if (word.startsWith("+")) { 157 - acc.options.push(word.slice(1)); 158 - } else { 159 - acc.q += `${word} `; 160 - } 161 - return acc; 162 - }, 163 - { options: [], q: "" }, 164 - ); 165 - 143 + const { q, options } = parseQuery(req.query.q); 166 144 const { items, after } = await G.searchSubmissions(q, { 167 - include_over_18: options.includes("nsfw"), 145 + include_over_18: (options.nsfw ?? "no") === "yes", 168 146 }); 169 147 const message = 170 148 items.length === 0 ··· 179 157 }); 180 158 } 181 159 }); 160 + 161 + function parseQuery(q) { 162 + return q.split(/\s+/).reduce( 163 + (acc, word) => { 164 + if (word.includes(":")) { 165 + const [key, val] = word.split(":"); 166 + acc.options[key] = val; 167 + } else { 168 + acc.q += `${word} `; 169 + } 170 + return acc; 171 + }, 172 + { options: [], q: "" }, 173 + ); 174 + } 182 175 183 176 // GET /dashboard 184 177 router.get("/dashboard", authenticateToken, async (req, res) => {
+1 -1
src/views/post-search.pug
··· 13 13 h1 search posts 14 14 form(action="/post-search" method="get").search-bar 15 15 - var prefill = original_query ?? ""; 16 - input(type="text" name="q" placeholder="search posts" value=prefill required).search-input 16 + input(type="text" name="q" placeholder="type in a search term..." value=prefill required).search-input 17 17 button(type="submit").search-button go 18 18 if message 19 19 div.search-message
+4 -6
src/views/search.pug
··· 13 13 14 14 form(action="/sub-search" method="get").search-bar 15 15 - var prefill = original_query ?? ""; 16 - input(type="text" name="q" placeholder="search subreddits" value=prefill required).search-input 16 + input(type="text" name="q" placeholder="type in a search term..." value=prefill required).search-input 17 17 button(type="submit").search-button go 18 + 19 + hr 18 20 19 21 h1 search posts 20 22 21 23 form(action="/post-search" method="get").search-bar 22 24 - var prefill = original_query ?? ""; 23 - input(type="text" name="q" placeholder="search posts" value=prefill required).search-input 25 + input(type="text" name="q" placeholder="type in a search term..." value=prefill required).search-input 24 26 button(type="submit").search-button go 25 - 26 - hr 27 - 28 - h3 tips 29 27 p 30 28 | you can narrow search results using filters: 31 29 br
+1 -1
src/views/sub-search.pug
··· 12 12 h1 search subreddits 13 13 form(action="/sub-search" method="get").search-bar 14 14 - var prefill = original_query ?? ""; 15 - input(type="text" name="q" placeholder="search subreddits" value=prefill required).search-input 15 + input(type="text" name="q" placeholder="type in a search term..." value=prefill required).search-input 16 16 button(type="submit").search-button go 17 17 if message 18 18 div.search-message