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

Use directus for project fetch #128

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion web/src/components/Map/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -404,4 +404,4 @@ export const Map = ({ initialOverlay, urlProjectId, mediaSize }) => {
)
}

export default Map
export default Map
42 changes: 9 additions & 33 deletions web/src/components/Map/mapfetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const fetchGainForestCenterpoints = async (map) => {
}

export const fetchProjectInfo = async (projectId) => {
const endpoint = `${process.env.GAINFOREST_ENDPOINT}/api/graphql`
const endpoint = `${process.env.DIRECTUS_ENDPOINT}/graphql/items/project`

const response = fetch(endpoint, {
method: 'POST',
Expand All @@ -66,61 +66,37 @@ export const fetchProjectInfo = async (projectId) => {
body: JSON.stringify({
query: `
query {
project(id:"${projectId}") {
id
project(filter: {legacyId:{ _eq: "${projectId}"}}) {
id: legacyId
name
country
dataDownloadUrl
dataDownloadInfo
description
longDescription
stripeUrl
discordId
lat
lon
area
objective
assets {
id
name
classification
awsCID
shapefile {
default
isReference
shortName
}
}
communityMembers {
id
firstName
lastName
priority
role
bio
Wallet {
CeloAccounts
SOLAccounts
}
fundsReceived
profileUrl
}
Wallet {
CeloAccounts
SOLAccounts
}

}
}
`,
}),
})
.then((res) => res.json())
.then((result) => {
console.log(result)
console.log(result.name)
console.log(result[0])
console.log(response)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure to remove all console.logs from the final result!

return result.data
})

return response
}
//
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here for the comments

export const fetchProjectPolygon = async (
endpoint: string,
setActiveProjectPolygon
Expand Down
26 changes: 16 additions & 10 deletions web/src/components/Overlays/Info/ProjectCard/ProjectCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { InfoTag } from '../../../InfoTag/InfoTag'
import ThemedSkeleton from '../../../Map/components/Skeleton'
import { InfoBox } from '../InfoBox'

import { ProjectSiteButtons } from './ProjectSiteButtons'
//import { ProjectSiteButtons } from './ProjectSiteButtons'

const fetchProjectNumbers = async (projectId) => {
try {
Expand All @@ -35,7 +35,9 @@ export const ProjectCard = ({
const [promoVideo, setPromoVideo] = useState('')
const [projectNumbers, setProjectNumbers] = useState(null)
const { theme } = useThemeUI()
console.log(activeProjectData)

//Will not use assets on Directus for now, but can use splashart
useEffect(() => {
const video = activeProjectData?.project?.assets?.find(
(d) => d.classification === 'Promotional Video'
Expand All @@ -47,6 +49,7 @@ export const ProjectCard = ({
}
}, [activeProjectData])


if (!activeProjectData) {
return <ProjectCardSkeleton mediaSize={mediaSize} />
}
Expand All @@ -64,11 +67,11 @@ export const ProjectCard = ({
mediaSize={mediaSize}
theme={theme}
/>
<ProjectSiteButtons
{/*<ProjectSiteButtons
assets={activeProjectData?.project?.assets}
activeShapefile={activeProjectPolygon}
setActiveShapefile={setActiveProjectPolygon}
/>
/>*/}
<Description activeProjectData={activeProjectData} />
<Objectives activeProjectData={activeProjectData} />
{projectNumbers && <SummaryStatistics numbers={projectNumbers} />}
Expand All @@ -94,6 +97,8 @@ const ProjectCardSkeleton = ({ mediaSize }) => (
</InfoBox>
)

//Will not use assets for now
//but will use splash art
const ProjectSplash = ({ activeProjectData, promoVideo, handleClick }) => {
const splash = activeProjectData?.project?.assets?.find((d) =>
d.classification?.includes('Splash')
Expand All @@ -118,21 +123,22 @@ const ProjectSplash = ({ activeProjectData, promoVideo, handleClick }) => {
)
}


const ProjectHeader = ({ activeProjectData, mediaSize, theme }) => (
<HeaderContainer>
<ProjectLogo project={activeProjectData?.project} theme={theme} />
<ProjectLogo project={activeProjectData?.project[0]} theme={theme} />
<div>
<ProjectTitle mediaSize={mediaSize}>
{activeProjectData?.project?.name || ''}
{activeProjectData?.project[0].name || ''}
</ProjectTitle>
<CountryAndArea theme={theme} activeProjectData={activeProjectData} />
</div>
</HeaderContainer>
)

const CountryAndArea = ({ activeProjectData, theme }) => {
const area = Math.round(activeProjectData?.project?.area / 10000)
const country = countryToEmoji[activeProjectData?.project?.country]
const area = Math.round(activeProjectData?.project[0].area / 10000)
const country = countryToEmoji[activeProjectData?.project[0].country]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we have to access the data in this format multiple times (activeProjectData?.project[0]), how can we make this code easier to read? Can we just pass in activeProjectData?.project[0] directly to the function?


return (
<CountryAreaText>
Expand All @@ -151,13 +157,13 @@ const Description = ({ activeProjectData }) => (
<Section>
<h3>Description</h3>
<DescriptionText>
{activeProjectData?.project?.longDescription.replaceAll('\\n', '\n')}
{activeProjectData?.project[0].longDescription.replaceAll('\\n', '\n')}
</DescriptionText>
</Section>
)

const Objectives = ({ activeProjectData }) => {
const objectives = activeProjectData.project?.objective
const objectives = activeProjectData?.project[0].objective
?.split(',')
?.filter(Boolean)

Expand Down Expand Up @@ -325,4 +331,4 @@ const StatValue = styled.div`
const StatLabel = styled.div`
font-size: 0.875rem;
color: ${({ theme }) => theme.colors.text};
`
`
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, useState } from 'react'

import Button from '../../../Map/components/Button'
import { fetchProjectPolygon } from '../../../Map/mapfetch'

/*
export const ProjectSiteButtons = ({
assets,
activeShapefile,
Expand Down Expand Up @@ -78,4 +78,4 @@ export const ProjectSiteButtons = ({
)}
</>
)
}
}*/
2 changes: 1 addition & 1 deletion web/src/components/Overlays/InfoOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,4 @@ export const ImageOverlay = ({
)}
</div>
)
}
}