Skip to content

Commit

Permalink
initial conversion + update query
Browse files Browse the repository at this point in the history
  • Loading branch information
benawad committed Aug 17, 2020
1 parent b4c85ce commit 3b45c0a
Show file tree
Hide file tree
Showing 18 changed files with 555 additions and 112 deletions.
2 changes: 1 addition & 1 deletion server/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/lireddit3
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/lireddit2
REDIS_URL=127.0.0.1:6379
PORT=4000
SESSION_SECRET=qowiueojwojfalksdjoqiwueo
Expand Down
2 changes: 1 addition & 1 deletion server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const main = async () => {
migrations: [path.join(__dirname, "./migrations/*")],
entities: [Post, User, Updoot],
});
await conn.runMigrations();
// await conn.runMigrations();

// await Post.delete({});

Expand Down
2 changes: 1 addition & 1 deletion web/codegen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ generates:
plugins:
- "typescript"
- "typescript-operations"
- "typescript-urql"
- "typescript-react-apollo"
2 changes: 2 additions & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"gen": "graphql-codegen --config codegen.yml"
},
"dependencies": {
"@apollo/client": "^3.1.3",
"@chakra-ui/core": "^0.5.2",
"@emotion/core": "^10.0.27",
"@emotion/styled": "^10.0.27",
Expand All @@ -29,6 +30,7 @@
"@graphql-codegen/cli": "1.17.7",
"@graphql-codegen/typescript": "1.17.7",
"@graphql-codegen/typescript-operations": "1.17.7",
"@graphql-codegen/typescript-react-apollo": "^2.0.6",
"@graphql-codegen/typescript-urql": "^2.0.0",
"@types/node": "^14.0.27",
"typescript": "^3.9.7"
Expand Down
6 changes: 3 additions & 3 deletions web/src/components/EditDeletePostButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export const EditDeletePostButtons: React.FC<EditDeletePostButtonsProps> = ({
id,
creatorId,
}) => {
const [{ data: meData }] = useMeQuery();
const [, deletePost] = useDeletePostMutation();
const { data: meData } = useMeQuery();
const [deletePost] = useDeletePostMutation();

if (meData?.me?.id !== creatorId) {
return null;
Expand All @@ -28,7 +28,7 @@ export const EditDeletePostButtons: React.FC<EditDeletePostButtonsProps> = ({
icon="delete"
aria-label="Delete Post"
onClick={() => {
deletePost({ id });
deletePost({ variables: { id } });
}}
/>
</Box>
Expand Down
12 changes: 7 additions & 5 deletions web/src/components/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@ import NextLink from "next/link";
import { useMeQuery, useLogoutMutation } from "../generated/graphql";
import { isServer } from "../utils/isServer";
import { useRouter } from "next/router";
import { useApolloClient } from "@apollo/client";

interface NavBarProps {}

export const NavBar: React.FC<NavBarProps> = ({}) => {
const router = useRouter();
const [{ fetching: logoutFetching }, logout] = useLogoutMutation();
const [{ data, fetching }] = useMeQuery({
pause: isServer(),
const [logout, { loading: logoutFetching }] = useLogoutMutation();
const apolloClient = useApolloClient();
const { data, loading } = useMeQuery({
skip: isServer(),
});

let body = null;

// data is loading
if (fetching) {
if (loading) {
// user not logged in
} else if (!data?.me) {
body = (
Expand All @@ -43,7 +45,7 @@ export const NavBar: React.FC<NavBarProps> = ({}) => {
<Button
onClick={async () => {
await logout();
router.reload();
await apolloClient.resetStore();
}}
isLoading={logoutFetching}
variant="link"
Expand Down
Loading

0 comments on commit 3b45c0a

Please sign in to comment.