Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hooks/campaigns: Disable useCampaignList only if data is prefetched #1689

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/common/hooks/campaigns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ export const campaignsOrderQueryFunction: QueryFunction<CampaignResponse[]> = as
return shuffledActiveCampaigns.concat(shuffledInactiveCampaigns)
}

export function useCampaignList() {
export function useCampaignList(prefetched = false) {
return useQuery<CampaignResponse[]>(
[endpoints.campaign.listCampaigns.url],
campaignsOrderQueryFunction,
{ enabled: false },
{ enabled: !prefetched },
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/client/campaigns/CampaignFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const categories: {
export default function CampaignFilter() {
const { t } = useTranslation()
const { mobile } = useMobile()
const { data: campaigns, isLoading } = useCampaignList()
const { data: campaigns, isLoading } = useCampaignList(true)
const [selectedCategory, setSelectedCategory] = useState<string>('ALL')
// TODO: add filters&sorting of campaigns so people can select based on personal preferences
const campaignToShow = useMemo<CampaignResponse[]>(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {

export default function ActiveCampaignsSection() {
const { t } = useTranslation('index')
const { data } = useCampaignList()
const { data } = useCampaignList(true)
const activeCampaigns = data
?.filter((campaign) => campaign.state === CampaignState.active)
.slice(0, 5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {

export default function CompletedCampaignsSection() {
const { t } = useTranslation('campaigns')
const { data } = useCampaignList()
const { data } = useCampaignList(true)

const completedCampaigns = data?.filter(
(campaign: CampaignResponse) =>
Expand Down
Loading