Skip to content

Commit

Permalink
CreatePost comp adde3d
Browse files Browse the repository at this point in the history
  • Loading branch information
Khumoyun Akhmedov committed Sep 25, 2020
1 parent 8c347f3 commit ea92cad
Show file tree
Hide file tree
Showing 18 changed files with 177 additions and 119 deletions.
14 changes: 14 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"eslint.options": {
"configFile": ".eslintrc"
},
"eslint.probe": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"html",
"markdown"
],
"vetur.validation.template": false
}
4 changes: 2 additions & 2 deletions src/components/BodyWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ export const BodyWrapper: React.FC<WrapperProps> = ({
mt={5}
p={3}
mx="auto"
maxW={variant === "regular" ? "800px" : "400px"}
maxW={variant === 'regular' ? '800px' : '400px'}
w="70%"
h="100%-50px"
>
{children}
</Box>
);
)
}
34 changes: 34 additions & 0 deletions src/components/CreatePost.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react'
import { Flex, Box, Input, Avatar } from '@chakra-ui/core'
// import PropTypes from 'prop-types'
import Link from '../icons/link.svg'
import Media from '../icons/media.svg'

export const CreatePost = (props: any) => {

const handleClick = (e: React.SyntheticEvent, type: string) => {
console.log('handleClick' , type)
}

return (
<Flex alignItems="center" justifyContent="space-between" p={3} bg="#fff" w="100%" my={5} flexDirection="row">
<Avatar mr={3} size="sm" name="Ryan Florence" src="https://bit.ly/ryan-florence"></Avatar>
<Input size='sm'></Input>
<Flex ml={2} w={60} justifyContent="space-around">
<Media
onClick={(e) => handleClick(e, 'up')}
style={{ fill: '#ccc' }}
width={20}
height={20}
></Media>
<Link
onClick={(e) => handleClick(e, 'up')}
style={{ fill: '#ccc' }}
width={20}
height={20}
></Link>
</Flex>
</Flex>
)
}

8 changes: 4 additions & 4 deletions src/components/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { NavBar } from './NavBar'
import { BodyWrapper } from "./BodyWrapper";
import { BodyWrapper } from './BodyWrapper'
import { Box } from '@chakra-ui/core'

interface LayoutProps {
Expand All @@ -10,11 +10,11 @@ interface LayoutProps {

const Layout: React.FC<LayoutProps> = ({ children, variant })=> {
return (
<Box className="reddir-app" bg="#f4f5f7" w="100%" h="100vh">
<Box className="reddir-app" bg="#f4f5f7" w="100%" h="100%">
<NavBar></NavBar>
<BodyWrapper variant={variant}>{children}</BodyWrapper>
</Box>
);
)
}

export default Layout;
export default Layout
6 changes: 3 additions & 3 deletions src/components/MediaUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ const MediaUpload = (props: MediaUploadProps) => {
return (
<Box>
<input
style={{ display: "none" }}
style={{ display: 'none' }}
type="file"
encType="multipart/form-data"
{...props}
/>
</Box>
);
)
}

export default MediaUpload;
export default MediaUpload
7 changes: 4 additions & 3 deletions src/components/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useMeQuery, useLogoutMutation } from '../generated/graphql'


export interface NavBarProps {
dummy?: string
}

export const NavBar: React.FC<NavBarProps> = ({ }) => {
Expand Down Expand Up @@ -34,7 +35,7 @@ export const NavBar: React.FC<NavBarProps> = ({ }) => {
</Button>
</NextLink>
</>
);
)
} else {
body = (
<Flex alignItems="center">
Expand All @@ -61,7 +62,7 @@ export const NavBar: React.FC<NavBarProps> = ({ }) => {
position="sticky"
top={0}
>
<Box ml={"auto"}>{body}</Box>
<Box ml={'auto'}>{body}</Box>
</Flex>
);
)
}
69 changes: 40 additions & 29 deletions src/components/Post.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
import React from 'react'
import { Flex, Box, Heading, PseudoBox } from "@chakra-ui/core";
import Downvote from "../icons/down-arrow.svg";
import Upvote from "../icons/up-arrow.svg";
import React, { useState } from 'react'
import { Flex, Box, Heading } from '@chakra-ui/core'
import Downvote from '../icons/down-arrow.svg'
import Upvote from '../icons/up-arrow.svg'

