Skip to content

Commit

Permalink
Rename search query param for ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
nolze committed Sep 16, 2020
1 parent 169b1e3 commit 407e959
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion server/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const router = express.Router();
app.use(BASEPATH, router);

router.get('/api/search', (req, res) => {
db.search(req.query.q, req.query.offset, req.query.limit, req.query.s)
db.search(req.query.q, req.query.offset, req.query.limit, req.query.ord)
.then((pages) => {
res.json({
pages: pages,
Expand Down
4 changes: 2 additions & 2 deletions view/src/components/Navbar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
<Link to="" class="underline">Top</Link>
</div>
<div class="text-sm mx-2">
<Link to="search?q=*&s=updated" class="underline">Recent Changes</Link>
<Link to="search?q=*{'&'}ord=updated" class="underline">Recent Changes</Link>
</div>
<div class="text-sm mx-2">
<Link to="search?q=*&s=alphabetical" class="underline">Index</Link>
<Link to="search?q=*{'&'}ord=alphabetical" class="underline">Index</Link>
</div>
<form on:submit|preventDefault={search}>
<input
Expand Down
12 changes: 6 additions & 6 deletions view/src/pages/Search.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
export let query;
$: q = query.q;
$: order = query.s || 'updated';
$: order = query.ord || 'updated';
$: start = parseInt(query.start) || 0;
$: fetchResults = async () => {
return await api
.get(`/search`, { params: { q, start, s: order } })
.get(`/search`, { params: { q, start, ord: order } })
.then((resp) => resp.data)
.catch(() => {});
};
Expand All @@ -28,12 +28,12 @@
<div class="mb-4 text-sm flex">
<span class="mr-1">Sort:</span>
<Link
to="search?q={q}&s=updated"
to="search?q={q}{'&'}ord=updated"
class={order === 'updated' ? 'font-bold' : ''}>
Recently updated
</Link><span class="mx-1">·</span>
<Link
to="search?q={q}&s=alphabetical"
to="search?q={q}{'&'}ord=alphabetical"
class={order === 'alphabetical' ? 'font-bold' : ''}>
Alphabetical
</Link>
Expand All @@ -51,11 +51,11 @@
{/await}
<div class="text-sm mt-8 flex">
<Link
to="search?q={q}&s={order}&start=0"
to="search?q={q}{'&'}ord={order}&start=0"
class={start === 0 ? 'text-gray-600' : ''}>
Previous
</Link><span class="mx-2" />
<Link to="search?q={q}&s={order}&start=0">Next</Link>
<Link to="search?q={q}{'&'}ord={order}&start=0">Next</Link>
</div>
</main>
</div>
Expand Down

0 comments on commit 407e959

Please sign in to comment.