-
-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DB refactor [4/n]: switch DB queries to subgraph (#4366)
Co-authored-by: aeolian <[email protected]>
- Loading branch information
1 parent
0bb6cf5
commit fee3a52
Showing
15 changed files
with
147 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 11 additions & 22 deletions
33
src/components/Home/JuicyPicksSection/hooks/useJuicyPicks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,18 @@ | ||
import { JUICY_PICKS_PROJECT_IDS } from 'components/Home/JuicyPicksSection/constants' | ||
import { PV_V2 } from 'constants/pv' | ||
import { useDBProjectsQuery } from 'hooks/useProjects' | ||
import { DBProject } from 'models/dbProject' | ||
import { useProjectsQuery } from 'generated/graphql' | ||
import { client } from 'lib/apollo/client' | ||
import { getSubgraphIdForProject } from 'utils/graph' | ||
|
||
export function useFetchJuicyPicks() { | ||
const res = useDBProjectsQuery({ | ||
ids: JUICY_PICKS_PROJECT_IDS.map(projectId => | ||
getSubgraphIdForProject(PV_V2, projectId), | ||
), | ||
return useProjectsQuery({ | ||
client, | ||
variables: { | ||
where: { | ||
id_in: JUICY_PICKS_PROJECT_IDS.map(projectId => | ||
getSubgraphIdForProject(PV_V2, projectId), | ||
), | ||
}, | ||
}, | ||
}) | ||
|
||
if (!res.data) { | ||
return res | ||
} | ||
|
||
// ensure list sorted by JUICY_PICKS_PROJECT_IDS array order | ||
const sortedPicks = JUICY_PICKS_PROJECT_IDS.map(projectId => { | ||
return res.data?.find(project => project.projectId === projectId) as | ||
| DBProject | ||
| undefined | ||
}).filter((p): p is DBProject => !!p) | ||
|
||
return { | ||
...res, | ||
data: sortedPicks, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.