interface PostProps {
data: Object
interface PostProps {
data: PostData;
}

const Post = ({ data }) => {
const handlePostClick = () => {
console.log("handlePostClick");
export interface PostData {
id: string;
title: string;
content: string;
vote: number;
}

export const Post = ({ data }: PostProps) => {
const [vote, setVote] = useState(data.vote)
const handlePostClick = () => {
console.log('handlePostClick')
}
const handleVote = (e: React.SyntheticEvent, vote: string) => {

const handleVote = (e: React.SyntheticEvent, vote: string) => {
e.stopPropagation()
console.log("vote for post ", vote);
if (vote === 'up') setVote((v) => v + 1)
else setVote((v) => v - 1)
console.log('vote for post ', vote)
}

return (
Expand All @@ -25,7 +36,7 @@ const Post = ({ data }) => {
borderRadius={3}
borderColor="lightgrey"
_hover={{
borderColor: "black",
borderColor: 'black',
}}
cursor="pointer"
onClick={() => handlePostClick()}
Expand All @@ -38,19 +49,21 @@ const Post = ({ data }) => {
borderTopLeftRadius={2}
borderBottomLeftRadius={2}
>
<Upvote
onClick={(e) => handleVote(e, "up")}
style={{ fill: "red" }}
width={18}
height={18}
></Upvote>
<Box>123</Box>
<Downvote
onClick={(e) => handleVote(e, "down")}
style={{ fill: "#455A64" }}
width={18}
height={18}
></Downvote>
<Flex alignItems="center" flexDirection="column" >
<Upvote
onClick={(e) => handleVote(e, 'up')}
style={{ fill: 'red' }}
width={15}
height={15}
></Upvote>
<Box userSelect="none">{vote}</Box>
<Downvote
onClick={(e) => handleVote(e, 'down')}
style={{ fill: '#455A64' }}
width={15}
height={15}
></Downvote>
</Flex>
</Box>

<Flex
Expand All @@ -67,7 +80,5 @@ const Post = ({ data }) => {
<Box fontSize={14}>{data.content}</Box>
</Flex>
</Flex>
);
};

export default Post;
)
}
1 change: 1 addition & 0 deletions src/icons/link.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions src/icons/media.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 7 additions & 40 deletions src/icons/upload-succes.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Empty file added src/pages/channel/[id].tsx
Empty file.
16 changes: 8 additions & 8 deletions src/pages/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Box,
Button,
} from '@chakra-ui/core'
import { BodyWrapper } from "../components/BodyWrapper";
import { BodyWrapper } from '../components/BodyWrapper'
import { InputField } from '../components/InputField'
import { useMutation } from 'urql'
import { useRouter } from 'next/router'
Expand All @@ -17,7 +17,7 @@ import { toErrorMap } from '../utils/errorMapper'
import { withUrqlClient } from 'next-urql'
import { createUrqlClient } from '../utils/createUrqlCLient'

interface loginProps {}
// interface loginProps {}

const Login: React.FC<loginProps> = ({}) => {
const [, login] = useLoginMutation()
Expand All @@ -26,14 +26,14 @@ const Login: React.FC<loginProps> = ({}) => {
return (
<BodyWrapper variant="small">
<Formik
initialValues={{ usernameOrEmail: "", password: "" }}
initialValues={{ usernameOrEmail: '', password: '' }}
onSubmit={async (values, { setErrors }) => {
console.log("values ", values);
const resp = await login(values);
console.log('values ', values)
const resp = await login(values)
if (resp.data?.login.errors) {
setErrors(toErrorMap(resp.data?.login.errors));
setErrors(toErrorMap(resp.data?.login.errors))
} else if (resp.data?.login.member) {
router.push("/");
router.push('/')
}
}}
>
Expand Down Expand Up @@ -64,7 +64,7 @@ const Login: React.FC<loginProps> = ({}) => {
)}
</Formik>
</BodyWrapper>
);
)
}

export default withUrqlClient(createUrqlClient)(Login)
Empty file added src/pages/post/[id].tsx
Empty file.
Empty file added src/pages/post/edit/[id].tsx
Empty file.
Empty file added src/pages/profile/[id].tsx
Empty file.
9 changes: 2 additions & 7 deletions src/pages/register.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
import React from 'react'
import { Formik, Form } from 'formik'
import {
FormControl,
FormLabel,
Input,
FormErrorMessage,
Box,
Button,
} from '@chakra-ui/core'
import { Wrapper } from '../components/BodyWrapper'
import { InputField } from '../components/InputField'
import { useMutation } from 'urql'
import { useRouter } from 'next/router'
import { useRegisterMutation } from '../generated/graphql'
import { toErrorMap } from '../utils/errorMapper'
import { withUrqlClient } from 'next-urql'
import { createUrqlClient } from '../utils/createUrqlCLient'

interface registerProps {}
// interface registerProps {}

const Register: React.FC<registerProps> = ({ }) => {
const router = useRouter();
const router = useRouter()
const [, register] = useRegisterMutation()

return (
Expand Down
Loading

0 comments on commit ea92cad

Please sign in to comment.