Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ront-End into clark
  • Loading branch information
Cwill14 committed Oct 23, 2019
2 parents cface08 + 0f2c672 commit 636d758
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 92 deletions.
96 changes: 60 additions & 36 deletions revclient/src/graphql/fragments/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,22 @@ export const COMMENTS_FRAG = gql`
likes {
id
profile {
...UserSummary
id
verified
email
firstName
lastName
profileImage
country
state
city
zip
phone
address
aptNumber
}
}
}
${USER_SUMMARY_FRAG}
`;


Expand Down Expand Up @@ -63,23 +74,6 @@ export const PROJECT_SUMMARY_FRAG = gql`
difficulty
startDate
featuredImage
applicants {
id
licensed
coverLetter
jobExperience
education
availability
status
trade {
id
name
description
}
profile {
...UserSummary
}
}
images {
id
imageUrl
Expand All @@ -92,38 +86,68 @@ export const PROJECT_SUMMARY_FRAG = gql`
id
profile {
id
verified
email
firstName
lastName
profileImage
country
state
city
zip
phone
address
aptNumber
}
}
tradeMasters {
id
profile {
...UserSummary
}
}
students {
id
profile {
...UserSummary
id
verified
email
firstName
lastName
profileImage
country
state
city
zip
phone
address
aptNumber
}
}
trades {
id
name
description
}
tradeMasters {
id
profile {
id
profileImage
firstName
lastName
email
address
city
state
zip
}
}
tasks {
...Tasks
id
title
description
priority
dueDate
budgetHours
completed
}
# comments {
# id
# ...Comments
# profile {
# ...UserSummary
# }
# }
}
${USER_SUMMARY_FRAG}
${TASKS_FRAG}
`


Expand Down
36 changes: 25 additions & 11 deletions revclient/src/graphql/queries/Projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export const GET_PROJECTS = gql`
...ProjectSummary
}
}
${USER_SUMMARY_FRAG}
${PROJECT_SUMMARY_FRAG}
`;

Expand All @@ -23,19 +22,26 @@ export const GET_RECOMMENDED_PROJECTS = gql`
...ProjectSummary
}
}
${USER_SUMMARY_FRAG}
${PROJECT_SUMMARY_FRAG}
`;


export const GET_PROJECTS_NEAR_ME = gql`
query projectsNearMe {
projectsNearMe {
...ProjectSummary
id
slug
name
description
address
city
state
zip
goalAmount
duration
featuredImage
}
}
${USER_SUMMARY_FRAG}
${PROJECT_SUMMARY_FRAG}
`;


Expand All @@ -60,6 +66,12 @@ export const GET_PROJECT_BY_ID = gql`
}
}
}
tradeMasters {
id
profile {
...UserSummary
}
}
comments {
...Comments
profile {
Expand Down Expand Up @@ -93,12 +105,14 @@ export const GET_PROJECT_BY_SLUG = gql`
${USER_SUMMARY_FRAG}
${COMMENTS_FRAG}
${PROJECT_SUMMARY_FRAG}
${TASKS_FRAG}
`;


// export const GET_TRADES_BY_PROJECT_ID = gql`
// query projectById($id: ID!) {

// }
// `;
export const QUERY_PROJECTS = gql`
query projects($query: String!) {
projects(query: $query) {
...ProjectSummary
}
}
${PROJECT_SUMMARY_FRAG}
`
63 changes: 34 additions & 29 deletions revclient/src/graphql/queries/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ export const GET_USER_PROFILE = gql`
project {
...ProjectSummary
}
profile {
...UserSummary
}
# profile {
# ...UserSummary
# }
}
# This is an array with items if the user has created a project
Expand Down Expand Up @@ -70,34 +70,40 @@ export const GET_USER_PROFILE = gql`
likedProjects {
id
project {
...ProjectSummary
}
profile {
...UserSummary
id
name
featuredImage
}
}
# This is an array with items if the user has left comments
comments {
...Comments
project {
...ProjectSummary
}
}
# comments {
# ...Comments
# project {
# id
# students {
# id
# profile {
# id
# profileImage
# }
# }
# }
# }
# This is an array with items if the user has liked comments
likedComments {
id
comment {
...Comments
profile {
...UserSummary
}
project {
...ProjectSummary
}
}
}
# likedComments {
# id
# comment {
# ...Comments
# profile {
# ...UserSummary
# }
# project {
# ...ProjectSummary
# }
# }
# }
# This is an array with items if the user has submitted an application to join a project
applications {
Expand Down Expand Up @@ -158,9 +164,9 @@ export const GET_USER_PROFILE = gql`
project {
...ProjectSummary
}
profile {
...UserSummary
}
# profile {
# ...UserSummary
# }
### Redundant. This query returns the projects the user is a trademaster on.
### No need to return the profile we already have
Expand All @@ -178,7 +184,6 @@ export const GET_USER_PROFILE = gql`
}
${USER_SUMMARY_FRAG}
${PROJECT_SUMMARY_FRAG}
${COMMENTS_FRAG}
`;
Expand Down
6 changes: 4 additions & 2 deletions revclient/src/graphql/queries/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
GET_PROJECT_BY_ID,
GET_PROJECT_BY_SLUG,
GET_RECOMMENDED_PROJECTS,
GET_PROJECTS_NEAR_ME
GET_PROJECTS_NEAR_ME,
QUERY_PROJECTS,
// GET_TRADES_BY_PROJECT_ID,
} from './Projects';

Expand All @@ -21,6 +22,7 @@ export {
GET_PROJECT_BY_SLUG,
GET_USER_PROFILE,
GET_RECOMMENDED_PROJECTS,
GET_PROJECTS_NEAR_ME
GET_PROJECTS_NEAR_ME,
QUERY_PROJECTS,
// GET_TRADES_BY_PROJECT_ID,
}
29 changes: 23 additions & 6 deletions revclient/src/views/BrowseAll/BrowseAll.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,48 @@ import LoadingSpinner from '../../components/LoadingSpinner/LoadingSpinner';


// Graphql
import { useQuery } from '@apollo/react-hooks';
import { GET_PROJECTS } from '../../graphql/queries';
import { useQuery, useLazyQuery } from '@apollo/react-hooks';
import { GET_PROJECTS, QUERY_PROJECTS } from '../../graphql/queries';

const BrowseAll = () => {
const [projectState, setProjectState] = useState();
const { loading, error, data } = useQuery(GET_PROJECTS);
const [ projectState, setProjectState ] = useState();
const [ queryFormState, setQueryFormState ] = useState({ query: "" });

// const { loading, error, data } = useQuery( GET_PROJECTS );
const [ queryProjects, { loading, data } ] = useLazyQuery( QUERY_PROJECTS );


useEffect(() => {
submitQuery()
data && setProjectState({ projects: data.projects });

}, [data]);

const submitQuery = async () => {
const queried = await queryProjects({ variables: { query: queryFormState.query } })
console.log(queried);
}



if (loading) return <LoadingSpinner />
if (error) return <h3>error</h3>;
// if (error) return <h3>error</h3>;

return (
<>
<Nav />
<div className="browse-all-container">
<Top />

<Top submitQuery={submitQuery} queryFormState={queryFormState} setQueryFormState={setQueryFormState} />



<section className="browse-all-project-card-container">
{projectState && projectState.projects
? projectState.projects.map(project => <ProjectCard project={project} key={project.id} />)
: null}
</section>

</div>
<Footer />
</>
Expand Down
Loading

0 comments on commit 636d758

Please sign in to comment.