From a40d04d1380cc4f9db607637362c9319b28ae04b Mon Sep 17 00:00:00 2001 From: Riccardo Date: Sun, 29 Aug 2021 10:35:05 +0200 Subject: [PATCH] Done --- client/src/components/App.test.js | 8 ---- client/src/components/CreateLink.js | 56 ++++++++++++------------ client/src/components/Header.js | 34 ++++----------- client/src/components/Link.js | 65 +++++++++++----------------- client/src/components/LinkList.js | 4 -- client/src/components/Search.js | 1 - client/src/setupTests.js | 5 --- server/prisma/dev.db | Bin 49152 -> 49152 bytes 8 files changed, 62 insertions(+), 111 deletions(-) delete mode 100644 client/src/components/App.test.js delete mode 100644 client/src/setupTests.js diff --git a/client/src/components/App.test.js b/client/src/components/App.test.js deleted file mode 100644 index 1f03afe..0000000 --- a/client/src/components/App.test.js +++ /dev/null @@ -1,8 +0,0 @@ -import { render, screen } from '@testing-library/react'; -import App from './App'; - -test('renders learn react link', () => { - render(); - const linkElement = screen.getByText(/learn react/i); - expect(linkElement).toBeInTheDocument(); -}); diff --git a/client/src/components/CreateLink.js b/client/src/components/CreateLink.js index 9b6d85c..d810ff6 100644 --- a/client/src/components/CreateLink.js +++ b/client/src/components/CreateLink.js @@ -1,8 +1,8 @@ import React, { useState } from 'react'; import { useHistory } from 'react-router'; import { useMutation, gql } from '@apollo/client'; -import { LINKS_PER_PAGE } from '../constants'; -import { FEED_QUERY } from './LinkList'; +// import { LINKS_PER_PAGE } from '../constants'; +// import { FEED_QUERY } from './LinkList'; const CREATE_LINK_MUTATION = gql` mutation PostMutation( @@ -31,34 +31,34 @@ const CreateLink = () => { description: formState.description, url: formState.url }, - update: (cache, { data: { post } }) => { - const take = LINKS_PER_PAGE; - const skip = 0; - const orderBy = { createdAt: 'desc' }; + // update: (cache, { data: { post } }) => { + // const take = LINKS_PER_PAGE; + // const skip = 0; + // const orderBy = { createdAt: 'desc' }; - const { data } = cache.readQuery({ - query: FEED_QUERY, - variables: { - take, - skip, - orderBy - } - }); + // const { data } = cache.readQuery({ + // query: FEED_QUERY, + // variables: { + // take, + // skip, + // orderBy + // } + // }); - cache.writeQuery({ - query: FEED_QUERY, - data: { - feed: { - links: [post, ...data.feed.links] - } - }, - variables: { - take, - skip, - orderBy - } - }); - }, + // cache.writeQuery({ + // query: FEED_QUERY, + // data: { + // feed: { + // links: [post, ...data.feed.links] + // } + // }, + // variables: { + // take, + // skip, + // orderBy + // } + // }); + // }, onCompleted: () => history.push('/new/1') }); diff --git a/client/src/components/Header.js b/client/src/components/Header.js index 6087837..eddbb18 100644 --- a/client/src/components/Header.js +++ b/client/src/components/Header.js @@ -9,48 +9,30 @@ const Header = () => { return (
-
Hacker News
- - new - +
News
+ Top
|
- - top - + New
|
- - search - + Search {authToken && (
|
- - submit - + Create
)}
{authToken ? ( -
{ +
{ localStorage.removeItem(AUTH_TOKEN); history.push(`/`); }} > - logout + Logout
) : ( - - login - + Login )}
diff --git a/client/src/components/Link.js b/client/src/components/Link.js index 9657f80..3fe2e34 100644 --- a/client/src/components/Link.js +++ b/client/src/components/Link.js @@ -1,8 +1,8 @@ import React from 'react'; import { useMutation, gql } from '@apollo/client'; -import { AUTH_TOKEN, LINKS_PER_PAGE } from '../constants'; +import { AUTH_TOKEN } from '../constants'; import { timeDifferenceForDate } from '../utils' -import { FEED_QUERY } from './LinkList' +// import { FEED_QUERY } from './LinkList' const VOTE_MUTATION = gql` mutation VoteMutation($linkId: ID!) { @@ -24,45 +24,38 @@ const VOTE_MUTATION = gql` } `; -const take = LINKS_PER_PAGE; -const skip = 0; -const orderBy = { createdAt: 'desc' }; - const Link = (props) => { const { link } = props; const authToken = localStorage.getItem(AUTH_TOKEN); - const take = LINKS_PER_PAGE; - const skip = 0; - const orderBy = { createdAt: 'desc' }; const [vote] = useMutation(VOTE_MUTATION, { variables: { linkId: link.id }, - update(cache, { data: { vote } }) { - const { feed } = cache.readQuery({ - query: FEED_QUERY - }); + // update(cache, { data: { vote } }) { + // const { feed } = cache.readQuery({ + // query: FEED_QUERY + // }); - const updatedLinks = feed.links.map((feedLink) => { - if (feedLink.id === link.id) { - return { - ...feedLink, - votes: [...feedLink.votes, vote] - }; - } - return feedLink; - }); + // const updatedLinks = feed.links.map((feedLink) => { + // if (feedLink.id === link.id) { + // return { + // ...feedLink, + // votes: [...feedLink.votes, vote] + // }; + // } + // return feedLink; + // }); - cache.writeQuery({ - query: FEED_QUERY, - data: { - feed: { - links: updatedLinks - } - } - }); - } + // cache.writeQuery({ + // query: FEED_QUERY, + // data: { + // feed: { + // links: updatedLinks + // } + // } + // }); + // } }); return ( @@ -70,19 +63,13 @@ const Link = (props) => {
{props.index + 1}. {authToken && ( -
- ▲ -
+
)}
{link.description} ({link.url}) -
+
{authToken && (
{link.votes.length} votes, submitted by{' '} diff --git a/client/src/components/LinkList.js b/client/src/components/LinkList.js index 2a20b8f..4cf17b0 100644 --- a/client/src/components/LinkList.js +++ b/client/src/components/LinkList.js @@ -75,8 +75,6 @@ const LinkList = () => { pageIndexParams[pageIndexParams.length - 1] ); - console.log(pageIndexParams.length, page); - const pageIndex = page ? (page - 1) * LINKS_PER_PAGE : 0; const { @@ -88,8 +86,6 @@ const LinkList = () => { variables: getQueryVariables(isNewPage, page) }); - // const { data } = useQuery(FEED_QUERY); - const getLinksToRender = (isNewPage, data) => { if (isNewPage) { return data.feed.links; diff --git a/client/src/components/Search.js b/client/src/components/Search.js index a8cb691..166fd71 100644 --- a/client/src/components/Search.js +++ b/client/src/components/Search.js @@ -6,7 +6,6 @@ import Link from './Link'; const FEED_SEARCH_QUERY = gql` query FeedSearchQuery($filter: String!) { feed(filter: $filter) { - id links { id url diff --git a/client/src/setupTests.js b/client/src/setupTests.js deleted file mode 100644 index 8f2609b..0000000 --- a/client/src/setupTests.js +++ /dev/null @@ -1,5 +0,0 @@ -// jest-dom adds custom jest matchers for asserting on DOM nodes. -// allows you to do things like: -// expect(element).toHaveTextContent(/react/i) -// learn more: https://github.com/testing-library/jest-dom -import '@testing-library/jest-dom'; diff --git a/server/prisma/dev.db b/server/prisma/dev.db index 2dad153624af6ed2394845d285cfe129c21127f7..5c9b51633c185e5c7ed4983b8198fcae7c1d2411 100644 GIT binary patch delta 641 zcmY+AO-vI(6vtnB>iG^1kN%U#%wAYT~1Q8hm_Y zk_O+--ygmRU83lsiK3QeT>^hi=a&j@LWso@FJ)KlI8PibOz<1N!^=2?R`!d1VISFR z_LS9_%EGvX4{^CM5IxQs;h>w|lR}Z;?Nd3K(-o5r}b0jY>l$C;7 z=2W1^#Y0Y)5qkOIeZH*ZWw{LQ9`1FS1uwq-kyRy?<2D4|PVPT(?0;je%Du8&&~mC= zscM>;6EyvT)C<$iYi$7gc5F3{E2Pc#clkoPk4KE z$6cbO=GEv5v(PU#nlfDBh2Q#xMV_1GkDkldMkmZw^mo3b|z`)5FTAW(M z3uN)~c`@*BFpk{i4*wVI1zv4g2|DONq z