diff --git a/src/components/DocFeedbackNote.tsx b/src/components/DocFeedbackNote.tsx
index a0918a5d8..c9b1e9e35 100644
--- a/src/components/DocFeedbackNote.tsx
+++ b/src/components/DocFeedbackNote.tsx
@@ -1,11 +1,7 @@
import * as React from 'react'
import { twMerge } from 'tailwind-merge'
import { useMutation, useQueryClient } from '@tanstack/react-query'
-import {
- deleteDocFeedback,
- updateDocFeedback,
- updateDocFeedbackCollapsed,
-} from '~/utils/docFeedback.functions'
+import { docFeedbackMutations, docFeedbackQueries } from '~/queries/docFeedback'
import type { DocFeedback } from '~/db/types'
import {
CaretDownIcon,
@@ -87,19 +83,19 @@ export function DocFeedbackNote({
firstLine.length > 60 ? firstLine.substring(0, 60) + '...' : firstLine
const deleteMutation = useMutation({
- mutationFn: deleteDocFeedback,
+ ...docFeedbackMutations.delete(),
onMutate: async () => {
// Cancel any outgoing refetches
- await queryClient.cancelQueries({ queryKey: ['docFeedback'] })
+ await queryClient.cancelQueries({ queryKey: docFeedbackQueries.all() })
// Snapshot the previous value
const previousData = queryClient.getQueriesData({
- queryKey: ['docFeedback'],
+ queryKey: docFeedbackQueries.all(),
})
// Optimistically remove the note from all matching queries
queryClient.setQueriesData(
- { queryKey: ['docFeedback'] },
+ { queryKey: docFeedbackQueries.all() },
(old: DocFeedbackCacheData) => {
if (!old || typeof old !== 'object') return old
@@ -140,24 +136,24 @@ export function DocFeedbackNote({
setIsDeleting(false)
},
onSettled: () => {
- queryClient.invalidateQueries({ queryKey: ['docFeedback'] })
+ queryClient.invalidateQueries({ queryKey: docFeedbackQueries.all() })
},
})
const updateMutation = useMutation({
- mutationFn: updateDocFeedback,
+ ...docFeedbackMutations.update(),
onMutate: async (variables) => {
// Cancel any outgoing refetches
- await queryClient.cancelQueries({ queryKey: ['docFeedback'] })
+ await queryClient.cancelQueries({ queryKey: docFeedbackQueries.all() })
// Snapshot the previous value
const previousData = queryClient.getQueriesData({
- queryKey: ['docFeedback'],
+ queryKey: docFeedbackQueries.all(),
})
// Optimistically update the note content
queryClient.setQueriesData(
- { queryKey: ['docFeedback'] },
+ { queryKey: docFeedbackQueries.all() },
(old: DocFeedbackCacheData) => {
if (!old || typeof old !== 'object') return old
@@ -214,24 +210,24 @@ export function DocFeedbackNote({
setIsSaving(false)
},
onSettled: () => {
- queryClient.invalidateQueries({ queryKey: ['docFeedback'] })
+ queryClient.invalidateQueries({ queryKey: docFeedbackQueries.all() })
},
})
const collapsedMutation = useMutation({
- mutationFn: updateDocFeedbackCollapsed,
+ ...docFeedbackMutations.updateCollapsed(),
onMutate: async (variables) => {
// Cancel any outgoing refetches
- await queryClient.cancelQueries({ queryKey: ['docFeedback'] })
+ await queryClient.cancelQueries({ queryKey: docFeedbackQueries.all() })
// Snapshot the previous value
const previousData = queryClient.getQueriesData({
- queryKey: ['docFeedback'],
+ queryKey: docFeedbackQueries.all(),
})
// Optimistically toggle collapsed state
queryClient.setQueriesData(
- { queryKey: ['docFeedback'] },
+ { queryKey: docFeedbackQueries.all() },
(old: DocFeedbackCacheData) => {
if (!old || typeof old !== 'object') return old
@@ -274,7 +270,7 @@ export function DocFeedbackNote({
}
},
onSettled: () => {
- queryClient.invalidateQueries({ queryKey: ['docFeedback'] })
+ queryClient.invalidateQueries({ queryKey: docFeedbackQueries.all() })
},
})
diff --git a/src/components/DocFeedbackProvider.tsx b/src/components/DocFeedbackProvider.tsx
index 26125bcba..9e52e5fb3 100644
--- a/src/components/DocFeedbackProvider.tsx
+++ b/src/components/DocFeedbackProvider.tsx
@@ -4,8 +4,7 @@ import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
import { twMerge } from 'tailwind-merge'
import { DocFeedbackNote } from './DocFeedbackNote'
import { DocFeedbackFloatingButton } from './DocFeedbackFloatingButton'
-import { getDocFeedbackForPageQueryOptions } from '~/queries/docFeedback'
-import { createDocFeedback } from '~/utils/docFeedback.functions'
+import { docFeedbackMutations, docFeedbackQueries } from '~/queries/docFeedback'
import { useCurrentUser } from '~/hooks/useCurrentUser'
import { useLoginModal } from '~/contexts/LoginModalContext'
import {
@@ -58,7 +57,7 @@ export function DocFeedbackProvider({
// Fetch feedback for this page
const { data: feedbackData } = useQuery(
- getDocFeedbackForPageQueryOptions({
+ docFeedbackQueries.page({
pagePath,
libraryVersion,
}),
@@ -602,14 +601,14 @@ function CreatingFeedbackNote({
}
const createMutation = useMutation({
- mutationFn: createDocFeedback,
+ ...docFeedbackMutations.create(),
onMutate: async (variables) => {
// Cancel any outgoing refetches
- await queryClient.cancelQueries({ queryKey: ['docFeedback'] })
+ await queryClient.cancelQueries({ queryKey: docFeedbackQueries.all() })
// Snapshot the previous value
const previousData = queryClient.getQueriesData({
- queryKey: ['docFeedback'],
+ queryKey: docFeedbackQueries.all(),
})
// Create a temporary optimistic note
@@ -640,7 +639,7 @@ function CreatingFeedbackNote({
userFeedback: DocFeedback[]
detachedFeedback: any[]
isModerator: boolean
- }>({ queryKey: ['docFeedback'] }, (old) => {
+ }>({ queryKey: docFeedbackQueries.all() }, (old) => {
if (!old) return old
return {
...old,
@@ -664,7 +663,7 @@ function CreatingFeedbackNote({
setIsSaving(false)
},
onSettled: () => {
- queryClient.invalidateQueries({ queryKey: ['docFeedback'] })
+ queryClient.invalidateQueries({ queryKey: docFeedbackQueries.all() })
},
})
diff --git a/src/components/FeedbackLeaderboard.tsx b/src/components/FeedbackLeaderboard.tsx
index c079809cb..7620c41d9 100644
--- a/src/components/FeedbackLeaderboard.tsx
+++ b/src/components/FeedbackLeaderboard.tsx
@@ -1,7 +1,7 @@
import * as React from 'react'
import { useQuery } from '@tanstack/react-query'
import { useNavigate, useSearch } from '@tanstack/react-router'
-import { getDocFeedbackLeaderboardQueryOptions } from '~/queries/docFeedback'
+import { docFeedbackQueries } from '~/queries/docFeedback'
import { Spinner } from './Spinner'
import {
Table,
@@ -22,7 +22,7 @@ export function FeedbackLeaderboard() {
const { page, pageSize } = search
const { data, isLoading, error } = useQuery(
- getDocFeedbackLeaderboardQueryOptions({
+ docFeedbackQueries.leaderboard({
pagination: { page, pageSize },
}),
)
diff --git a/src/components/FeedbackModerationPage.tsx b/src/components/FeedbackModerationPage.tsx
index d22514821..208851470 100644
--- a/src/components/FeedbackModerationPage.tsx
+++ b/src/components/FeedbackModerationPage.tsx
@@ -1,8 +1,7 @@
import * as React from 'react'
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
import { useNavigate, useSearch } from '@tanstack/react-router'
-import { listDocFeedbackForModerationQueryOptions } from '~/queries/docFeedback'
-import { moderateDocFeedback } from '~/utils/docFeedback.functions'
+import { docFeedbackMutations, docFeedbackQueries } from '~/queries/docFeedback'
import { FeedbackModerationTopBar } from './FeedbackModerationTopBar'
import { FeedbackModerationList } from './FeedbackModerationList'
import { useToast } from '~/components/ToastProvider'
@@ -15,7 +14,7 @@ export function FeedbackModerationPage() {
const { notify } = useToast()
const { data, isLoading, error } = useQuery(
- listDocFeedbackForModerationQueryOptions({
+ docFeedbackQueries.moderation({
pagination: {
page: search.page,
pageSize: search.pageSize,
@@ -32,7 +31,7 @@ export function FeedbackModerationPage() {
)
const moderateMutation = useMutation({
- mutationFn: moderateDocFeedback,
+ ...docFeedbackMutations.moderate(),
onSuccess: (_, variables) => {
notify(
@@ -44,7 +43,9 @@ export function FeedbackModerationPage() {
,
)
- queryClient.invalidateQueries({ queryKey: ['docFeedback', 'moderation'] })
+ queryClient.invalidateQueries({
+ queryKey: docFeedbackQueries.moderations(),
+ })
},
onError: (error: Error) => {
notify(
diff --git a/src/components/NotesModerationPage.tsx b/src/components/NotesModerationPage.tsx
index 0182cad93..ce35fc72c 100644
--- a/src/components/NotesModerationPage.tsx
+++ b/src/components/NotesModerationPage.tsx
@@ -1,7 +1,7 @@
import * as React from 'react'
import { useQuery } from '@tanstack/react-query'
import { useNavigate, useSearch } from '@tanstack/react-router'
-import { listDocFeedbackForModerationQueryOptions } from '~/queries/docFeedback'
+import { docFeedbackQueries } from '~/queries/docFeedback'
import { NotesModerationTopBar } from './NotesModerationTopBar'
import { NotesModerationList } from './NotesModerationList'
import { Spinner } from '~/components/Spinner'
@@ -11,7 +11,7 @@ export function NotesModerationPage() {
const search = useSearch({ from: '/admin/notes/' })
const { data, isLoading, error } = useQuery(
- listDocFeedbackForModerationQueryOptions({
+ docFeedbackQueries.moderation({
pagination: {
page: search.page,
pageSize: search.pageSize,
diff --git a/src/components/OpenSourceStats.tsx b/src/components/OpenSourceStats.tsx
index ae0bed1c1..071cb9385 100644
--- a/src/components/OpenSourceStats.tsx
+++ b/src/components/OpenSourceStats.tsx
@@ -5,11 +5,7 @@ import {
StarIcon,
} from '@phosphor-icons/react'
import { type Library } from '~/libraries'
-import {
- homepageNpmStatsSummaryQuery,
- ossStatsQuery,
- recentDownloadsQuery,
-} from '~/queries/stats'
+import { statsQueries } from '~/queries/stats'
import { HomeStatNumber } from '~/components/home/HomeStatNumber'
import { LiveDownloadCount } from '~/components/home/LiveDownloadCount'
import { useNpmDownloadCounter } from '~/hooks/useNpmDownloadCounter'
@@ -60,18 +56,20 @@ export default function OssStats({
page?: StatsPage
initialStats?: HomepageStatsSnapshot
}) {
- const { data: stats, isLoading } = useQuery(ossStatsQuery({ library }))
+ const { data: stats, isLoading } = useQuery(
+ statsQueries.ossSummary({ library }),
+ )
const {
data: homepageNpmSummary,
dataUpdatedAt,
isLoading: isLoadingHomepageNpmSummary,
} = useQuery({
- ...homepageNpmStatsSummaryQuery(),
+ ...statsQueries.homepageNpmSummary(),
enabled: !library,
})
const { data: recentDownloads, isLoading: isLoadingRecentDownloads } =
useQuery({
- ...recentDownloadsQuery({
+ ...statsQueries.recentDownloads({
library: library ?? tanStackTotalNpmStatsLibrary,
}),
enabled: Boolean(library),
diff --git a/src/components/ShowcaseDetail.tsx b/src/components/ShowcaseDetail.tsx
index a369d4d14..2d5185b59 100644
--- a/src/components/ShowcaseDetail.tsx
+++ b/src/components/ShowcaseDetail.tsx
@@ -14,12 +14,7 @@ import { Button } from '~/ui'
import { twMerge } from 'tailwind-merge'
import { libraries, type LibraryId } from '~/libraries'
import { USE_CASE_LABELS } from '~/utils/showcase.shared'
-import { voteShowcase } from '~/utils/showcase.functions'
-import {
- getShowcaseQueryOptions,
- getRelatedShowcasesQueryOptions,
- getMyShowcaseVotesQueryOptions,
-} from '~/queries/showcases'
+import { showcasesMutations, showcasesQueries } from '~/queries/showcases'
import { useCurrentUser } from '~/hooks/useCurrentUser'
import { useLoginModal } from '~/contexts/LoginModalContext'
import { ShowcaseCard } from './ShowcaseCard'
@@ -36,10 +31,10 @@ export function ShowcaseDetail({ showcaseId }: ShowcaseDetailProps) {
const currentUser = useCurrentUser()
const { openLoginModal } = useLoginModal()
- const { data, isLoading } = useQuery(getShowcaseQueryOptions(showcaseId))
+ const { data, isLoading } = useQuery(showcasesQueries.detail(showcaseId))
const { data: relatedData } = useQuery({
- ...getRelatedShowcasesQueryOptions({
+ ...showcasesQueries.related({
showcaseId,
libraries: data?.showcase.libraries ?? [],
limit: 4,
@@ -48,7 +43,7 @@ export function ShowcaseDetail({ showcaseId }: ShowcaseDetailProps) {
})
const { data: votesData } = useQuery({
- ...getMyShowcaseVotesQueryOptions([showcaseId]),
+ ...showcasesQueries.myVotes([showcaseId]),
enabled: !!currentUser,
})
@@ -66,7 +61,7 @@ export function ShowcaseDetail({ showcaseId }: ShowcaseDetailProps) {
)
const { data: relatedVotesData } = useQuery({
- ...getMyShowcaseVotesQueryOptions(relatedShowcaseIds),
+ ...showcasesQueries.myVotes(relatedShowcaseIds),
enabled: !!currentUser && relatedShowcaseIds.length > 0,
})
@@ -81,21 +76,20 @@ export function ShowcaseDetail({ showcaseId }: ShowcaseDetailProps) {
}, [relatedVotesData])
const voteMutation = useMutation({
- mutationFn: (params: { showcaseId: string; value: 1 | -1 }) =>
- voteShowcase({ data: params }),
+ ...showcasesMutations.vote(),
onMutate: async ({ showcaseId: voteShowcaseId, value }) => {
- await queryClient.cancelQueries({ queryKey: ['showcases'] })
+ await queryClient.cancelQueries({ queryKey: showcasesQueries.all() })
const previousShowcase = queryClient.getQueryData(
- getShowcaseQueryOptions(showcaseId).queryKey,
+ showcasesQueries.detail(showcaseId).queryKey,
)
const previousVotes = queryClient.getQueryData(
- getMyShowcaseVotesQueryOptions([showcaseId]).queryKey,
+ showcasesQueries.myVotes([showcaseId]).queryKey,
)
// Optimistically update the vote
queryClient.setQueryData(
- getMyShowcaseVotesQueryOptions([showcaseId]).queryKey,
+ showcasesQueries.myVotes([showcaseId]).queryKey,
(old: typeof votesData) => {
if (!old) return { votes: [{ showcaseId: voteShowcaseId, value }] }
const existingVote = old.votes.find(
@@ -122,7 +116,7 @@ export function ShowcaseDetail({ showcaseId }: ShowcaseDetailProps) {
// Optimistically update the showcase score
if (voteShowcaseId === showcaseId) {
queryClient.setQueryData(
- getShowcaseQueryOptions(showcaseId).queryKey,
+ showcasesQueries.detail(showcaseId).queryKey,
(old: typeof data) => {
if (!old) return old
let scoreDelta: number = value
@@ -147,19 +141,19 @@ export function ShowcaseDetail({ showcaseId }: ShowcaseDetailProps) {
onError: (_err, _vars, context) => {
if (context?.previousShowcase) {
queryClient.setQueryData(
- getShowcaseQueryOptions(showcaseId).queryKey,
+ showcasesQueries.detail(showcaseId).queryKey,
context.previousShowcase,
)
}
if (context?.previousVotes) {
queryClient.setQueryData(
- getMyShowcaseVotesQueryOptions([showcaseId]).queryKey,
+ showcasesQueries.myVotes([showcaseId]).queryKey,
context.previousVotes,
)
}
},
onSettled: () => {
- queryClient.invalidateQueries({ queryKey: ['showcases'] })
+ queryClient.invalidateQueries({ queryKey: showcasesQueries.all() })
},
})
diff --git a/src/components/ShowcaseGallery.tsx b/src/components/ShowcaseGallery.tsx
index c6d588b29..d846ec73c 100644
--- a/src/components/ShowcaseGallery.tsx
+++ b/src/components/ShowcaseGallery.tsx
@@ -1,11 +1,7 @@
import * as React from 'react'
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { Link, useNavigate, useSearch } from '@tanstack/react-router'
-import {
- getApprovedShowcasesQueryOptions,
- getMyShowcaseVotesQueryOptions,
-} from '~/queries/showcases'
-import { voteShowcase } from '~/utils/showcase.functions'
+import { showcasesMutations, showcasesQueries } from '~/queries/showcases'
import { ShowcaseCard, ShowcaseCardSkeleton } from './ShowcaseCard'
import { CommunityProjectCard } from './CommunityProjectCard'
import { SubmitShowcasePlaceholder } from './ShowcaseSection'
@@ -38,7 +34,7 @@ export function ShowcaseGallery({
const pageSize = search.pageSize ?? 24
const { data, isLoading } = useQuery(
- getApprovedShowcasesQueryOptions({
+ showcasesQueries.approved({
pagination: {
page: search.page,
pageSize,
@@ -59,7 +55,7 @@ export function ShowcaseGallery({
)
const { data: votesData } = useQuery({
- ...getMyShowcaseVotesQueryOptions(showcaseIds),
+ ...showcasesQueries.myVotes(showcaseIds),
enabled: !community && !!currentUser && showcaseIds.length > 0,
})
@@ -74,15 +70,14 @@ export function ShowcaseGallery({
}, [votesData])
const voteMutation = useMutation({
- mutationFn: (params: { showcaseId: string; value: 1 | -1 }) =>
- voteShowcase({ data: params }),
+ ...showcasesMutations.vote(),
onMutate: async ({ showcaseId, value }) => {
// Cancel outgoing refetches
- await queryClient.cancelQueries({ queryKey: ['showcases'] })
+ await queryClient.cancelQueries({ queryKey: showcasesQueries.all() })
// Snapshot previous values
const previousShowcases = queryClient.getQueryData(
- getApprovedShowcasesQueryOptions({
+ showcasesQueries.approved({
pagination: { page: search.page, pageSize },
filters: {
placement,
@@ -94,12 +89,12 @@ export function ShowcaseGallery({
}).queryKey,
)
const previousVotes = queryClient.getQueryData(
- getMyShowcaseVotesQueryOptions(showcaseIds).queryKey,
+ showcasesQueries.myVotes(showcaseIds).queryKey,
)
// Optimistically update votes
queryClient.setQueryData(
- getMyShowcaseVotesQueryOptions(showcaseIds).queryKey,
+ showcasesQueries.myVotes(showcaseIds).queryKey,
(old: typeof votesData) => {
if (!old) return { votes: [{ showcaseId, value }] }
const existingVote = old.votes.find(
@@ -128,7 +123,7 @@ export function ShowcaseGallery({
// Optimistically update showcase score
queryClient.setQueryData(
- getApprovedShowcasesQueryOptions({
+ showcasesQueries.approved({
pagination: { page: search.page, pageSize },
filters: {
placement,
@@ -171,7 +166,7 @@ export function ShowcaseGallery({
// Rollback on error
if (context?.previousShowcases) {
queryClient.setQueryData(
- getApprovedShowcasesQueryOptions({
+ showcasesQueries.approved({
pagination: { page: search.page, pageSize },
filters: {
placement,
@@ -186,14 +181,14 @@ export function ShowcaseGallery({
}
if (context?.previousVotes) {
queryClient.setQueryData(
- getMyShowcaseVotesQueryOptions(showcaseIds).queryKey,
+ showcasesQueries.myVotes(showcaseIds).queryKey,
context.previousVotes,
)
}
},
onSettled: () => {
// Refetch to sync with server
- queryClient.invalidateQueries({ queryKey: ['showcases'] })
+ queryClient.invalidateQueries({ queryKey: showcasesQueries.all() })
},
})
diff --git a/src/components/ShowcaseModerationPage.tsx b/src/components/ShowcaseModerationPage.tsx
index 68024b685..08e35e554 100644
--- a/src/components/ShowcaseModerationPage.tsx
+++ b/src/components/ShowcaseModerationPage.tsx
@@ -1,12 +1,7 @@
import * as React from 'react'
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
import { useNavigate, useSearch } from '@tanstack/react-router'
-import { listShowcasesForModerationQueryOptions } from '~/queries/showcases'
-import {
- setShowcaseFeatured,
- adminDeleteShowcase,
- voteShowcase,
-} from '~/utils/showcase.functions'
+import { showcasesMutations, showcasesQueries } from '~/queries/showcases'
import { ShowcaseModerationTopBar } from './ShowcaseModerationTopBar'
import { ShowcaseModerationList } from './ShowcaseModerationList'
import { useToast } from '~/components/ToastProvider'
@@ -19,7 +14,7 @@ export function ShowcaseModerationPage() {
const { notify } = useToast()
const { data, isLoading, error } = useQuery(
- listShowcasesForModerationQueryOptions({
+ showcasesQueries.moderation({
pagination: {
page: search.page,
pageSize: search.pageSize,
@@ -34,7 +29,7 @@ export function ShowcaseModerationPage() {
)
const featuredMutation = useMutation({
- mutationFn: setShowcaseFeatured,
+ ...showcasesMutations.setFeatured(),
onSuccess: (_, variables) => {
notify(
@@ -45,7 +40,7 @@ export function ShowcaseModerationPage() {
,
)
- queryClient.invalidateQueries({ queryKey: ['showcases'] })
+ queryClient.invalidateQueries({ queryKey: showcasesQueries.all() })
},
onError: (error: Error) => {
notify(
@@ -60,14 +55,14 @@ export function ShowcaseModerationPage() {
})
const deleteMutation = useMutation({
- mutationFn: adminDeleteShowcase,
+ ...showcasesMutations.adminDelete(),
onSuccess: () => {
notify(
,
)
- queryClient.invalidateQueries({ queryKey: ['showcases'] })
+ queryClient.invalidateQueries({ queryKey: showcasesQueries.all() })
},
onError: (error: Error) => {
notify(
@@ -82,9 +77,9 @@ export function ShowcaseModerationPage() {
})
const voteMutation = useMutation({
- mutationFn: voteShowcase,
+ ...showcasesMutations.vote(),
onSuccess: () => {
- queryClient.invalidateQueries({ queryKey: ['showcases'] })
+ queryClient.invalidateQueries({ queryKey: showcasesQueries.all() })
},
})
@@ -130,9 +125,7 @@ export function ShowcaseModerationPage() {
}
const handleVote = (showcaseId: string, value: 1 | -1) => {
- voteMutation.mutate({
- data: { showcaseId, value },
- })
+ voteMutation.mutate({ showcaseId, value })
}
return (
diff --git a/src/components/ShowcaseSection.tsx b/src/components/ShowcaseSection.tsx
index 6c7d6b9f4..d222ba2e4 100644
--- a/src/components/ShowcaseSection.tsx
+++ b/src/components/ShowcaseSection.tsx
@@ -1,12 +1,7 @@
import * as React from 'react'
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { Link } from '@tanstack/react-router'
-import {
- getFeaturedShowcasesQueryOptions,
- getShowcasesByLibraryQueryOptions,
- getMyShowcaseVotesQueryOptions,
-} from '~/queries/showcases'
-import { voteShowcase } from '~/utils/showcase.functions'
+import { showcasesMutations, showcasesQueries } from '~/queries/showcases'
import { ShowcaseCard, ShowcaseCardSkeleton } from './ShowcaseCard'
import { Button } from '~/ui'
import { ArrowRightIcon, PlusIcon } from '@phosphor-icons/react'
@@ -69,8 +64,8 @@ export function ShowcaseSection({
const { openLoginModal } = useLoginModal()
const queryOptions = libraryId
- ? getShowcasesByLibraryQueryOptions({ libraryId, limit })
- : getFeaturedShowcasesQueryOptions({ limit })
+ ? showcasesQueries.byLibrary({ libraryId, limit })
+ : showcasesQueries.featured({ limit })
const { data, isLoading } = useQuery(queryOptions)
@@ -86,7 +81,7 @@ export function ShowcaseSection({
)
const { data: votesData } = useQuery({
- ...getMyShowcaseVotesQueryOptions(showcaseIds),
+ ...showcasesQueries.myVotes(showcaseIds),
enabled: !!currentUser && showcaseIds.length > 0,
})
@@ -101,19 +96,18 @@ export function ShowcaseSection({
}, [votesData])
const voteMutation = useMutation({
- mutationFn: (params: { showcaseId: string; value: 1 | -1 }) =>
- voteShowcase({ data: params }),
+ ...showcasesMutations.vote(),
onMutate: async ({ showcaseId, value }) => {
- await queryClient.cancelQueries({ queryKey: ['showcases'] })
+ await queryClient.cancelQueries({ queryKey: showcasesQueries.all() })
const previousShowcases = queryClient.getQueryData(queryOptions.queryKey)
const previousVotes = queryClient.getQueryData(
- getMyShowcaseVotesQueryOptions(showcaseIds).queryKey,
+ showcasesQueries.myVotes(showcaseIds).queryKey,
)
// Optimistically update votes
queryClient.setQueryData(
- getMyShowcaseVotesQueryOptions(showcaseIds).queryKey,
+ showcasesQueries.myVotes(showcaseIds).queryKey,
(old: typeof votesData) => {
if (!old) return { votes: [{ showcaseId, value }] }
const existingVote = old.votes.find(
@@ -173,13 +167,13 @@ export function ShowcaseSection({
}
if (context?.previousVotes) {
queryClient.setQueryData(
- getMyShowcaseVotesQueryOptions(showcaseIds).queryKey,
+ showcasesQueries.myVotes(showcaseIds).queryKey,
context.previousVotes,
)
}
},
onSettled: () => {
- queryClient.invalidateQueries({ queryKey: ['showcases'] })
+ queryClient.invalidateQueries({ queryKey: showcasesQueries.all() })
},
})
diff --git a/src/components/intent/SkillDiffViewer.tsx b/src/components/intent/SkillDiffViewer.tsx
index e48c484cf..ca4de7c0e 100644
--- a/src/components/intent/SkillDiffViewer.tsx
+++ b/src/components/intent/SkillDiffViewer.tsx
@@ -1,7 +1,7 @@
import * as React from 'react'
import { useQuery } from '@tanstack/react-query'
import { diffLines } from 'diff'
-import { intentSkillContentDiffQueryOptions } from '~/queries/intent'
+import { intentQueries } from '~/queries/intent'
export function SkillDiffViewer({
packageName,
@@ -15,7 +15,7 @@ export function SkillDiffViewer({
readonly toVersion: string
}) {
const diffQuery = useQuery(
- intentSkillContentDiffQueryOptions({
+ intentQueries.skillContentDiff({
packageName,
skillName,
fromVersion,
diff --git a/src/components/landing/LibraryLanding.tsx b/src/components/landing/LibraryLanding.tsx
index 7b7916c94..0f77dd81f 100644
--- a/src/components/landing/LibraryLanding.tsx
+++ b/src/components/landing/LibraryLanding.tsx
@@ -15,7 +15,7 @@ import { getLibrary } from '~/libraries'
import type { LibraryId } from '~/libraries'
import { PartnersSponsorsSection } from '~/components/PartnersSponsorsSection'
import { LibraryStatusBadge } from '~/components/LibraryStatusBadge'
-import { ossStatsQuery, recentDownloadsQuery } from '~/queries/stats'
+import { statsQueries } from '~/queries/stats'
import { LandingCopyPromptButton } from './LandingCopyPromptButton'
import { ChartsTextBackdrop } from './ChartsTextBackdrop'
@@ -619,8 +619,10 @@ function LandingWorkbench({
function LandingStats({ libraryId }: { libraryId: LibraryLandingId }) {
const library = getLibrary(libraryId)
- const { data: stats } = useQuery(ossStatsQuery({ library }))
- const { data: downloads } = useQuery(recentDownloadsQuery({ library }))
+ const { data: stats } = useQuery(statsQueries.ossSummary({ library }))
+ const { data: downloads } = useQuery(
+ statsQueries.recentDownloads({ library }),
+ )
const metrics = [
{
href: 'https://www.npmjs.com/org/tanstack',
diff --git a/src/components/npm-stats/NPMSummary.tsx b/src/components/npm-stats/NPMSummary.tsx
index cbde3e3e5..f71d53fbf 100644
--- a/src/components/npm-stats/NPMSummary.tsx
+++ b/src/components/npm-stats/NPMSummary.tsx
@@ -2,7 +2,7 @@ import * as React from 'react'
import { Suspense } from 'react'
import { useSuspenseQuery } from '@tanstack/react-query'
import { BlankErrorBoundary } from '~/components/BlankErrorBoundary'
-import { ossStatsQuery, recentDownloadsQuery } from '~/queries/stats'
+import { statsQueries } from '~/queries/stats'
import { useNpmDownloadCounter } from '~/hooks/useNpmDownloadCounter'
import type { Library } from '~/libraries'
@@ -85,11 +85,13 @@ function StatCard({
*/
function NPMSummaryContent({ library }: { library: Library }) {
// Fetch all-time stats (includes ratePerDay for animation)
- const { data: ossStats } = useSuspenseQuery(ossStatsQuery({ library }))
+ const { data: ossStats } = useSuspenseQuery(
+ statsQueries.ossSummary({ library }),
+ )
// Fetch recent download stats (daily, weekly, monthly)
const { data: recentStats } = useSuspenseQuery(
- recentDownloadsQuery({ library }),
+ statsQueries.recentDownloads({ library }),
)
return (
diff --git a/src/queries/docFeedback.ts b/src/queries/docFeedback.ts
index c36f9c714..a8b564049 100644
--- a/src/queries/docFeedback.ts
+++ b/src/queries/docFeedback.ts
@@ -1,9 +1,14 @@
-import { queryOptions } from '@tanstack/react-query'
+import { mutationOptions, queryOptions } from '@tanstack/react-query'
import {
+ createDocFeedback,
+ deleteDocFeedback,
+ getDocFeedbackForPage,
+ getDocFeedbackLeaderboard,
getUserDocFeedback,
listDocFeedbackForModeration,
- getDocFeedbackLeaderboard,
- getDocFeedbackForPage,
+ moderateDocFeedback,
+ updateDocFeedback,
+ updateDocFeedbackCollapsed,
} from '~/utils/docFeedback.functions'
import type { DocFeedbackStatus, DocFeedbackType } from '~/db/types'
@@ -22,42 +27,47 @@ export interface DocFeedbackPagination {
pageSize: number
}
-export const getUserDocFeedbackQueryOptions = (params: {
- pagination: DocFeedbackPagination
- filters?: {
- status?: DocFeedbackStatus[]
- libraryId?: string
- type?: DocFeedbackType[]
- }
-}) =>
- queryOptions({
- queryKey: ['docFeedback', 'user', params],
- queryFn: () => getUserDocFeedback({ data: params }),
- })
-
-export const listDocFeedbackForModerationQueryOptions = (params: {
- pagination: DocFeedbackPagination
- filters?: DocFeedbackFilters
-}) =>
- queryOptions({
- queryKey: ['docFeedback', 'moderation', params],
- queryFn: () => listDocFeedbackForModeration({ data: params }),
- staleTime: 0,
- })
-
-export const getDocFeedbackLeaderboardQueryOptions = (params: {
- pagination: DocFeedbackPagination
-}) =>
- queryOptions({
- queryKey: ['docFeedback', 'leaderboard', params],
- queryFn: () => getDocFeedbackLeaderboard({ data: params }),
- })
+export const docFeedbackQueries = {
+ all: () => ['docFeedback'],
+ user: (params: {
+ pagination: DocFeedbackPagination
+ filters?: {
+ status?: DocFeedbackStatus[]
+ libraryId?: string
+ type?: DocFeedbackType[]
+ }
+ }) =>
+ queryOptions({
+ queryKey: [...docFeedbackQueries.all(), 'user', params],
+ queryFn: () => getUserDocFeedback({ data: params }),
+ }),
+ moderations: () => [...docFeedbackQueries.all(), 'moderation'],
+ moderation: (params: {
+ pagination: DocFeedbackPagination
+ filters?: DocFeedbackFilters
+ }) =>
+ queryOptions({
+ queryKey: [...docFeedbackQueries.moderations(), params],
+ queryFn: () => listDocFeedbackForModeration({ data: params }),
+ staleTime: 0,
+ }),
+ leaderboard: (params: { pagination: DocFeedbackPagination }) =>
+ queryOptions({
+ queryKey: [...docFeedbackQueries.all(), 'leaderboard', params],
+ queryFn: () => getDocFeedbackLeaderboard({ data: params }),
+ }),
+ page: (params: { pagePath: string; libraryVersion: string }) =>
+ queryOptions({
+ queryKey: [...docFeedbackQueries.all(), 'page', params],
+ queryFn: () => getDocFeedbackForPage({ data: params }),
+ }),
+}
-export const getDocFeedbackForPageQueryOptions = (params: {
- pagePath: string
- libraryVersion: string
-}) =>
- queryOptions({
- queryKey: ['docFeedback', 'page', params],
- queryFn: () => getDocFeedbackForPage({ data: params }),
- })
+export const docFeedbackMutations = {
+ create: () => mutationOptions({ mutationFn: createDocFeedback }),
+ update: () => mutationOptions({ mutationFn: updateDocFeedback }),
+ delete: () => mutationOptions({ mutationFn: deleteDocFeedback }),
+ updateCollapsed: () =>
+ mutationOptions({ mutationFn: updateDocFeedbackCollapsed }),
+ moderate: () => mutationOptions({ mutationFn: moderateDocFeedback }),
+}
diff --git a/src/queries/docsConfig.ts b/src/queries/docsConfig.ts
index 3d75cf630..19c31c9f0 100644
--- a/src/queries/docsConfig.ts
+++ b/src/queries/docsConfig.ts
@@ -14,12 +14,14 @@ function getDocsConfigRequest(libraryId: LibraryId, version: string) {
}
}
-export function docsConfigQueryOptions(libraryId: LibraryId, version: string) {
- const request = getDocsConfigRequest(libraryId, version)
+export const docsConfigQueries = {
+ detail: (libraryId: LibraryId, version: string) => {
+ const request = getDocsConfigRequest(libraryId, version)
- return queryOptions({
- queryKey: ['docs-config', request.repo, request.branch, request.docsRoot],
- queryFn: () => getTanstackDocsConfig({ data: request }),
- staleTime: 1000 * 60 * 5,
- })
+ return queryOptions({
+ queryKey: ['docs-config', request.repo, request.branch, request.docsRoot],
+ queryFn: () => getTanstackDocsConfig({ data: request }),
+ staleTime: 1000 * 60 * 5,
+ })
+ },
}
diff --git a/src/queries/docsManifest.ts b/src/queries/docsManifest.ts
index 7d307e5db..16f2d3eba 100644
--- a/src/queries/docsManifest.ts
+++ b/src/queries/docsManifest.ts
@@ -1,16 +1,15 @@
import { queryOptions } from '@tanstack/react-query'
import { fetchDocsPathManifest } from '~/utils/docs.functions'
-export function docsPathManifestQueryOptions(request: {
- repo: string
- branch: string
- docsRoot: string
-}) {
- const { repo, branch, docsRoot } = request
+export const docsManifestQueries = {
+ paths: (request: { repo: string; branch: string; docsRoot: string }) => {
+ const { repo, branch, docsRoot } = request
- return queryOptions({
- queryKey: ['docs-path-manifest', repo, branch, docsRoot],
- queryFn: () => fetchDocsPathManifest({ data: { repo, branch, docsRoot } }),
- staleTime: 1000 * 60 * 5,
- })
+ return queryOptions({
+ queryKey: ['docs-path-manifest', repo, branch, docsRoot],
+ queryFn: () =>
+ fetchDocsPathManifest({ data: { repo, branch, docsRoot } }),
+ staleTime: 1000 * 60 * 5,
+ })
+ },
}
diff --git a/src/queries/intent.ts b/src/queries/intent.ts
index 026e51a2c..24dfb6917 100644
--- a/src/queries/intent.ts
+++ b/src/queries/intent.ts
@@ -12,95 +12,88 @@ import {
getIntentSkillContentDiff,
} from '~/utils/intent.functions'
-export const intentStatsQueryOptions = () =>
- queryOptions({
- queryKey: ['intent', 'stats'],
- queryFn: () => getIntentStats(),
- staleTime: 5 * 60 * 1000,
- })
-
-export const intentDirectoryQueryOptions = (params: {
- search?: string
- framework?: string
- sort?: 'downloads' | 'name' | 'skills' | 'newest'
- page?: number
- pageSize?: number
-}) =>
- queryOptions({
- queryKey: ['intent', 'directory', params],
- queryFn: () => getIntentDirectory({ data: params }),
- staleTime: 5 * 60 * 1000,
- })
-
-export const intentPackageDetailQueryOptions = (name: string) =>
- queryOptions({
- queryKey: ['intent', 'package', name],
- queryFn: () => getIntentPackageDetail({ data: { name } }),
- staleTime: 10 * 60 * 1000,
- })
-
-export const intentVersionSkillsQueryOptions = (params: {
- packageName: string
- version: string
-}) =>
- queryOptions({
- queryKey: ['intent', 'skills', params.packageName, params.version],
- queryFn: () => getIntentVersionSkills({ data: params }),
- staleTime: 30 * 60 * 1000,
- })
-
-export const intentSkillSearchQueryOptions = (query: string) =>
- queryOptions({
- queryKey: ['intent', 'skill-search', query],
- queryFn: () => searchIntentSkills({ data: { query } }),
- staleTime: 2 * 60 * 1000,
- enabled: query.trim().length > 0,
- })
-
-export const intentVersionDiffQueryOptions = (params: {
- packageName: string
- fromVersion: string
- toVersion: string
-}) =>
- queryOptions({
- queryKey: ['intent', 'diff', params],
- queryFn: () => diffIntentVersions({ data: params }),
- staleTime: 30 * 60 * 1000,
- })
-
-export const intentSkillHistoryQueryOptions = (packageNames: Array) =>
- queryOptions({
- queryKey: ['intent', 'skill-history', packageNames],
- queryFn: () => getIntentSkillHistory({ data: { packageNames } }),
- staleTime: 10 * 60 * 1000,
- enabled: packageNames.length > 0,
- })
-
-export const intentPackageChangelogQueryOptions = (packageName: string) =>
- queryOptions({
- queryKey: ['intent', 'changelog', packageName],
- queryFn: () => getIntentPackageChangelog({ data: { packageName } }),
- staleTime: 10 * 60 * 1000,
- })
-
-export const intentSingleSkillHistoryQueryOptions = (params: {
- packageName: string
- skillName: string
-}) =>
- queryOptions({
- queryKey: ['intent', 'single-skill-history', params],
- queryFn: () => getIntentSingleSkillHistory({ data: params }),
- staleTime: 10 * 60 * 1000,
- })
-
-export const intentSkillContentDiffQueryOptions = (params: {
- packageName: string
- skillName: string
- fromVersion: string
- toVersion: string
-}) =>
- queryOptions({
- queryKey: ['intent', 'skill-content-diff', params],
- queryFn: () => getIntentSkillContentDiff({ data: params }),
- staleTime: 30 * 60 * 1000,
- })
+export const intentQueries = {
+ all: () => ['intent'],
+ stats: () =>
+ queryOptions({
+ queryKey: [...intentQueries.all(), 'stats'],
+ queryFn: () => getIntentStats(),
+ staleTime: 5 * 60 * 1000,
+ }),
+ directory: (params: {
+ search?: string
+ framework?: string
+ sort?: 'downloads' | 'name' | 'skills' | 'newest'
+ page?: number
+ pageSize?: number
+ }) =>
+ queryOptions({
+ queryKey: [...intentQueries.all(), 'directory', params],
+ queryFn: () => getIntentDirectory({ data: params }),
+ staleTime: 5 * 60 * 1000,
+ }),
+ packageDetail: (name: string) =>
+ queryOptions({
+ queryKey: [...intentQueries.all(), 'package', name],
+ queryFn: () => getIntentPackageDetail({ data: { name } }),
+ staleTime: 10 * 60 * 1000,
+ }),
+ versionSkills: (params: { packageName: string; version: string }) =>
+ queryOptions({
+ queryKey: [
+ ...intentQueries.all(),
+ 'skills',
+ params.packageName,
+ params.version,
+ ],
+ queryFn: () => getIntentVersionSkills({ data: params }),
+ staleTime: 30 * 60 * 1000,
+ }),
+ skillSearch: (query: string) =>
+ queryOptions({
+ queryKey: [...intentQueries.all(), 'skill-search', query],
+ queryFn: () => searchIntentSkills({ data: { query } }),
+ staleTime: 2 * 60 * 1000,
+ enabled: query.trim().length > 0,
+ }),
+ versionDiff: (params: {
+ packageName: string
+ fromVersion: string
+ toVersion: string
+ }) =>
+ queryOptions({
+ queryKey: [...intentQueries.all(), 'diff', params],
+ queryFn: () => diffIntentVersions({ data: params }),
+ staleTime: 30 * 60 * 1000,
+ }),
+ skillHistory: (packageNames: Array) =>
+ queryOptions({
+ queryKey: [...intentQueries.all(), 'skill-history', packageNames],
+ queryFn: () => getIntentSkillHistory({ data: { packageNames } }),
+ staleTime: 10 * 60 * 1000,
+ enabled: packageNames.length > 0,
+ }),
+ packageChangelog: (packageName: string) =>
+ queryOptions({
+ queryKey: [...intentQueries.all(), 'changelog', packageName],
+ queryFn: () => getIntentPackageChangelog({ data: { packageName } }),
+ staleTime: 10 * 60 * 1000,
+ }),
+ singleSkillHistory: (params: { packageName: string; skillName: string }) =>
+ queryOptions({
+ queryKey: [...intentQueries.all(), 'single-skill-history', params],
+ queryFn: () => getIntentSingleSkillHistory({ data: params }),
+ staleTime: 10 * 60 * 1000,
+ }),
+ skillContentDiff: (params: {
+ packageName: string
+ skillName: string
+ fromVersion: string
+ toVersion: string
+ }) =>
+ queryOptions({
+ queryKey: [...intentQueries.all(), 'skill-content-diff', params],
+ queryFn: () => getIntentSkillContentDiff({ data: params }),
+ staleTime: 30 * 60 * 1000,
+ }),
+}
diff --git a/src/queries/roles.ts b/src/queries/roles.ts
index 266da7c06..f5eeec0d4 100644
--- a/src/queries/roles.ts
+++ b/src/queries/roles.ts
@@ -11,22 +11,22 @@ export interface ListRolesFilters {
capabilityFilter?: Capability[]
}
-export const listRolesQueryOptions = (filters?: ListRolesFilters) =>
- queryOptions({
- queryKey: ['admin', 'roles', filters],
- queryFn: () => listRoles({ data: filters || {} }),
- })
-
-export const getBulkUserRolesQueryOptions = (userIds: string[]) =>
- queryOptions({
- queryKey: ['admin', 'bulkUserRoles', userIds],
- queryFn: () => getBulkUserRoles({ data: { userIds } }),
- enabled: userIds.length > 0,
- })
-
-export const getBulkEffectiveCapabilitiesQueryOptions = (userIds: string[]) =>
- queryOptions({
- queryKey: ['admin', 'bulkEffectiveCapabilities', userIds],
- queryFn: () => getBulkEffectiveCapabilities({ data: { userIds } }),
- enabled: userIds.length > 0,
- })
+export const rolesQueries = {
+ list: (filters?: ListRolesFilters) =>
+ queryOptions({
+ queryKey: ['admin', 'roles', filters],
+ queryFn: () => listRoles({ data: filters || {} }),
+ }),
+ bulkUserRoles: (userIds: string[]) =>
+ queryOptions({
+ queryKey: ['admin', 'bulkUserRoles', userIds],
+ queryFn: () => getBulkUserRoles({ data: { userIds } }),
+ enabled: userIds.length > 0,
+ }),
+ bulkEffectiveCapabilities: (userIds: string[]) =>
+ queryOptions({
+ queryKey: ['admin', 'bulkEffectiveCapabilities', userIds],
+ queryFn: () => getBulkEffectiveCapabilities({ data: { userIds } }),
+ enabled: userIds.length > 0,
+ }),
+}
diff --git a/src/queries/showcases.ts b/src/queries/showcases.ts
index 2542984ca..b14a23e84 100644
--- a/src/queries/showcases.ts
+++ b/src/queries/showcases.ts
@@ -1,13 +1,17 @@
-import { queryOptions } from '@tanstack/react-query'
+import { mutationOptions, queryOptions } from '@tanstack/react-query'
import {
- getMyShowcases,
+ adminDeleteShowcase,
+ deleteShowcase,
getApprovedShowcases,
- getShowcasesByLibrary,
getFeaturedShowcases,
- listShowcasesForModeration,
- getShowcase,
+ getMyShowcases,
getMyShowcaseVotes,
getRelatedShowcases,
+ getShowcase,
+ getShowcasesByLibrary,
+ listShowcasesForModeration,
+ setShowcaseFeatured,
+ voteShowcase,
} from '~/utils/showcase.functions'
import type { ShowcaseStatus, ShowcaseUseCase } from '~/db/types'
@@ -26,85 +30,94 @@ export interface ShowcaseFilters {
featured?: boolean
}
-export const getMyShowcasesQueryOptions = (params: {
- pagination: ShowcasePagination
-}) =>
- queryOptions({
- queryKey: ['showcases', 'mine', params],
- queryFn: () => getMyShowcases({ data: params }),
- })
-
-export const getApprovedShowcasesQueryOptions = (params: {
- pagination: ShowcasePagination
- filters?: {
- placement?: 'showcase' | 'community'
- libraryIds?: string[]
- useCases?: ShowcaseUseCase[]
- featured?: boolean
- hasSourceCode?: boolean
- q?: string
- }
-}) =>
- queryOptions({
- queryKey: ['showcases', 'approved', params],
- queryFn: () => getApprovedShowcases({ data: params }),
- })
-
-export const getShowcasesByLibraryQueryOptions = (params: {
- libraryId: string
- limit?: number
-}) =>
- queryOptions({
- queryKey: ['showcases', 'library', params.libraryId, params.limit],
- queryFn: () =>
- getShowcasesByLibrary({
- data: { libraryId: params.libraryId, limit: params.limit ?? 6 },
- }),
- })
-
-export const getFeaturedShowcasesQueryOptions = (params: { limit?: number }) =>
- queryOptions({
- queryKey: ['showcases', 'featured', params.limit],
- queryFn: () => getFeaturedShowcases({ data: { limit: params.limit ?? 6 } }),
- })
-
-export const listShowcasesForModerationQueryOptions = (params: {
- pagination: ShowcasePagination
- filters?: ShowcaseFilters
-}) =>
- queryOptions({
- queryKey: ['showcases', 'moderation', params],
- queryFn: () => listShowcasesForModeration({ data: params }),
- staleTime: 0,
- })
-
-export const getShowcaseQueryOptions = (showcaseId: string) =>
- queryOptions({
- queryKey: ['showcases', 'detail', showcaseId],
- queryFn: () => getShowcase({ data: { showcaseId } }),
- })
-
-export const getMyShowcaseVotesQueryOptions = (showcaseIds: string[]) =>
- queryOptions({
- queryKey: ['showcases', 'votes', 'mine', showcaseIds],
- queryFn: () => getMyShowcaseVotes({ data: { showcaseIds } }),
- enabled: showcaseIds.length > 0,
- })
+export const showcasesQueries = {
+ all: () => ['showcases'],
+ mine: () => [...showcasesQueries.all(), 'mine'],
+ mineList: (params: { pagination: ShowcasePagination }) =>
+ queryOptions({
+ queryKey: [...showcasesQueries.mine(), params],
+ queryFn: () => getMyShowcases({ data: params }),
+ }),
+ approved: (params: {
+ pagination: ShowcasePagination
+ filters?: {
+ placement?: 'showcase' | 'community'
+ libraryIds?: string[]
+ useCases?: ShowcaseUseCase[]
+ featured?: boolean
+ hasSourceCode?: boolean
+ q?: string
+ }
+ }) =>
+ queryOptions({
+ queryKey: [...showcasesQueries.all(), 'approved', params],
+ queryFn: () => getApprovedShowcases({ data: params }),
+ }),
+ byLibrary: (params: { libraryId: string; limit?: number }) =>
+ queryOptions({
+ queryKey: [
+ ...showcasesQueries.all(),
+ 'library',
+ params.libraryId,
+ params.limit,
+ ],
+ queryFn: () =>
+ getShowcasesByLibrary({
+ data: { libraryId: params.libraryId, limit: params.limit ?? 6 },
+ }),
+ }),
+ featured: (params: { limit?: number }) =>
+ queryOptions({
+ queryKey: [...showcasesQueries.all(), 'featured', params.limit],
+ queryFn: () =>
+ getFeaturedShowcases({ data: { limit: params.limit ?? 6 } }),
+ }),
+ moderation: (params: {
+ pagination: ShowcasePagination
+ filters?: ShowcaseFilters
+ }) =>
+ queryOptions({
+ queryKey: [...showcasesQueries.all(), 'moderation', params],
+ queryFn: () => listShowcasesForModeration({ data: params }),
+ staleTime: 0,
+ }),
+ detail: (showcaseId: string) =>
+ queryOptions({
+ queryKey: [...showcasesQueries.all(), 'detail', showcaseId],
+ queryFn: () => getShowcase({ data: { showcaseId } }),
+ }),
+ myVotes: (showcaseIds: string[]) =>
+ queryOptions({
+ queryKey: [...showcasesQueries.all(), 'votes', 'mine', showcaseIds],
+ queryFn: () => getMyShowcaseVotes({ data: { showcaseIds } }),
+ enabled: showcaseIds.length > 0,
+ }),
+ related: (params: {
+ showcaseId: string
+ libraries: string[]
+ limit?: number
+ }) =>
+ queryOptions({
+ queryKey: [...showcasesQueries.all(), 'related', params.showcaseId],
+ queryFn: () =>
+ getRelatedShowcases({
+ data: {
+ showcaseId: params.showcaseId,
+ libraries: params.libraries,
+ limit: params.limit ?? 4,
+ },
+ }),
+ enabled: params.libraries.length > 0,
+ }),
+}
-export const getRelatedShowcasesQueryOptions = (params: {
- showcaseId: string
- libraries: string[]
- limit?: number
-}) =>
- queryOptions({
- queryKey: ['showcases', 'related', params.showcaseId],
- queryFn: () =>
- getRelatedShowcases({
- data: {
- showcaseId: params.showcaseId,
- libraries: params.libraries,
- limit: params.limit ?? 4,
- },
- }),
- enabled: params.libraries.length > 0,
- })
+export const showcasesMutations = {
+ vote: () =>
+ mutationOptions({
+ mutationFn: (params: { showcaseId: string; value: 1 | -1 }) =>
+ voteShowcase({ data: params }),
+ }),
+ setFeatured: () => mutationOptions({ mutationFn: setShowcaseFeatured }),
+ delete: () => mutationOptions({ mutationFn: deleteShowcase }),
+ adminDelete: () => mutationOptions({ mutationFn: adminDeleteShowcase }),
+}
diff --git a/src/queries/stats.ts b/src/queries/stats.ts
index f0261a81a..37ff02f61 100644
--- a/src/queries/stats.ts
+++ b/src/queries/stats.ts
@@ -12,51 +12,46 @@ export type { StatsQueryParams } from '~/utils/stats-queries.functions'
type StatsQueryLibrary = NonNullable
type RecentDownloadsLibrary = StatsQueryLibrary
-export const ossStatsQueryOptions = (params?: StatsQueryParams) =>
- queryOptions({
- queryKey: ['stats', 'oss', params],
- queryFn: () => getOSSStats({ data: { library: params?.library } }),
- staleTime: 1000 * 60 * 15, // Cache for 15 minutes
- })
+export const statsQueries = {
+ all: () => ['stats'],
+ oss: () => [...statsQueries.all(), 'oss'],
+ ossSummary: ({ library }: { library?: StatsQueryLibrary } = {}) => {
+ const params: StatsQueryParams = {
+ library: library
+ ? {
+ id: library.id,
+ npmPackageNames: library.npmPackageNames,
+ repo: library.repo,
+ frameworks: library.frameworks,
+ }
+ : undefined,
+ }
-export const homepageNpmStatsSummaryQuery = () =>
- queryOptions({
- queryKey: ['stats', 'homepage-npm-summary'],
- queryFn: () => getHomepageNpmStatsSummary(),
- staleTime: 1000 * 60 * 15,
- })
+ return queryOptions({
+ queryKey: [...statsQueries.oss(), params],
+ queryFn: () => getOSSStats({ data: { library: params.library } }),
+ staleTime: 1000 * 60 * 15, // Cache for 15 minutes
+ })
+ },
+ homepageNpmSummary: () =>
+ queryOptions({
+ queryKey: [...statsQueries.all(), 'homepage-npm-summary'],
+ queryFn: () => getHomepageNpmStatsSummary(),
+ staleTime: 1000 * 60 * 15,
+ }),
+ recentDownloads: ({ library }: { library: RecentDownloadsLibrary }) => {
+ const queryLibrary = {
+ id: library.id,
+ npmPackageNames: library.npmPackageNames,
+ repo: library.repo,
+ frameworks: library.frameworks,
+ }
-export function ossStatsQuery({
- library,
-}: { library?: StatsQueryLibrary } = {}) {
- return ossStatsQueryOptions({
- library: library
- ? {
- id: library.id,
- npmPackageNames: library.npmPackageNames,
- repo: library.repo,
- frameworks: library.frameworks,
- }
- : undefined,
- })
-}
-
-export function recentDownloadsQuery({
- library,
-}: {
- library: RecentDownloadsLibrary
-}) {
- const queryLibrary = {
- id: library.id,
- npmPackageNames: library.npmPackageNames,
- repo: library.repo,
- frameworks: library.frameworks,
- }
-
- return queryOptions({
- queryKey: ['npm-recent-downloads', queryLibrary],
- queryFn: (): Promise =>
- fetchRecentDownloadStats({ data: { library: queryLibrary } }),
- staleTime: 5 * 60 * 1000,
- })
+ return queryOptions({
+ queryKey: ['npm-recent-downloads', queryLibrary],
+ queryFn: (): Promise =>
+ fetchRecentDownloadStats({ data: { library: queryLibrary } }),
+ staleTime: 5 * 60 * 1000,
+ })
+ },
}
diff --git a/src/queries/users.ts b/src/queries/users.ts
index 9eaa44867..67975b7e7 100644
--- a/src/queries/users.ts
+++ b/src/queries/users.ts
@@ -18,9 +18,11 @@ export interface ListUsersFilters {
sortDir?: 'asc' | 'desc'
}
-export const listUsersQueryOptions = (filters: ListUsersFilters) =>
- queryOptions({
- queryKey: ['admin', 'users', filters],
- queryFn: () => listUsers({ data: filters }),
- staleTime: 0,
- })
+export const usersQueries = {
+ list: (filters: ListUsersFilters) =>
+ queryOptions({
+ queryKey: ['admin', 'users', filters],
+ queryFn: () => listUsers({ data: filters }),
+ staleTime: 0,
+ }),
+}
diff --git a/src/routes/-library-landing-route.tsx b/src/routes/-library-landing-route.tsx
index e85111c74..7a5231fbb 100644
--- a/src/routes/-library-landing-route.tsx
+++ b/src/routes/-library-landing-route.tsx
@@ -3,8 +3,8 @@ import { redirect } from '@tanstack/react-router'
import type { QueryClient } from '@tanstack/react-query'
import { getLibrary } from '~/libraries'
import type { LibraryId } from '~/libraries'
-import { docsConfigQueryOptions } from '~/queries/docsConfig'
-import { ossStatsQuery, recentDownloadsQuery } from '~/queries/stats'
+import { docsConfigQueries } from '~/queries/docsConfig'
+import { statsQueries } from '~/queries/stats'
import { ogImageUrl } from '~/utils/og'
import { seo } from '~/utils/seo'
import { stackBlitzEmbedHeaders } from '~/utils/stackblitz-embed'
@@ -44,14 +44,16 @@ export async function loadLibraryLandingRouteData(
}> {
const library = getLibrary(libraryId)
const configPromise = queryClient.ensureQueryData(
- docsConfigQueryOptions(libraryId, version),
+ docsConfigQueries.detail(libraryId, version),
)
const statsPromise =
library.statsAvailable === false
? Promise.resolve()
: Promise.all([
- queryClient.ensureQueryData(ossStatsQuery({ library })),
- queryClient.ensureQueryData(recentDownloadsQuery({ library })),
+ queryClient.ensureQueryData(statsQueries.ossSummary({ library })),
+ queryClient.ensureQueryData(
+ statsQueries.recentDownloads({ library }),
+ ),
]).then(() => undefined)
const [config] = await Promise.all([configPromise, statsPromise])
diff --git a/src/routes/_library/$libraryId/$version.tsx b/src/routes/_library/$libraryId/$version.tsx
index 661f89e0e..5b2bd4a60 100644
--- a/src/routes/_library/$libraryId/$version.tsx
+++ b/src/routes/_library/$libraryId/$version.tsx
@@ -6,7 +6,7 @@ import {
} from '@tanstack/react-router'
import { RedirectVersionBanner } from '~/components/RedirectVersionBanner'
import { findLibrary } from '~/libraries'
-import { docsConfigQueryOptions } from '~/queries/docsConfig'
+import { docsConfigQueries } from '~/queries/docsConfig'
import { validateLibraryVersion } from '../../-library-landing'
export const Route = createFileRoute('/_library/$libraryId/$version')({
@@ -49,7 +49,7 @@ export const Route = createFileRoute('/_library/$libraryId/$version')({
return {
config: await ctx.context.queryClient.ensureQueryData(
- docsConfigQueryOptions(library.id, version!),
+ docsConfigQueries.detail(library.id, version!),
),
}
},
diff --git a/src/routes/_library/charts.catalog.tsx b/src/routes/_library/charts.catalog.tsx
index 040b4e305..5e3b05626 100644
--- a/src/routes/_library/charts.catalog.tsx
+++ b/src/routes/_library/charts.catalog.tsx
@@ -1,11 +1,11 @@
import { Outlet, createFileRoute } from '@tanstack/react-router'
-import { docsConfigQueryOptions } from '~/queries/docsConfig'
+import { docsConfigQueries } from '~/queries/docsConfig'
export const Route = createFileRoute('/_library/charts/catalog')({
staleTime: 1000 * 60 * 5,
loader: async ({ context: { queryClient } }) => ({
config: await queryClient.ensureQueryData(
- docsConfigQueryOptions('charts', 'latest'),
+ docsConfigQueries.detail('charts', 'latest'),
),
version: 'latest',
}),
diff --git a/src/routes/_library/highlight.$version.theme-editor.tsx b/src/routes/_library/highlight.$version.theme-editor.tsx
index dad771ba7..32d6aac89 100644
--- a/src/routes/_library/highlight.$version.theme-editor.tsx
+++ b/src/routes/_library/highlight.$version.theme-editor.tsx
@@ -1,5 +1,5 @@
import { createFileRoute, redirect } from '@tanstack/react-router'
-import { docsConfigQueryOptions } from '~/queries/docsConfig'
+import { docsConfigQueries } from '~/queries/docsConfig'
import { ThemeEditorPage } from '~/components/highlight-theme-editor/ThemeEditorPage'
import { validateLibraryVersion } from '../-library-landing'
@@ -20,7 +20,7 @@ export const Route = createFileRoute(
loader: async ({ params, context: { queryClient } }) => {
return {
config: await queryClient.ensureQueryData(
- docsConfigQueryOptions('highlight', params.version),
+ docsConfigQueries.detail('highlight', params.version),
),
}
},
diff --git a/src/routes/account/feedback.tsx b/src/routes/account/feedback.tsx
index ffc3b7737..ac81a8133 100644
--- a/src/routes/account/feedback.tsx
+++ b/src/routes/account/feedback.tsx
@@ -1,7 +1,7 @@
import * as React from 'react'
import { Link, createFileRoute } from '@tanstack/react-router'
import { useQuery } from '@tanstack/react-query'
-import { getUserDocFeedbackQueryOptions } from '~/queries/docFeedback'
+import { docFeedbackQueries } from '~/queries/docFeedback'
import { PaginationControls } from '~/components/PaginationControls'
import { useCurrentUserQuery } from '~/hooks/useCurrentUser'
import { DocFeedbackNote } from '~/components/DocFeedbackNote'
@@ -22,7 +22,7 @@ function AccountFeedbackPage() {
user && typeof user === 'object' && 'userId' in user ? user.userId : null
const { data, isLoading } = useQuery(
- getUserDocFeedbackQueryOptions({
+ docFeedbackQueries.user({
pagination: { page, pageSize },
filters: { type: ['improvement'] },
}),
diff --git a/src/routes/account/notes.tsx b/src/routes/account/notes.tsx
index e3ce540ca..bb8331b1d 100644
--- a/src/routes/account/notes.tsx
+++ b/src/routes/account/notes.tsx
@@ -1,7 +1,7 @@
import * as React from 'react'
import { Link, createFileRoute } from '@tanstack/react-router'
import { useQuery } from '@tanstack/react-query'
-import { getUserDocFeedbackQueryOptions } from '~/queries/docFeedback'
+import { docFeedbackQueries } from '~/queries/docFeedback'
import { PaginationControls } from '~/components/PaginationControls'
import { useCurrentUserQuery } from '~/hooks/useCurrentUser'
import { DocFeedbackNote } from '~/components/DocFeedbackNote'
@@ -22,7 +22,7 @@ function AccountNotesPage() {
user && typeof user === 'object' && 'userId' in user ? user.userId : null
const { data, isLoading } = useQuery(
- getUserDocFeedbackQueryOptions({
+ docFeedbackQueries.user({
pagination: { page, pageSize },
filters: { type: ['note'] },
}),
diff --git a/src/routes/account/submissions.tsx b/src/routes/account/submissions.tsx
index 368080135..885d065f1 100644
--- a/src/routes/account/submissions.tsx
+++ b/src/routes/account/submissions.tsx
@@ -2,8 +2,7 @@ import { PLACEMENT_LABELS } from '~/utils/showcase.shared'
import * as React from 'react'
import { Link, createFileRoute } from '@tanstack/react-router'
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
-import { getMyShowcasesQueryOptions } from '~/queries/showcases'
-import { deleteShowcase } from '~/utils/showcase.functions'
+import { showcasesMutations, showcasesQueries } from '~/queries/showcases'
import { libraries } from '~/libraries'
import { useToast } from '~/components/ToastProvider'
import { seo } from '~/utils/seo'
@@ -22,7 +21,7 @@ import { Badge, Button } from '~/ui'
export const Route = createFileRoute('/account/submissions')({
loader: async ({ context: { queryClient } }) => {
await queryClient.ensureQueryData(
- getMyShowcasesQueryOptions({
+ showcasesQueries.mineList({
pagination: { page: 1, pageSize: 20 },
}),
)
@@ -43,20 +42,20 @@ function AccountSubmissionsPage() {
const { notify } = useToast()
const { data, isLoading } = useQuery(
- getMyShowcasesQueryOptions({
+ showcasesQueries.mineList({
pagination: { page: 1, pageSize: 20 },
}),
)
const deleteMutation = useMutation({
- mutationFn: deleteShowcase,
+ ...showcasesMutations.delete(),
onSuccess: () => {
notify(
,
)
- queryClient.invalidateQueries({ queryKey: ['showcases', 'mine'] })
+ queryClient.invalidateQueries({ queryKey: showcasesQueries.mine() })
},
onError: (error: Error) => {
notify(
diff --git a/src/routes/admin/feedback.index.tsx b/src/routes/admin/feedback.index.tsx
index f14256b3f..312930bbb 100644
--- a/src/routes/admin/feedback.index.tsx
+++ b/src/routes/admin/feedback.index.tsx
@@ -2,7 +2,7 @@ import { redirect, createFileRoute } from '@tanstack/react-router'
import * as v from 'valibot'
import { seo } from '~/utils/seo'
import { FeedbackModerationPage } from '~/components/FeedbackModerationPage'
-import { listDocFeedbackForModerationQueryOptions } from '~/queries/docFeedback'
+import { docFeedbackQueries } from '~/queries/docFeedback'
import { requireCapability } from '~/utils/auth.functions'
import {
libraryIdSchema,
@@ -46,7 +46,7 @@ export const Route = createFileRoute('/admin/feedback/')({
}),
loader: async ({ deps, context: { queryClient } }) => {
await queryClient.ensureQueryData(
- listDocFeedbackForModerationQueryOptions({
+ docFeedbackQueries.moderation({
pagination: {
page: deps.page,
pageSize: deps.pageSize,
diff --git a/src/routes/admin/feedback_.$id.tsx b/src/routes/admin/feedback_.$id.tsx
index ae87b458e..18449f2d9 100644
--- a/src/routes/admin/feedback_.$id.tsx
+++ b/src/routes/admin/feedback_.$id.tsx
@@ -5,6 +5,7 @@ import {
moderateDocFeedback,
} from '~/utils/docFeedback.functions'
import { libraries } from '~/libraries'
+import { docFeedbackQueries } from '~/queries/docFeedback'
import {
ArrowLeftIcon,
ChatCenteredIcon,
@@ -47,7 +48,9 @@ function FeedbackDetailPage() {
}),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['admin', 'feedback', id] })
- queryClient.invalidateQueries({ queryKey: ['docFeedback', 'moderation'] })
+ queryClient.invalidateQueries({
+ queryKey: docFeedbackQueries.moderations(),
+ })
},
})
diff --git a/src/routes/admin/notes.index.tsx b/src/routes/admin/notes.index.tsx
index d5681537c..2641d394b 100644
--- a/src/routes/admin/notes.index.tsx
+++ b/src/routes/admin/notes.index.tsx
@@ -2,7 +2,7 @@ import { redirect, createFileRoute } from '@tanstack/react-router'
import * as v from 'valibot'
import { seo } from '~/utils/seo'
import { NotesModerationPage } from '~/components/NotesModerationPage'
-import { listDocFeedbackForModerationQueryOptions } from '~/queries/docFeedback'
+import { docFeedbackQueries } from '~/queries/docFeedback'
import { requireCapability } from '~/utils/auth.functions'
import {
isoDateSchema,
@@ -48,7 +48,7 @@ export const Route = createFileRoute('/admin/notes/')({
}),
loader: async ({ deps, context: { queryClient } }) => {
await queryClient.ensureQueryData(
- listDocFeedbackForModerationQueryOptions({
+ docFeedbackQueries.moderation({
pagination: {
page: deps.page,
pageSize: deps.pageSize,
diff --git a/src/routes/admin/npm-stats.tsx b/src/routes/admin/npm-stats.tsx
index f81787f96..492cd07f3 100644
--- a/src/routes/admin/npm-stats.tsx
+++ b/src/routes/admin/npm-stats.tsx
@@ -3,7 +3,7 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { DownloadIcon, ArrowsClockwiseIcon } from '@phosphor-icons/react'
import { Card } from '~/components/Card'
import { NpmIcon } from '~/components/icons/NpmIcon'
-import { homepageNpmStatsSummaryQuery } from '~/queries/stats'
+import { statsQueries } from '~/queries/stats'
import { Button } from '~/ui'
import { refreshAllNpmStats } from '~/utils/stats-admin.functions'
import { formatDistanceToNow } from '~/utils/dates'
@@ -15,16 +15,16 @@ export const Route = createFileRoute('/admin/npm-stats')({
function NpmStatsAdmin() {
const queryClient = useQueryClient()
const { data: homepageSummary, isLoading: homepageSummaryLoading } = useQuery(
- homepageNpmStatsSummaryQuery(),
+ statsQueries.homepageNpmSummary(),
)
const refreshSummaryMutation = useMutation({
mutationFn: () => refreshAllNpmStats({ data: { org: 'tanstack' } }),
onSuccess: () => {
queryClient.invalidateQueries({
- queryKey: ['stats', 'homepage-npm-summary'],
+ queryKey: statsQueries.homepageNpmSummary().queryKey,
})
- queryClient.invalidateQueries({ queryKey: ['stats', 'oss'] })
+ queryClient.invalidateQueries({ queryKey: statsQueries.oss() })
},
})
diff --git a/src/routes/admin/showcases.index.tsx b/src/routes/admin/showcases.index.tsx
index 884d9e9a4..7eed68459 100644
--- a/src/routes/admin/showcases.index.tsx
+++ b/src/routes/admin/showcases.index.tsx
@@ -2,7 +2,7 @@ import { redirect, createFileRoute } from '@tanstack/react-router'
import * as v from 'valibot'
import { seo } from '~/utils/seo'
import { ShowcaseModerationPage } from '~/components/ShowcaseModerationPage'
-import { listShowcasesForModerationQueryOptions } from '~/queries/showcases'
+import { showcasesQueries } from '~/queries/showcases'
import { requireCapability } from '~/utils/auth.functions'
import {
libraryIdSchema,
@@ -44,7 +44,7 @@ export const Route = createFileRoute('/admin/showcases/')({
}),
loader: async ({ deps, context: { queryClient } }) => {
await queryClient.ensureQueryData(
- listShowcasesForModerationQueryOptions({
+ showcasesQueries.moderation({
pagination: {
page: deps.page,
pageSize: deps.pageSize,
diff --git a/src/routes/admin/showcases_.$id.tsx b/src/routes/admin/showcases_.$id.tsx
index 3f4862acb..0d55a8ed6 100644
--- a/src/routes/admin/showcases_.$id.tsx
+++ b/src/routes/admin/showcases_.$id.tsx
@@ -10,6 +10,7 @@ import {
voteShowcase,
} from '~/utils/showcase.functions'
import { libraries } from '~/libraries'
+import { showcasesQueries } from '~/queries/showcases'
import { USE_CASE_LABELS, PLACEMENT_LABELS } from '~/utils/showcase.shared'
import {
ArrowLeftIcon,
@@ -77,7 +78,7 @@ function ShowcaseDetailPage() {
adminUpdateShowcase({ data }),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['admin', 'showcase', id] })
- queryClient.invalidateQueries({ queryKey: ['showcases'] })
+ queryClient.invalidateQueries({ queryKey: showcasesQueries.all() })
setIsEditing(false)
setFormData(null)
},
@@ -86,7 +87,7 @@ function ShowcaseDetailPage() {
const deleteMutation = useMutation({
mutationFn: () => adminDeleteShowcase({ data: { showcaseId: id } }),
onSuccess: () => {
- queryClient.invalidateQueries({ queryKey: ['showcases'] })
+ queryClient.invalidateQueries({ queryKey: showcasesQueries.all() })
navigate({ to: '/admin/showcases' })
},
})
@@ -96,7 +97,7 @@ function ShowcaseDetailPage() {
voteShowcase({ data: { showcaseId: id, value: params.value } }),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['admin', 'showcase', id] })
- queryClient.invalidateQueries({ queryKey: ['showcases'] })
+ queryClient.invalidateQueries({ queryKey: showcasesQueries.all() })
},
})
diff --git a/src/routes/admin/users.tsx b/src/routes/admin/users.tsx
index 7bd83558c..e8fed71f7 100644
--- a/src/routes/admin/users.tsx
+++ b/src/routes/admin/users.tsx
@@ -34,12 +34,8 @@ import {
type SignupSource,
} from '~/db/types'
import * as v from 'valibot'
-import { listUsersQueryOptions } from '~/queries/users'
-import {
- listRolesQueryOptions,
- getBulkUserRolesQueryOptions,
- getBulkEffectiveCapabilitiesQueryOptions,
-} from '~/queries/roles'
+import { usersQueries } from '~/queries/users'
+import { rolesQueries } from '~/queries/roles'
import { getUserRoles } from '~/utils/roles.functions'
import {
FloppyDiskIcon,
@@ -287,7 +283,7 @@ function UsersPage() {
const pageSize = search.pageSize ?? 10
const usersQuery = useQuery({
- ...listUsersQueryOptions({
+ ...usersQueries.list({
pagination: {
limit: pageSize,
page: currentPageIndex,
@@ -316,7 +312,7 @@ function UsersPage() {
const bulkAssignRolesToUsers = useBulkAssignRolesToUsers()
const bulkUpdateUserCapabilities = useBulkUpdateUserCapabilities()
const allRolesQuery = useQuery({
- ...listRolesQueryOptions({}),
+ ...rolesQueries.list({}),
placeholderData: keepPreviousData,
})
const allRoles = useMemo(() => allRolesQuery.data || [], [allRolesQuery.data])
@@ -327,12 +323,12 @@ function UsersPage() {
[usersQuery?.data?.page],
)
const bulkUserRolesQuery = useQuery({
- ...getBulkUserRolesQueryOptions(userIds),
+ ...rolesQueries.bulkUserRoles(userIds),
placeholderData: keepPreviousData,
})
const bulkUserRoles = bulkUserRolesQuery.data
const bulkEffectiveCapabilitiesQuery = useQuery({
- ...getBulkEffectiveCapabilitiesQueryOptions(userIds),
+ ...rolesQueries.bulkEffectiveCapabilities(userIds),
placeholderData: keepPreviousData,
})
const bulkEffectiveCapabilities = bulkEffectiveCapabilitiesQuery.data
diff --git a/src/routes/community-projects.tsx b/src/routes/community-projects.tsx
index fda322e03..807c78b01 100644
--- a/src/routes/community-projects.tsx
+++ b/src/routes/community-projects.tsx
@@ -2,7 +2,7 @@ import { createFileRoute } from '@tanstack/react-router'
import * as v from 'valibot'
import { seo } from '~/utils/seo'
import { ShowcaseGallery } from '~/components/ShowcaseGallery'
-import { getApprovedShowcasesQueryOptions } from '~/queries/showcases'
+import { showcasesQueries } from '~/queries/showcases'
import {
libraryIdSchema,
showcaseUseCaseSchema,
@@ -44,7 +44,7 @@ export const Route = createFileRoute('/community-projects')({
}),
loader: async ({ deps, context: { queryClient } }) => {
await queryClient.ensureQueryData(
- getApprovedShowcasesQueryOptions({
+ showcasesQueries.approved({
pagination: {
page: deps.page,
pageSize: deps.pageSize,
diff --git a/src/routes/feedback-leaderboard.tsx b/src/routes/feedback-leaderboard.tsx
index 767ca12b9..b0031e844 100644
--- a/src/routes/feedback-leaderboard.tsx
+++ b/src/routes/feedback-leaderboard.tsx
@@ -2,7 +2,7 @@ import { createFileRoute } from '@tanstack/react-router'
import * as v from 'valibot'
import { seo } from '~/utils/seo'
import { FeedbackLeaderboard } from '~/components/FeedbackLeaderboard'
-import { getDocFeedbackLeaderboardQueryOptions } from '~/queries/docFeedback'
+import { docFeedbackQueries } from '~/queries/docFeedback'
const searchSchema = v.object({
page: v.fallback(v.optional(v.number(), 1), 1),
@@ -21,7 +21,7 @@ export const Route = createFileRoute('/feedback-leaderboard')({
}),
loader: async ({ deps, context: { queryClient } }) => {
await queryClient.ensureQueryData(
- getDocFeedbackLeaderboardQueryOptions({
+ docFeedbackQueries.leaderboard({
pagination: {
page: deps.page,
pageSize: deps.pageSize,
diff --git a/src/routes/index.tsx b/src/routes/index.tsx
index c515252e5..941ca5d4f 100644
--- a/src/routes/index.tsx
+++ b/src/routes/index.tsx
@@ -24,7 +24,7 @@ import { useQuery } from '@tanstack/react-query'
import { Button } from '~/components/ds/ui'
import { Scarf } from '~/components/Scarf'
import { useInView } from '~/hooks/useInView'
-import { homepageNpmStatsSummaryQuery, ossStatsQuery } from '~/queries/stats'
+import { statsQueries } from '~/queries/stats'
import { useLibrariesOverlay } from '~/contexts/LibrariesOverlayContext'
import { fetchRecentPosts } from '~/utils/blog.functions'
import { usePrefersReducedMotion } from '~/utils/usePrefersReducedMotion'
@@ -33,9 +33,9 @@ import { getTanStackHomepageJsonLd } from '~/utils/organization-structured-data'
export const Route = createFileRoute('/')({
loader: async ({ context: { queryClient } }) => {
- const npmStatsQuery = homepageNpmStatsSummaryQuery()
+ const npmStatsQuery = statsQueries.homepageNpmSummary()
const [stats, npmSummary, recentPosts] = await Promise.all([
- queryClient.ensureQueryData(ossStatsQuery()),
+ queryClient.ensureQueryData(statsQueries.ossSummary()),
queryClient.ensureQueryData(npmStatsQuery),
fetchRecentPosts(),
])
@@ -683,9 +683,9 @@ function PrincipleProof({
function AdoptionProof() {
const { initialStats } = Route.useLoaderData()
const { data: summary, dataUpdatedAt } = useQuery(
- homepageNpmStatsSummaryQuery(),
+ statsQueries.homepageNpmSummary(),
)
- const { data: stats } = useQuery(ossStatsQuery())
+ const { data: stats } = useQuery(statsQueries.ossSummary())
const totalDownloads =
summary?.totalDownloads ?? initialStats.totalDownloads ?? 0
diff --git a/src/routes/intent/registry/$packageName.$skillName.tsx b/src/routes/intent/registry/$packageName.$skillName.tsx
index 8de195819..a43d80b7d 100644
--- a/src/routes/intent/registry/$packageName.$skillName.tsx
+++ b/src/routes/intent/registry/$packageName.$skillName.tsx
@@ -2,11 +2,7 @@ import * as React from 'react'
import { createFileRoute, Link, useNavigate } from '@tanstack/react-router'
import { useSuspenseQuery, useQuery } from '@tanstack/react-query'
import { seo } from '~/utils/seo'
-import {
- intentPackageDetailQueryOptions,
- intentVersionSkillsQueryOptions,
- intentSingleSkillHistoryQueryOptions,
-} from '~/queries/intent'
+import { intentQueries } from '~/queries/intent'
import {
getIntentSkillPage,
type SkillVersionEntry,
@@ -54,13 +50,13 @@ export const Route = createFileRoute(
loader: async ({ params, deps, context: { queryClient } }) => {
const name = decodePkgName(params.packageName)
const detail = await queryClient.ensureQueryData(
- intentPackageDetailQueryOptions(name),
+ intentQueries.packageDetail(name),
)
const latestVersion = detail?.versions[0]?.version ?? ''
const activeVersion = deps.version ?? latestVersion
if (activeVersion) {
await queryClient.ensureQueryData(
- intentVersionSkillsQueryOptions({
+ intentQueries.versionSkills({
packageName: name,
version: activeVersion,
}),
@@ -112,7 +108,7 @@ function SkillDetailPage() {
)
const skillsQuery = useSuspenseQuery(
- intentVersionSkillsQueryOptions({
+ intentQueries.versionSkills({
packageName: pkgName,
version: activeVersion,
}),
@@ -276,7 +272,7 @@ function SkillVersionHistory({
readonly activeVersion: string
}) {
const historyQuery = useQuery(
- intentSingleSkillHistoryQueryOptions({ packageName, skillName }),
+ intentQueries.singleSkillHistory({ packageName, skillName }),
)
const entries = historyQuery.data
diff --git a/src/routes/intent/registry/$packageName.index.tsx b/src/routes/intent/registry/$packageName.index.tsx
index c56ba0c52..584bfb537 100644
--- a/src/routes/intent/registry/$packageName.index.tsx
+++ b/src/routes/intent/registry/$packageName.index.tsx
@@ -1,11 +1,7 @@
import * as React from 'react'
import { createFileRoute, Link, useNavigate } from '@tanstack/react-router'
import { useSuspenseQuery, useQuery } from '@tanstack/react-query'
-import {
- intentPackageDetailQueryOptions,
- intentVersionSkillsQueryOptions,
- intentPackageChangelogQueryOptions,
-} from '~/queries/intent'
+import { intentQueries } from '~/queries/intent'
import type { ChangelogEntry } from '~/utils/intent.functions'
import { Panel, PanelContent } from '~/components/Panel'
const LazySkillDiffViewer = React.lazy(() =>
@@ -26,13 +22,13 @@ export const Route = createFileRoute('/intent/registry/$packageName/')({
loader: async ({ params, deps, context: { queryClient } }) => {
const name = decodePkgName(params.packageName)
const detail = queryClient.getQueryData(
- intentPackageDetailQueryOptions(name).queryKey,
+ intentQueries.packageDetail(name).queryKey,
)
const latestVersion = detail?.versions[0]?.version ?? ''
const activeVersion = deps.version ?? latestVersion
if (activeVersion) {
await queryClient.ensureQueryData(
- intentVersionSkillsQueryOptions({
+ intentQueries.versionSkills({
packageName: name,
version: activeVersion,
}),
@@ -68,14 +64,14 @@ function PackageIndexPage() {
)
const skillsQuery = useSuspenseQuery(
- intentVersionSkillsQueryOptions({
+ intentQueries.versionSkills({
packageName: pkgName,
version: activeVersion,
}),
)
const skills = skillsQuery.data?.skills ?? []
- const changelogQuery = useQuery(intentPackageChangelogQueryOptions(pkgName))
+ const changelogQuery = useQuery(intentQueries.packageChangelog(pkgName))
const expandedSkillSet = React.useMemo(
() => new Set(urlExpandedSkills ?? []),
diff --git a/src/routes/intent/registry/$packageName.tsx b/src/routes/intent/registry/$packageName.tsx
index 1e88adcf3..ccadb0e9d 100644
--- a/src/routes/intent/registry/$packageName.tsx
+++ b/src/routes/intent/registry/$packageName.tsx
@@ -11,11 +11,7 @@ import * as v from 'valibot'
import { CopyIcon, CheckIcon } from '@phosphor-icons/react'
import { Panel, PanelContent } from '~/components/Panel'
import { seo } from '~/utils/seo'
-import {
- intentPackageDetailQueryOptions,
- intentVersionSkillsQueryOptions,
- intentSkillHistoryQueryOptions,
-} from '~/queries/intent'
+import { intentQueries } from '~/queries/intent'
import type { IntentPackageDetail } from '~/utils/intent.functions'
import { useToast } from '~/components/ToastProvider'
import { SkillSparklineFallback } from '~/components/intent/SkillSparklineFallback'
@@ -68,7 +64,7 @@ export const Route = createFileRoute('/intent/registry/$packageName')({
validateSearch: (search) => v.parse(searchSchema, search),
loader: async ({ params, context: { queryClient } }) => {
const name = decodePkgName(params.packageName)
- await queryClient.ensureQueryData(intentPackageDetailQueryOptions(name))
+ await queryClient.ensureQueryData(intentQueries.packageDetail(name))
},
head: ({ params }) => {
const name = decodePkgName(params.packageName)
@@ -98,7 +94,7 @@ function PackageLayout() {
function PackageLayoutContent({ name }: { readonly name: string }) {
const { version: searchVersion } = Route.useSearch()
const navigate = useNavigate({ from: Route.fullPath })
- const detailQuery = useSuspenseQuery(intentPackageDetailQueryOptions(name))
+ const detailQuery = useSuspenseQuery(intentQueries.packageDetail(name))
const detail = detailQuery.data
const latestVersion = detail?.versions[0]?.version ?? ''
@@ -155,7 +151,7 @@ function PackageLayoutInner({
}
const skillsQuery = useSuspenseQuery(
- intentVersionSkillsQueryOptions({
+ intentQueries.versionSkills({
packageName: name,
version: activeVersion,
}),
@@ -163,9 +159,7 @@ function PackageLayoutInner({
const skills = skillsQuery.data?.skills ?? []
const packageNames = React.useMemo(() => [name], [name])
- const skillHistoryQuery = useQuery(
- intentSkillHistoryQueryOptions(packageNames),
- )
+ const skillHistoryQuery = useQuery(intentQueries.skillHistory(packageNames))
const skillHistory = skillHistoryQuery.data?.[name]
return (
diff --git a/src/routes/intent/registry/index.tsx b/src/routes/intent/registry/index.tsx
index bd6c3f9c8..d1dbc207a 100644
--- a/src/routes/intent/registry/index.tsx
+++ b/src/routes/intent/registry/index.tsx
@@ -3,12 +3,7 @@ import { createFileRoute, Link, useNavigate } from '@tanstack/react-router'
import { useSuspenseQuery, useQuery } from '@tanstack/react-query'
import * as v from 'valibot'
import { seo } from '~/utils/seo'
-import {
- intentStatsQueryOptions,
- intentDirectoryQueryOptions,
- intentSkillSearchQueryOptions,
- intentSkillHistoryQueryOptions,
-} from '~/queries/intent'
+import { intentQueries } from '~/queries/intent'
import type {
EnrichedIntentPackage,
SkillHistoryEntry,
@@ -47,9 +42,9 @@ export const Route = createFileRoute('/intent/registry/')({
}),
loader: ({ deps, context: { queryClient } }) =>
Promise.all([
- queryClient.ensureQueryData(intentStatsQueryOptions()),
+ queryClient.ensureQueryData(intentQueries.stats()),
queryClient.ensureQueryData(
- intentDirectoryQueryOptions({
+ intentQueries.directory({
search: deps.q,
framework: deps.framework,
sort: deps.sort,
@@ -74,12 +69,12 @@ function IntentRegistryPage() {
const { q, tab, framework, sort, page, view } = Route.useSearch()
const navigate = Route.useNavigate()
- const statsQuery = useSuspenseQuery(intentStatsQueryOptions())
+ const statsQuery = useSuspenseQuery(intentQueries.stats())
const directoryQuery = useSuspenseQuery(
- intentDirectoryQueryOptions({ search: q, framework, sort, page }),
+ intentQueries.directory({ search: q, framework, sort, page }),
)
const skillSearchQuery = useQuery({
- ...intentSkillSearchQueryOptions(q ?? ''),
+ ...intentQueries.skillSearch(q ?? ''),
enabled: tab === 'skills' && (q?.trim().length ?? 0) > 0,
})
@@ -95,7 +90,7 @@ function IntentRegistryPage() {
[packageNames],
)
const skillHistoryQuery = useQuery(
- intentSkillHistoryQueryOptions(skillHistoryPackageNames),
+ intentQueries.skillHistory(skillHistoryPackageNames),
)
const skillHistory = React.useMemo(
() => skillHistoryQuery.data ?? {},
diff --git a/src/routes/showcase/$id.tsx b/src/routes/showcase/$id.tsx
index df130ae9d..571a7d39d 100644
--- a/src/routes/showcase/$id.tsx
+++ b/src/routes/showcase/$id.tsx
@@ -3,10 +3,7 @@ import { createFileRoute } from '@tanstack/react-router'
import * as v from 'valibot'
import { seo } from '~/utils/seo'
import { ShowcaseDetail } from '~/components/ShowcaseDetail'
-import {
- getShowcaseQueryOptions,
- getRelatedShowcasesQueryOptions,
-} from '~/queries/showcases'
+import { showcasesQueries } from '~/queries/showcases'
export const Route = createFileRoute('/showcase/$id')({
params: {
@@ -17,12 +14,12 @@ export const Route = createFileRoute('/showcase/$id')({
},
loader: async ({ params, context: { queryClient } }) => {
const showcaseData = await queryClient.ensureQueryData(
- getShowcaseQueryOptions(params.id),
+ showcasesQueries.detail(params.id),
)
if (showcaseData?.showcase.libraries.length) {
await queryClient.ensureQueryData(
- getRelatedShowcasesQueryOptions({
+ showcasesQueries.related({
showcaseId: params.id,
libraries: showcaseData.showcase.libraries,
limit: 4,
diff --git a/src/routes/showcase/index.tsx b/src/routes/showcase/index.tsx
index 063b52f59..1c44027c1 100644
--- a/src/routes/showcase/index.tsx
+++ b/src/routes/showcase/index.tsx
@@ -2,7 +2,7 @@ import { createFileRoute, stripSearchParams } from '@tanstack/react-router'
import * as v from 'valibot'
import { seo } from '~/utils/seo'
import { ShowcaseGallery } from '~/components/ShowcaseGallery'
-import { getApprovedShowcasesQueryOptions } from '~/queries/showcases'
+import { showcasesQueries } from '~/queries/showcases'
import {
showcaseSearchSchema,
defaultShowcaseSearch,
@@ -36,7 +36,7 @@ export const Route = createFileRoute('/showcase/')({
}),
loader: async ({ deps, context: { queryClient } }) => {
await queryClient.ensureQueryData(
- getApprovedShowcasesQueryOptions({
+ showcasesQueries.approved({
pagination: {
page: deps.page,
pageSize: deps.pageSize,
diff --git a/src/utils/docs.ts b/src/utils/docs.ts
index 9c20f4921..37cec8198 100644
--- a/src/utils/docs.ts
+++ b/src/utils/docs.ts
@@ -1,6 +1,6 @@
import { isNotFound, notFound } from '@tanstack/react-router'
import type { QueryClient } from '@tanstack/react-query'
-import { docsPathManifestQueryOptions } from '~/queries/docsManifest'
+import { docsManifestQueries } from '~/queries/docsManifest'
import {
fetchDocs,
fetchDocsManifest,
@@ -104,7 +104,7 @@ export async function resolveDocsRoutePath(opts: {
docsRoot: opts.docsRoot,
}
const manifest = opts.queryClient
- ? await opts.queryClient.fetchQuery(docsPathManifestQueryOptions(request))
+ ? await opts.queryClient.fetchQuery(docsManifestQueries.paths(request))
: await fetchDocsPathManifest({ data: request })
if (manifest.paths.length === 0) {
@@ -256,7 +256,7 @@ async function findLatestDocsPath(
docsRoot: opts.docsRoot,
}
const manifest = opts.queryClient
- ? await opts.queryClient.fetchQuery(docsPathManifestQueryOptions(request))
+ ? await opts.queryClient.fetchQuery(docsManifestQueries.paths(request))
: await fetchDocsPathManifest({ data: request })
return docsManifestHasPath(manifest, docsPath) ? docsPath : null
diff --git a/tests/docs-manifest-cache.test.ts b/tests/docs-manifest-cache.test.ts
index 503c6f89a..b4da38495 100644
--- a/tests/docs-manifest-cache.test.ts
+++ b/tests/docs-manifest-cache.test.ts
@@ -1,7 +1,7 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import { dehydrate, hydrate, QueryClient } from '@tanstack/react-query'
-import { docsPathManifestQueryOptions } from '../src/queries/docsManifest'
+import { docsManifestQueries } from '../src/queries/docsManifest'
import { resolveDocsRoutePath } from '../src/utils/docs'
const request = {
@@ -12,7 +12,7 @@ const request = {
test('docs navigation reuses the manifest hydrated by the server', async () => {
const serverClient = new QueryClient()
- serverClient.setQueryData(docsPathManifestQueryOptions(request).queryKey, {
+ serverClient.setQueryData(docsManifestQueries.paths(request).queryKey, {
paths: ['routing/routing-concepts', 'routing/route-trees'],
redirects: {},
})
@@ -64,7 +64,7 @@ test('cached manifests stay separate for each repository, branch, and docs root'
try {
for (const [index, data] of requests.entries()) {
- queryClient.setQueryData(docsPathManifestQueryOptions(data).queryKey, {
+ queryClient.setQueryData(docsManifestQueries.paths(data).queryKey, {
paths: [`page-${index}`],
redirects: {},
})