diff --git a/.gitignore b/.gitignore index 4d19a85e..1634b3fa 100644 --- a/.gitignore +++ b/.gitignore @@ -87,4 +87,7 @@ subgraph/subgraph.yaml ui/.textile/auth.yml # vscode -.vscode/ \ No newline at end of file +.vscode/ + +# The Graph Client +.graphclient \ No newline at end of file diff --git a/package.json b/package.json index 621c4480..0f3c17e8 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,8 @@ "deploy:subgraph-mainnet": "lerna exec --scope everest-subgraph -- yarn deploy-mainnet", "deploy:subgraph-testing": "lerna exec --scope everest-subgraph -- yarn deploy-testing", "build:ui": "lerna exec --scope everest-ui -- yarn build", + "prestart:ui": "lerna exec --scope everest-ui -- yarn build:client", + "prebuild:ui": "lerna exec --scope everest-ui -- yarn build:client", "start:ui": "lerna exec --scope everest-ui -- yarn start", "build-ropsten": "yarn build:contracts && yarn build:subgraph-ropsten && yarn build:mutations", "build-mainnet": "yarn build:contracts && yarn build:subgraph-mainnet && yarn build:mutations", diff --git a/ui/.babelrc.js b/ui/.babelrc.js new file mode 100644 index 00000000..a8d9752a --- /dev/null +++ b/ui/.babelrc.js @@ -0,0 +1,13 @@ +module.exports = { + presets: [ + [ + 'babel-preset-gatsby', + { + targets: { + node: process.versions.node.split('.')[0], + browsers: ['>0.25%', 'not dead'], + }, + }, + ], + ], +} diff --git a/ui/.graphclientrc.yml b/ui/.graphclientrc.yml new file mode 100644 index 00000000..a39c27a6 --- /dev/null +++ b/ui/.graphclientrc.yml @@ -0,0 +1,11 @@ +# This loads the Subgraph schema, from the actual Subgrahp +sources: + - name: everest + handler: + graphql: + endpoint: ${GATSBY_GRAPHQL_HTTP_URI} + +# Loads all queries and generates a TypedDocumentNode +documents: + - "./src/graphql/**/*.graphql" + diff --git a/ui/gatsby-node.js b/ui/gatsby-node.js index 26706bfa..4aac251a 100644 --- a/ui/gatsby-node.js +++ b/ui/gatsby-node.js @@ -1,4 +1,4 @@ -const fetch = require('isomorphic-fetch') +const { fetch } = require('cross-undici-fetch') const activeEnv = process.env.GATSBY_ACTIVE_ENV || process.env.NODE_ENV || 'development' @@ -12,27 +12,29 @@ require('dotenv').config({ exports.createPages = async ({ page, actions }) => { const { createPage } = actions - const query = `{ - categories { - id - name - imageUrl - description - subcategories { + const query = /* GraphQL */ ` + { + categories { id + name + imageUrl + description + subcategories { + id + projects { + id + } + } + parentCategory { + id + name + } projects { id } } - parentCategory { - id - name - } - projects { - id - } } - }` + ` const result = await fetch(process.env.GATSBY_GRAPHQL_HTTP_URI, { method: 'POST', @@ -102,6 +104,22 @@ exports.onCreateWebpackConfig = ({ stage, loaders, actions }) => { } actions.setWebpackConfig({ + resolve: { + alias: { + 'cross-undici-fetch': require.resolve( + 'cross-undici-fetch/dist/global-ponyfill.js', + ), + }, + }, node: { fs: 'empty', net: 'empty', child_process: 'empty' }, + module: { + rules: [ + { + test: /\.mjs$/, + include: /node_modules/, + type: 'javascript/auto', + }, + ], + }, }) } diff --git a/ui/package.json b/ui/package.json index b2143f18..4ef1d5ae 100644 --- a/ui/package.json +++ b/ui/package.json @@ -5,6 +5,7 @@ "version": "0.1.0", "license": "MIT", "scripts": { + "build:client": "DOTENV_CONFIG_PATH=./.env.development graphclient build --require dotenv/config", "build": "rm -rf public/ && rm -rf .cache && gatsby build --prefix-paths", "build:staging": "rm -rf public/ && rm -rf .cache && GATSBY_ACTIVE_ENV=staging gatsby build --prefix-paths && node post-build.js", "develop": "gatsby develop -p 4000", @@ -30,7 +31,6 @@ "@web3-react/network-connector": "^6.0.4", "@web3-react/walletconnect-connector": "^6.0.2", "@web3-react/walletlink-connector": "^6.0.2", - "apollo-boost": "^0.4.4", "base-x": "^3.0.7", "dotenv": "^8.2.0", "ethers": "^4.0.40", @@ -64,8 +64,11 @@ "web3-react": "^5.0.5" }, "devDependencies": { + "babel-preset-gatsby": "2.9.1", + "@graphprotocol/client-cli": "0.0.2", "gatsby-plugin-webpack-bundle-analyser-v2": "^1.1.8", - "prettier": "^1.19.1" + "prettier": "^1.19.1", + "dotenv": "16.0.0" }, "repository": { "type": "git", diff --git a/ui/src/components/Search/index.js b/ui/src/components/Search/index.js index c9109421..cbd7ef02 100644 --- a/ui/src/components/Search/index.js +++ b/ui/src/components/Search/index.js @@ -9,12 +9,12 @@ import Card from '../Card' import SearchIcon from '../../images/search.svg' import Close from '../../images/close.svg' -import { PROJECT_SEARCH } from '../../utils/apollo/queries' +import { projectSearchDocument } from '../../../.graphclient' const Search = ({ isSearchOpen, setIsSearchOpen, value, setValue }) => { let searchData = null - const [searchProjects, { data }] = useLazyQuery(PROJECT_SEARCH) + const [searchProjects, { data }] = useLazyQuery(projectSearchDocument) if (data && data.projectSearch) { searchData = data.projectSearch @@ -176,24 +176,24 @@ const Search = ({ isSearchOpen, setIsSearchOpen, value, setValue }) => { )} ) : ( - { - e.stopPropagation() - setIsSearchOpen(true) - }} - /> - ) + { + e.stopPropagation() + setIsSearchOpen(true) + }} + /> + ) } Search.propTypes = { diff --git a/ui/src/components/UploadImage/index.js b/ui/src/components/UploadImage/index.js index e1e94b20..5b3c9036 100644 --- a/ui/src/components/UploadImage/index.js +++ b/ui/src/components/UploadImage/index.js @@ -4,7 +4,7 @@ import PropTypes from 'prop-types' import { jsx } from 'theme-ui' import { Grid } from '@theme-ui/components' import { useMutation } from '@apollo/react-hooks' -import { gql } from 'apollo-boost' +import { gql } from 'graphql-tag' import Close from '../../images/close.svg' import Loading from '../Loading' diff --git a/ui/src/graphql/all-categoties.query.graphql b/ui/src/graphql/all-categoties.query.graphql new file mode 100644 index 00000000..e34eca4d --- /dev/null +++ b/ui/src/graphql/all-categoties.query.graphql @@ -0,0 +1,55 @@ +query allCategories( + $orderBy: Category_orderBy + $orderDirection: OrderDirection + ) { + categories( + orderBy: $orderBy + orderDirection: $orderDirection + where: { parentCategory: null } + ) { + id + name + description + imageUrl + projectCount + parentCategory { + id + name + } + subcategories { + id + name + imageUrl + parentCategory { + id + name + } + subcategories { + id + name + imageUrl + parentCategory { + id + name + parentCategory { + id + name + } + } + subcategories { + id + name + imageUrl + parentCategory { + id + name + parentCategory { + id + name + } + } + } + } + } + } + } \ No newline at end of file diff --git a/ui/src/graphql/categories.query.graphql b/ui/src/graphql/categories.query.graphql new file mode 100644 index 00000000..f2022665 --- /dev/null +++ b/ui/src/graphql/categories.query.graphql @@ -0,0 +1,30 @@ +query categories( + $parentCategory: String + $orderBy: Category_orderBy + $orderDirection: OrderDirection + ) { + categories( + orderBy: $orderBy + orderDirection: $orderDirection + where: { parentCategory: $parentCategory } + ) { + id + name + description + imageUrl + projectCount + subcategories { + id + projects { + id + } + } + parentCategory { + id + name + } + projects { + id + } + } + } \ No newline at end of file diff --git a/ui/src/graphql/category.query.graphql b/ui/src/graphql/category.query.graphql new file mode 100644 index 00000000..ae1113f8 --- /dev/null +++ b/ui/src/graphql/category.query.graphql @@ -0,0 +1,66 @@ +query category( + $id: ID! + $orderBy: Category_orderBy + $orderDirection: OrderDirection + ) { + category(id: $id) { + id + name + description + imageUrl + projectCount + subcategories(orderBy: $orderBy, orderDirection: $orderDirection) { + id + name + description + imageUrl + projectCount + projects { + id + name + description + avatar + createdAt + currentChallenge { + id + } + categories { + id + name + } + } + } + parentCategory { + id + name + parentCategory { + id + name + } + } + projects { + id + name + image + description + avatar + createdAt + isRepresentative + currentChallenge { + id + } + categories { + id + name + description + parentCategory { + id + name + } + subcategories { + id + } + } + } + } + } \ No newline at end of file diff --git a/ui/src/graphql/challenge.query.graphql b/ui/src/graphql/challenge.query.graphql new file mode 100644 index 00000000..f56a41f0 --- /dev/null +++ b/ui/src/graphql/challenge.query.graphql @@ -0,0 +1,7 @@ + query challenge($id: ID!) { + id + description + votes { + id + } + } \ No newline at end of file diff --git a/ui/src/graphql/challenges.query.graphql b/ui/src/graphql/challenges.query.graphql new file mode 100644 index 00000000..0f174470 --- /dev/null +++ b/ui/src/graphql/challenges.query.graphql @@ -0,0 +1,24 @@ + query challenges($projects: [ID!], $endTime: Int) { + challenges(where: { owner_in: $projects, endTime_lt: $endTime }) { + id + project { + id + name + description + avatar + image + website + github + twitter + isRepresentative + createdAt + currentChallenge { + id + } + categories { + id + name + } + } + } + } \ No newline at end of file diff --git a/ui/src/graphql/everests.query.graphql b/ui/src/graphql/everests.query.graphql new file mode 100644 index 00000000..df4c2412 --- /dev/null +++ b/ui/src/graphql/everests.query.graphql @@ -0,0 +1,10 @@ + query everests { + everests { + id + projectCount + categoriesCount + reserveBankBalance + claimedProjects + challengedProjects + } + } \ No newline at end of file diff --git a/ui/src/graphql/pages-categories.query.graphql b/ui/src/graphql/pages-categories.query.graphql new file mode 100644 index 00000000..6b0d2893 --- /dev/null +++ b/ui/src/graphql/pages-categories.query.graphql @@ -0,0 +1,21 @@ +query pagesCategories { + categories { + id + name + imageUrl + description + subcategories { + id + projects { + id + } + } + parentCategory { + id + name + } + projects { + id + } + } +} \ No newline at end of file diff --git a/ui/src/graphql/profile.query.graphql b/ui/src/graphql/profile.query.graphql new file mode 100644 index 00000000..c58ec619 --- /dev/null +++ b/ui/src/graphql/profile.query.graphql @@ -0,0 +1,97 @@ +query profile( + $id: ID! + $orderBy: Project_orderBy + $orderDirection: OrderDirection + $where: Project_filter +) { + user(id: $id) { + id + projects( + orderBy: $orderBy + orderDirection: $orderDirection + where: $where + ) { + id + name + description + avatar + image + website + github + twitter + isRepresentative + createdAt + delegates { + id + } + currentChallenge { + id + } + categories { + id + name + imageUrl + parentCategory { + id + name + } + subcategories { + id + name + imageUrl + parentCategory { + id + name + } + subcategories { + id + name + imageUrl + parentCategory { + id + name + parentCategory { + id + name + } + } + subcategories { + id + name + imageUrl + parentCategory { + id + name + parentCategory { + id + name + } + } + } + } + } + } + } + delegatorProjects { + id + name + description + createdAt + avatar + currentChallenge { + id + } + categories { + id + name + parentCategory { + id + name + } + subcategories { + id + } + } + } + } +} \ No newline at end of file diff --git a/ui/src/graphql/project-search.query.graphql b/ui/src/graphql/project-search.query.graphql new file mode 100644 index 00000000..7856fba1 --- /dev/null +++ b/ui/src/graphql/project-search.query.graphql @@ -0,0 +1,20 @@ +query projectSearch($text: String) { + projectSearch(text: $text) { + id + ipfsHash + name + avatar + description + categories { + id + name + parentCategory { + id + name + } + subcategories { + id + } + } + } + } \ No newline at end of file diff --git a/ui/src/graphql/project.query.graphql b/ui/src/graphql/project.query.graphql new file mode 100644 index 00000000..99951f4e --- /dev/null +++ b/ui/src/graphql/project.query.graphql @@ -0,0 +1,80 @@ +query project($id: ID!) { + project(id: $id) { + id + name + description + createdAt + website + twitter + github + image + avatar + totalVotes + isRepresentative + delegates { + id + } + currentChallenge { + id + endTime + owner { + id + name + } + description + resolved + keepVotes + removeVotes + votes { + id + } + } + owner { + id + } + categories { + id + name + imageUrl + parentCategory { + id + name + } + subcategories { + id + name + imageUrl + parentCategory { + id + name + } + subcategories { + id + name + imageUrl + parentCategory { + id + name + parentCategory { + id + name + } + } + subcategories { + id + name + imageUrl + parentCategory { + id + name + parentCategory { + id + name + } + } + } + } + } + } + } +} \ No newline at end of file diff --git a/ui/src/graphql/projects.query.graphql b/ui/src/graphql/projects.query.graphql new file mode 100644 index 00000000..80d3c5e9 --- /dev/null +++ b/ui/src/graphql/projects.query.graphql @@ -0,0 +1,38 @@ +query projects( + $orderBy: Project_orderBy + $orderDirection: OrderDirection + $where: Project_filter + $first: Int + $skip: Int + ) { + projects( + orderBy: $orderBy + orderDirection: $orderDirection + where: $where + first: $first + skip: $skip + ) { + id + name + image + description + avatar + createdAt + isRepresentative + currentChallenge { + id + } + categories { + id + name + description + parentCategory { + id + name + } + subcategories { + id + } + } + } + } \ No newline at end of file diff --git a/ui/src/graphql/user-projects.query.graphql b/ui/src/graphql/user-projects.query.graphql new file mode 100644 index 00000000..f9da65c1 --- /dev/null +++ b/ui/src/graphql/user-projects.query.graphql @@ -0,0 +1,15 @@ +query everestUserProjects($id: ID!) { + user(id: $id) { + id + projects { + id + name + avatar + } + delegatorProjects { + id + name + avatar + } + } + } \ No newline at end of file diff --git a/ui/src/pages/categories.js b/ui/src/pages/categories.js index 0bbd90ab..eb73d3d4 100644 --- a/ui/src/pages/categories.js +++ b/ui/src/pages/categories.js @@ -4,13 +4,13 @@ import { Styled, jsx, Box } from 'theme-ui' import { Grid } from '@theme-ui/components' import { useQuery } from '@apollo/react-hooks' -import { CATEGORIES_QUERY } from '../utils/apollo/queries' import { CATEGORIES_ORDER_BY, ORDER_DIRECTION } from '../utils/constants' import Section from '../components/Section' import Sorting from '../components/Sorting' import Seo from '../components/Seo' import Loading from '../components/Loading' +import { categoriesDocument } from '../../.graphclient' const Categories = () => { const [selectedOrderBy, setSelectedOrderBy] = useState( @@ -21,7 +21,7 @@ const Categories = () => { ) const [isSortingOpen, setIsSortingOpen] = useState(false) - const { loading, data, error } = useQuery(CATEGORIES_QUERY, { + const { loading, data, error } = useQuery(categoriesDocument, { variables: { parentCategory: null, orderDirection: selectedOrderDirection, @@ -32,7 +32,11 @@ const Categories = () => { if (data && data.categories.length) { data.categories.forEach(category => { if (category.imageUrl.includes('https://api.thegraph.com/ipfs/api/v0/')) { - category.imageUrl = category.imageUrl.replace('https://api.thegraph.com/ipfs/api/v0/', 'https://ipfs.everest.link/') + // TODO: Apollo Client v3 does support mutability on responses, this needs to be done somewhere else + // category.imageUrl = category.imageUrl.replace( + // 'https://api.thegraph.com/ipfs/api/v0/', + // 'https://ipfs.everest.link/', + // ) } }) } diff --git a/ui/src/pages/index.js b/ui/src/pages/index.js index 563abaa8..d3714c42 100644 --- a/ui/src/pages/index.js +++ b/ui/src/pages/index.js @@ -9,11 +9,6 @@ import { isMobile } from 'react-device-detect' import { useAccount } from '../utils/hooks' import { getAddress } from '../services/ethers' -import { - CATEGORIES_QUERY, - PROJECTS_QUERY, - EVEREST_QUERY, -} from '../utils/apollo/queries' import { CATEGORIES_ORDER_BY, ORDER_DIRECTION } from '../utils/constants' import Link from '../components/Link' @@ -22,6 +17,11 @@ import Button from '../components/Button' import Section from '../components/Section' import Divider from '../components/Divider' import Modal from '../components/Modal' +import { + categoriesDocument, + everestsDocument, + projectsDocument, +} from '../../.graphclient' const Index = () => { const { account } = useAccount() @@ -38,7 +38,7 @@ const Index = () => { } }, []) - const { data: categories } = useQuery(CATEGORIES_QUERY, { + const { data: categories } = useQuery(categoriesDocument, { variables: { parentCategory: null, orderBy: CATEGORIES_ORDER_BY.Name, @@ -49,18 +49,22 @@ const Index = () => { if (categories && categories.categories.length) { categories.categories.forEach(category => { if (category.imageUrl.includes('https://api.thegraph.com/ipfs/api/v0/')) { - category.imageUrl = category.imageUrl.replace('https://api.thegraph.com/ipfs/api/v0/', 'https://ipfs.everest.link/') + // TODO: Apollo Client v3 does support mutability on responses, this needs to be done somewhere else + // category.imageUrl = category.imageUrl.replace( + // 'https://api.thegraph.com/ipfs/api/v0/', + // 'https://ipfs.everest.link/', + // ) } }) } - const { data: projects } = useQuery(PROJECTS_QUERY, { + const { data: projects } = useQuery(projectsDocument, { variables: { orderBy: 'createdAt', orderDirection: 'desc', }, }) - const { data: everestData } = useQuery(EVEREST_QUERY, { + const { data: everestData } = useQuery(everestsDocument, { fetchPolicy: 'network-only', notifyOnNetworkStatusChange: true, }) diff --git a/ui/src/pages/profile.js b/ui/src/pages/profile.js index 735e0901..f89ca116 100644 --- a/ui/src/pages/profile.js +++ b/ui/src/pages/profile.js @@ -13,7 +13,6 @@ import moment from 'moment' import { useAccount } from '../utils/hooks' import { metamaskAccountChange } from '../services/ethers' import { convertDate } from '../utils/helpers' -import { PROFILE_QUERY, USER_CHALLENGES_QUERY } from '../utils/apollo/queries' import { FILTERS, ORDER_BY, ORDER_DIRECTION } from '../utils/constants' import Divider from '../components/Divider' @@ -26,6 +25,7 @@ import Menu from '../components/Menu' import Filters from '../components/Filters' import Link from '../components/Link' import ProfilePlaceholder from '../images/profile-placeholder.svg' +import { challengesDocument, profileDocument } from '../../.graphclient' const Profile = ({ location }) => { const { account } = useAccount() @@ -106,7 +106,7 @@ const Profile = ({ location }) => { orderDirection: selectedOrderDirection, } - const { error, data, loading } = useQuery(PROFILE_QUERY, { + const { error, data, loading } = useQuery(profileDocument, { variables: selectedFilter === FILTERS.all ? variables @@ -127,7 +127,7 @@ const Profile = ({ location }) => { notifyOnNetworkStatusChange: true, }) - const { data: userChallenges } = useQuery(USER_CHALLENGES_QUERY, { + const { data: userChallenges } = useQuery(challengesDocument, { variables: { endTime: moment().unix(), projects: diff --git a/ui/src/pages/project/template.js b/ui/src/pages/project/template.js index 162b9465..c2d2729b 100644 --- a/ui/src/pages/project/template.js +++ b/ui/src/pages/project/template.js @@ -21,20 +21,17 @@ import { import client from '../../utils/apollo/client' import { useAccount } from '../../utils/hooks' import { metamaskAccountChange } from '../../services/ethers' - -import { - PROJECT_QUERY, - USER_PROJECTS_QUERY, - PROFILE_QUERY, -} from '../../utils/apollo/queries' import { - REMOVE_PROJECT, - RESOLVE_CHALLENGE, - CHALLENGE_PROJECT, - VOTE_CHALLENGE, - TRANSFER_OWNERSHIP, - DELEGATE_OWNERSHIP, -} from '../../utils/apollo/mutations' + projectDocument, + everestUserProjectsDocument, + profileDocument, + removeProjectDocument, + resolveChallengeDocument, + challengeProjectDocument, + voteChallengeDocument, + transferOwnershipDocument, + delegateOwnershipDocument, +} from '../../../.graphclient' import { ORDER_BY, ORDER_DIRECTION } from '../../utils/constants' @@ -68,13 +65,13 @@ const Project = ({ location }) => { const projectId = location && index ? location.pathname.slice(index, index + 42) : '' - const { loading, error, data } = useQuery(PROJECT_QUERY, { + const { loading, error, data } = useQuery(projectDocument, { variables: { id: projectId, }, }) - const { data: userData } = useQuery(USER_PROJECTS_QUERY, { + const { data: userData } = useQuery(everestUserProjectsDocument, { variables: { id: account, }, @@ -82,7 +79,7 @@ const Project = ({ location }) => { notifyOnNetworkStatusChange: true, }) - const { data: profile } = useQuery(PROFILE_QUERY, { + const { data: profile } = useQuery(profileDocument, { variables: { id: account, orderBy: ORDER_BY['Name'], @@ -94,11 +91,11 @@ const Project = ({ location }) => { let userDelegatorProjects = userData && userData.user ? userData.user.delegatorProjects : [] - const [removeProject] = useMutation(REMOVE_PROJECT, { + const [removeProject] = useMutation(removeProjectDocument, { client: client, refetchQueries: [ { - query: PROFILE_QUERY, + query: profileDocument, variables: { id: account, orderBy: ORDER_BY['Name'], @@ -116,7 +113,7 @@ const Project = ({ location }) => { update: proxy => { const profileData = cloneDeep( proxy.readQuery({ - query: PROFILE_QUERY, + query: profileDocument, variables: { id: account, orderBy: ORDER_BY['Name'], @@ -130,7 +127,7 @@ const Project = ({ location }) => { ) proxy.writeQuery({ - query: PROFILE_QUERY, + query: profileDocument, variables: { id: account, orderBy: ORDER_BY['Name'], @@ -149,7 +146,7 @@ const Project = ({ location }) => { }, }) - const [resolveChallenge] = useMutation(RESOLVE_CHALLENGE, { + const [resolveChallenge] = useMutation(resolveChallengeDocument, { client: client, onError: error => { console.error('Error voting on a challenge: ', error) @@ -160,11 +157,11 @@ const Project = ({ location }) => { }, }) - const [challengeProject] = useMutation(CHALLENGE_PROJECT, { + const [challengeProject] = useMutation(challengeProjectDocument, { client: client, refetchQueries: [ { - query: PROJECT_QUERY, + query: projectDocument, variables: { id: projectId, }, @@ -220,7 +217,7 @@ const Project = ({ location }) => { update: (proxy, result) => { const projectData = cloneDeep( proxy.readQuery({ - query: PROJECT_QUERY, + query: projectDocument, variables: { id: data && data.project ? data.project.id : '', }, @@ -228,7 +225,7 @@ const Project = ({ location }) => { ) proxy.writeQuery({ - query: PROJECT_QUERY, + query: projectDocument, variables: { id: data && data.project ? data.project.id : '', }, @@ -242,7 +239,7 @@ const Project = ({ location }) => { }, }) - const [voteChallenge] = useMutation(VOTE_CHALLENGE, { + const [voteChallenge] = useMutation(voteChallengeDocument, { client: client, onError: error => { console.error('Error voting on a challenge: ', error) @@ -253,11 +250,11 @@ const Project = ({ location }) => { }, }) - const [transferOwnership] = useMutation(TRANSFER_OWNERSHIP, { + const [transferOwnership] = useMutation(transferOwnershipDocument, { client: client, refetchQueries: [ { - query: PROFILE_QUERY, + query: profileDocument, variables: { id: account, orderBy: ORDER_BY['Name'], @@ -292,7 +289,7 @@ const Project = ({ location }) => { update: (proxy, result) => { const profileData = cloneDeep( proxy.readQuery({ - query: PROFILE_QUERY, + query: profileDocument, variables: { id: account, orderBy: ORDER_BY['Name'], @@ -306,7 +303,7 @@ const Project = ({ location }) => { ) proxy.writeQuery({ - query: PROFILE_QUERY, + query: profileDocument, variables: { id: account, orderBy: ORDER_BY['Name'], @@ -325,11 +322,11 @@ const Project = ({ location }) => { }, }) - const [delegateOwnership] = useMutation(DELEGATE_OWNERSHIP, { + const [delegateOwnership] = useMutation(delegateOwnershipDocument, { client: client, refetchQueries: [ { - query: PROFILE_QUERY, + query: profileDocument, variables: { id: account, orderBy: 'createdAt', @@ -364,7 +361,7 @@ const Project = ({ location }) => { update: (proxy, result) => { const profileData = cloneDeep( proxy.readQuery({ - query: PROFILE_QUERY, + query: profileDocument, variables: { id: account, orderBy: 'createdAt', @@ -374,7 +371,7 @@ const Project = ({ location }) => { ) proxy.writeQuery({ - query: PROFILE_QUERY, + query: profileDocument, variables: { id: account, orderBy: 'createdAt', @@ -537,11 +534,11 @@ const Project = ({ location }) => { if (project) { tweet = `We’d like to claim the ${project.name} project on @EverestRegistry. Please transfer ownership to ${account} 🙌` } - + if (project.website && !project.website.startsWith('http')) { project.website = 'http://' + project.website } - + let items = [] if (account && project && project.owner && account === project.owner.id) { diff --git a/ui/src/pages/projects.js b/ui/src/pages/projects.js index 8c529bb1..95369cf7 100644 --- a/ui/src/pages/projects.js +++ b/ui/src/pages/projects.js @@ -8,7 +8,6 @@ import queryString from 'query-string' import { navigate } from '@reach/router' import { isMobile } from 'react-device-detect' -import { PROJECTS_QUERY, EVEREST_QUERY } from '../utils/apollo/queries' import { FILTERS, ORDER_BY, ORDER_DIRECTION } from '../utils/constants' import Section from '../components/Section' @@ -18,6 +17,7 @@ import Sorting from '../components/Sorting' import Button from '../components/Button' import Seo from '../components/Seo' import Loading from '../components/Loading' +import { everestsDocument, projectsDocument } from '../../.graphclient' const Projects = ({ location }) => { const queryParams = queryString.parse(location.search) @@ -44,20 +44,20 @@ const Projects = ({ location }) => { skip: 0, } - const { data: everestData } = useQuery(EVEREST_QUERY) + const { data: everestData } = useQuery(everestsDocument) - const { error, data, loading, fetchMore } = useQuery(PROJECTS_QUERY, { + const { error, data, loading, fetchMore } = useQuery(projectsDocument, { variables: selectedFilter === FILTERS.all ? variables : selectedFilter === FILTERS.challenged - ? { + ? { ...variables, where: { currentChallenge_not: null, }, } - : { + : { ...variables, where: { isRepresentative: true, @@ -152,8 +152,8 @@ const Projects = ({ location }) => { {selectedFilter === FILTERS.claimed ? ( {claimedCount} Claimed ) : ( - {challengesCount} Challenges - )} + {challengesCount} Challenges + )} { (selectedFilter === FILTERS.all ? data.projects.length < projectCount : selectedFilter === FILTERS.challenged - ? data.projects.length < challengesCount - : data.projects.length < claimedCount) && ( + ? data.projects.length < challengesCount + : data.projects.length < claimedCount) && (