Skip to content

Commit 946b9bd

Browse files
committed
(chore) - add comments and try stuff out
1 parent 2437d4b commit 946b9bd

File tree

3 files changed

+39
-14
lines changed

3 files changed

+39
-14
lines changed

src/components/Link.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const Link = ({ link, index }) => {
3030
const voteMutation = React.useCallback(() => {
3131
executeMutation({ linkId: link.id });
3232
}, [link, executeMutation]);
33-
33+
console.log(link);
3434
return (
3535
<div className="flex mt2 items-start">
3636
<div className="flex items-center">

src/components/Login.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@ const Login = ({ history }) => {
2828
const [{ fetching }, executeMutation] = useMutation(login ? LOGIN_MUTATION : SIGNUP_MUTATION);
2929

3030
const mutate = React.useCallback(() => {
31-
executeMutation({ email, password, name }).then(result => {
32-
console.log(result);
33-
const { token } = login ? result.login : result.signup;
31+
executeMutation({ email, password, name }).then(({ data }) => {
32+
const { token } = login ? data.login : data.signup;
3433
localStorage.setItem(AUTH_TOKEN, token);
3534
history.push(`/`);
3635
});
37-
}, [email, password, name, executeMutation]);
36+
}, [email, password, name, executeMutation, history, login]);
3837

3938
return (
4039
<div>

src/index.js

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,66 @@ import {
77
fetchExchange,
88
dedupExchange,
99
subscriptionExchange
10-
} from "urql";;
10+
} from "urql";
1111
import { cacheExchange } from '@urql/exchange-graphcache';
1212
// import { suspenseExchange } from '@urql/exchange-suspense';
1313
import { BrowserRouter } from 'react-router-dom';
1414
import "./styles/index.css";
1515
import App from "./components/App";
16-
import { AUTH_TOKEN, LINKS_PER_PAGE } from './constants'
16+
import { AUTH_TOKEN, LINKS_PER_PAGE } from './constants';
1717
import { FEED_QUERY } from './components/LinkList';
1818
import * as serviceWorker from "./serviceWorker";
19+
// import { timeDifferenceForDate } from './utils';
1920

2021
const cache = cacheExchange({
2122
keys: {
23+
// TODO: evaluate if we're not indicating wrong things by
24+
// warning on these.
2225
Feed: data => data.id || data._id || null,
23-
Link: data => data.id || data._id || null
26+
Link: data => data.id || data._id || null,
2427
},
28+
// Optimistic is not possible due to the nature of the data-structure
29+
// every vote needs to have an unique id for a unique userId...
30+
31+
// We could write a custom resolver to format the datetime of a post
32+
// to indicate the text of x time ago.
33+
// TODO: found inconsistency with resolvers
34+
// Initial write does not respect the resolvers given for querying data.
35+
// resolvers: {
36+
// Link: {
37+
// createdAt: (parent) => {
38+
// console.log('in link resolver');
39+
// return timeDifferenceForDate(parent.createdAt);
40+
// }
41+
// }
42+
// },
43+
44+
// Mutations that need updates due to adding/removing/... to a list
45+
// Will most likely come here. We can't make assumptions for adding to
46+
// a list.
2547
updates: {
2648
Mutation: {
2749
post: ({ post }, _, cache) => {
28-
const first = LINKS_PER_PAGE
29-
const skip = 0
30-
const orderBy = 'createdAt_DESC'
50+
const first = LINKS_PER_PAGE;
51+
const skip = 0;
52+
const orderBy = 'createdAt_DESC';
53+
// TODO: update @urql/exchange-graphcache for this to work
3154
cache.updateQuery(FEED_QUERY, { first, skip, orderBy }, data => {
3255
data.feed.links.unshift(post);
56+
data.feed.count += 1;
3357
return data;
3458
});
3559
},
3660
},
3761
Subscription: {
3862
newLink: ({ newLink }, _, cache) => {
39-
const first = LINKS_PER_PAGE
40-
const skip = 0
41-
const orderBy = 'createdAt_DESC'
63+
const first = LINKS_PER_PAGE;
64+
const skip = 0;
65+
const orderBy = 'createdAt_DESC';
66+
// TODO: update @urql/exchange-graphcache for this to work
4267
cache.updateQuery(FEED_QUERY, { first, skip, orderBy }, data => {
4368
data.feed.links.unshift(newLink);
69+
data.feed.count += 1;
4470
return data;
4571
});
4672
}

0 commit comments

Comments
 (0)