Skip to content

Commit

Permalink
Support sensitive state mode in tags page
Browse files Browse the repository at this point in the history
  • Loading branch information
bcomnes committed Jun 22, 2022
1 parent d57bd8b commit 9ecf11e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
23 changes: 18 additions & 5 deletions routes/api/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@ export default async function tagsRoutes (fastify, opts) {
'/tags',
{
preHandler: fastify.auth([fastify.verifyJWT]),
schema: {},
schema: {
querystring: {
type: 'object',
properties: {
sensitive: {
type: 'boolean',
default: false
}
}
}
},
response: {
200: {
type: 'object',
Expand All @@ -26,14 +36,17 @@ export default async function tagsRoutes (fastify, opts) {
},
async function (request, reply) {
const userId = request.user.id
const { sensitive } = request.query

const query = SQL`
select name, created_at, count(bookmarks_tags.tag_id) as count
select tags.name, tags.created_at, count(bookmarks_tags.tag_id) as count
from tags
left outer join bookmarks_tags on (tags.id = bookmarks_tags.tag_id)
where owner_id = ${userId}
group by (name, created_at)
order by created_at desc;
left outer join bookmarks on (bookmarks_tags.bookmark_id = bookmarks.id)
where tags.owner_id = ${userId}
${!sensitive ? SQL`AND sensitive = false` : SQL``}
group by (tags.name, tags.created_at)
order by tags.created_at desc;
`

const results = await fastify.pg.query(query)
Expand Down
7 changes: 4 additions & 3 deletions web/tags/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ export const page = Component(() => {
console.log('getting tags')
setTagsLoading(true)
setTagsError(null)

const response = await fetch(`${state.apiUrl}/tags`, {
const pageParams = new URLSearchParams(window.location.search)
pageParams.set('sensitive', state.sensitive)
const response = await fetch(`${state.apiUrl}/tags?${pageParams.toString()}`, {
method: 'get',
headers: {
'accept-encoding': 'application/json'
Expand All @@ -44,7 +45,7 @@ export const page = Component(() => {
.catch(err => { console.error(err); setTagsError(err) })
.finally(() => { setTagsLoading(false) })
}
}, [state.apiUrl])
}, [state.apiUrl, state.sensitive])

return html`
<div>
Expand Down

0 comments on commit 9ecf11e

Please sign in to comment.