Skip to content

Commit

Permalink
fix: fix PR reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
goratt12 committed Nov 10, 2024
1 parent ea6c691 commit 8760cc6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
15 changes: 10 additions & 5 deletions src/pages/Research/research.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ const search = async (
lastDocId?: string,
) => {
try {
const response = await fetch(
`/api/research?words=${words.join(',')}&category=${category}&sort=${sort}&status=${status ?? ''}&last_doc_id=${lastDocId ?? ''}`,
)
const url = new URL('/api/research', window.location.origin)
url.searchParams.append('words', words.join(','))
url.searchParams.append('category', category)
url.searchParams.append('sort', sort)
url.searchParams.append('status', status ?? '')
url.searchParams.append('lastDocId', lastDocId ?? '')

const response = await fetch(url)
const { items, total } = (await response.json()) as {
items: IResearch.Item[]
total: number
Expand Down Expand Up @@ -51,7 +56,7 @@ const getResearchCategories = async () => {

const getDraftCount = async (userId: string) => {
try {
const response = await fetch(`/api/research/drafts/count?user_id=${userId}`)
const response = await fetch(`/api/research/drafts/count?userId=${userId}`)
const { total } = (await response.json()) as { total: number }

return total
Expand All @@ -63,7 +68,7 @@ const getDraftCount = async (userId: string) => {

const getDrafts = async (userId: string) => {
try {
const response = await fetch(`/api/research?drafts=true&user_id=${userId}`)
const response = await fetch(`/api/research?drafts=true&userId=${userId}`)
const { items } = (await response.json()) as { items: IResearch.Item[] }

return items
Expand Down
4 changes: 2 additions & 2 deletions src/routes/api.research.categories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { firestore } from 'src/utils/firebase'

import type { ICategory } from 'oa-shared'

const cache = new Keyv<ICategory[]>({ ttl: 600000 }) // ttl: 10 minutes
const cache = new Keyv<ICategory[]>({ ttl: 3600000 }) // ttl: 60 minutes

// runs on the server
export const loader = async () => {
const cachedCategories = await cache.get('researchCategories')

// check if cached map pins are availbe, if not - load from db and cache them
// check if cached categories are available, if not - load from db and cache them
if (cachedCategories) return json({ categories: cachedCategories })

const collectionRef = collection(firestore, DB_ENDPOINTS.researchCategories)
Expand Down
2 changes: 1 addition & 1 deletion src/routes/api.research.drafts.count.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { firestore } from 'src/utils/firebase'
export const loader = async ({ request }) => {
const url = new URL(request.url)
const searchParams = url.searchParams
const userId: string | null = searchParams.get('user_id')
const userId: string | null = searchParams.get('userId')

const collectionRef = collection(firestore, DB_ENDPOINTS.research)
const filters = and(
Expand Down
4 changes: 2 additions & 2 deletions src/routes/api.research.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ export const loader = async ({ request }) => {
const status: ResearchStatus | null = searchParams.get(
'status',
) as ResearchStatus
const lastDocId: string | null = searchParams.get('last_doc_id')
const lastDocId: string | null = searchParams.get('lastDocId')
const drafts: boolean = searchParams.get('drafts') != undefined
const userId: string | null = searchParams.get('user_id')
const userId: string | null = searchParams.get('userId')

const { itemsQuery, countQuery } = await createSearchQuery(
words,
Expand Down

0 comments on commit 8760cc6

Please sign in to comment.