├── .env ├── src ├── react-app-env.d.ts ├── App.module.css ├── setupTests.ts ├── App.tsx ├── index.css ├── App.test.tsx ├── features │ ├── auth │ │ ├── Auth.module.css │ │ ├── authSlice.ts │ │ └── Auth.tsx │ ├── types.ts │ ├── core │ │ ├── Core.module.css │ │ ├── NewPost.tsx │ │ ├── EditProfile.tsx │ │ └── Core.tsx │ └── post │ │ ├── Post.module.css │ │ ├── Post.tsx │ │ └── postSlice.ts ├── app │ └── store.ts ├── index.tsx ├── logo.svg └── serviceWorker.ts ├── public ├── favicon.ico ├── logo192.png ├── logo512.png ├── robots.txt ├── manifest.json └── index.html ├── .gitignore ├── tsconfig.json ├── package.json └── README.md /.env: -------------------------------------------------------------------------------- 1 | REACT_APP_DEV_API_URL="http://localhost:8000/" -------------------------------------------------------------------------------- /src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GomaGoma676/react_insta_udemy/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GomaGoma676/react_insta_udemy/HEAD/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GomaGoma676/react_insta_udemy/HEAD/public/logo512.png -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/App.module.css: -------------------------------------------------------------------------------- 1 | @import url("https://fonts.googleapis.com/css2?family=Playball&display=swap"); 2 | * { 3 | margin: 0; 4 | } 5 | .app { 6 | background-color: #fafafa; 7 | height: 100%; 8 | } 9 | -------------------------------------------------------------------------------- /src/setupTests.ts: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom/extend-expect'; 6 | -------------------------------------------------------------------------------- /src/App.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | import styles from "./App.module.css"; 4 | import Core from "./features/core/Core"; 5 | 6 | function App() { 7 | return ( 8 |
9 | 10 |
11 | ); 12 | } 13 | 14 | export default App; 15 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /src/App.test.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render } from '@testing-library/react'; 3 | import { Provider } from 'react-redux'; 4 | import { store } from './app/store'; 5 | import App from './App'; 6 | 7 | test('renders learn react link', () => { 8 | const { getByText } = render( 9 | 10 | 11 | 12 | ); 13 | 14 | expect(getByText(/learn/i)).toBeInTheDocument(); 15 | }); 16 | -------------------------------------------------------------------------------- /src/features/auth/Auth.module.css: -------------------------------------------------------------------------------- 1 | .auth_title { 2 | font-family: "Playball", cursive; 3 | font-weight: normal; 4 | text-align: center; 5 | } 6 | .auth_error { 7 | color: #ff00ff; 8 | text-align: center; 9 | margin: 10px; 10 | } 11 | .auth_signUp { 12 | display: flex; 13 | flex-direction: column; 14 | } 15 | .auth_headerImage { 16 | object-fit: contain; 17 | } 18 | .auth_text { 19 | color: rgb(6, 153, 211); 20 | text-align: center; 21 | cursor: pointer; 22 | } 23 | .auth_progress { 24 | margin-top: 15px; 25 | display: flex; 26 | justify-content: center; 27 | } 28 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "strict": true, 14 | "forceConsistentCasingInFileNames": true, 15 | "module": "esnext", 16 | "moduleResolution": "node", 17 | "resolveJsonModule": true, 18 | "isolatedModules": true, 19 | "noEmit": true, 20 | "jsx": "react" 21 | }, 22 | "include": [ 23 | "src" 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /src/app/store.ts: -------------------------------------------------------------------------------- 1 | import { configureStore, ThunkAction, Action } from "@reduxjs/toolkit"; 2 | 3 | import authReducer from "../features/auth/authSlice"; 4 | import postReducer from "../features/post/postSlice"; 5 | export const store = configureStore({ 6 | reducer: { 7 | auth: authReducer, 8 | post: postReducer, 9 | }, 10 | }); 11 | 12 | export type RootState = ReturnType; 13 | export type AppThunk = ThunkAction< 14 | ReturnType, 15 | RootState, 16 | unknown, 17 | Action 18 | >; 19 | export type AppDispatch = typeof store.dispatch; 20 | -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import { store } from './app/store'; 6 | import { Provider } from 'react-redux'; 7 | import * as serviceWorker from './serviceWorker'; 8 | 9 | ReactDOM.render( 10 | 11 | 12 | 13 | 14 | , 15 | document.getElementById('root') 16 | ); 17 | 18 | // If you want your app to work offline and load faster, you can change 19 | // unregister() to register() below. Note this comes with some pitfalls. 20 | // Learn more about service workers: https://bit.ly/CRA-PWA 21 | serviceWorker.unregister(); 22 | -------------------------------------------------------------------------------- /src/features/types.ts: -------------------------------------------------------------------------------- 1 | export interface File extends Blob { 2 | readonly lastModified: number; 3 | readonly name: string; 4 | } 5 | /*authSlice.ts*/ 6 | export interface PROPS_AUTHEN { 7 | email: string; 8 | password: string; 9 | } 10 | 11 | export interface PROPS_PROFILE { 12 | id: number; 13 | nickName: string; 14 | img: File | null; 15 | } 16 | 17 | export interface PROPS_NICKNAME { 18 | nickName: string; 19 | } 20 | 21 | /*postSlice.ts*/ 22 | export interface PROPS_NEWPOST { 23 | title: string; 24 | img: File | null; 25 | } 26 | export interface PROPS_LIKED { 27 | id: number; 28 | title: string; 29 | current: number[]; 30 | new: number; 31 | } 32 | export interface PROPS_COMMENT { 33 | text: string; 34 | post: number; 35 | } 36 | /*Post.tsx*/ 37 | export interface PROPS_POST { 38 | postId: number; 39 | loginId: number; 40 | userPost: number; 41 | title: string; 42 | imageUrl: string; 43 | liked: number[]; 44 | } 45 | -------------------------------------------------------------------------------- /src/features/core/Core.module.css: -------------------------------------------------------------------------------- 1 | .core_title { 2 | font-family: "Playball", cursive; 3 | font-weight: normal; 4 | text-align: center; 5 | } 6 | .core_signUp { 7 | display: flex; 8 | flex-direction: column; 9 | } 10 | 11 | .core_text { 12 | color: rgb(6, 153, 211); 13 | text-align: center; 14 | cursor: pointer; 15 | } 16 | .core_header { 17 | position: sticky; 18 | top: 0; 19 | background-color: white; 20 | padding: 20px; 21 | border-bottom: 1px solid lightgray; 22 | object-fit: contain; 23 | display: flex; 24 | z-index: 1; 25 | justify-content: space-between; 26 | } 27 | .core_btnModal { 28 | background-color: transparent; 29 | color: gray; 30 | padding-top: 3px; 31 | font-size: 32px; 32 | border: none; 33 | outline: none; 34 | cursor: pointer; 35 | } 36 | 37 | .core_logout { 38 | display: flex; 39 | justify-content: flex-end; 40 | } 41 | .core_posts { 42 | padding: 20px; 43 | } 44 | .core_progress { 45 | margin-top: 15px; 46 | display: flex; 47 | justify-content: center; 48 | } 49 | -------------------------------------------------------------------------------- /src/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/features/post/Post.module.css: -------------------------------------------------------------------------------- 1 | .post { 2 | background-color: white; 3 | max-width: 100%; 4 | border: 1px solid lightgray; 5 | margin-bottom: 10px; 6 | } 7 | .post_header { 8 | display: flex; 9 | align-items: center; 10 | padding: 15px; 11 | } 12 | .post_avatar { 13 | margin-right: 10px; 14 | z-index: 0; 15 | } 16 | .post_image { 17 | width: 100%; 18 | height: 280px; 19 | object-fit: contain; 20 | } 21 | .post_text { 22 | font-weight: normal; 23 | padding: 20px; 24 | word-break: break-all; 25 | } 26 | 27 | .post_checkBox { 28 | z-index: 0; 29 | } 30 | .post_avatarGroup { 31 | z-index: 0 !important; 32 | } 33 | .post_comments { 34 | padding: 20px; 35 | } 36 | .post_comment { 37 | display: flex; 38 | align-items: center; 39 | margin-bottom: 5px; 40 | word-break: break-all; 41 | } 42 | .post_commentBox { 43 | display: flex; 44 | margin-top: 10px; 45 | } 46 | .post_input { 47 | flex: 1; 48 | padding: 10px; 49 | border: none; 50 | border-top: 1px solid lightgray; 51 | } 52 | .post_button { 53 | flex: 0; 54 | border: none; 55 | color: #4682b4; 56 | background-color: transparent; 57 | border-top: 1px solid lightgray; 58 | cursor: pointer; 59 | } 60 | .post_strong { 61 | margin-right: 5px; 62 | } 63 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react_insta", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@material-ui/core": "^4.11.0", 7 | "@material-ui/icons": "^4.9.1", 8 | "@material-ui/lab": "^4.0.0-alpha.56", 9 | "@reduxjs/toolkit": "^1.4.0", 10 | "@testing-library/jest-dom": "^4.2.4", 11 | "@testing-library/react": "^9.5.0", 12 | "@testing-library/user-event": "^7.2.1", 13 | "@types/jest": "^24.9.1", 14 | "@types/node": "^12.12.53", 15 | "@types/react": "^16.9.43", 16 | "@types/react-dom": "^16.9.8", 17 | "@types/react-modal": "^3.10.6", 18 | "@types/react-redux": "^7.1.9", 19 | "@types/yup": "^0.29.3", 20 | "axios": "^0.19.2", 21 | "formik": "^2.1.5", 22 | "formik-material-ui": "^2.0.1", 23 | "react": "^16.13.1", 24 | "react-dom": "^16.13.1", 25 | "react-icons": "^3.10.0", 26 | "react-modal": "^3.11.2", 27 | "react-redux": "^7.2.0", 28 | "react-scripts": "3.4.1", 29 | "typescript": "^3.8.3", 30 | "yup": "^0.29.1" 31 | }, 32 | "scripts": { 33 | "start": "react-scripts start", 34 | "build": "react-scripts build", 35 | "test": "react-scripts test", 36 | "eject": "react-scripts eject" 37 | }, 38 | "eslintConfig": { 39 | "extends": "react-app" 40 | }, 41 | "browserslist": { 42 | "production": [ 43 | ">0.2%", 44 | "not dead", 45 | "not op_mini all" 46 | ], 47 | "development": [ 48 | "last 1 chrome version", 49 | "last 1 firefox version", 50 | "last 1 safari version" 51 | ] 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React Redux App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app), using the [Redux](https://redux.js.org/) and [Redux Toolkit](https://redux-toolkit.js.org/) template. 2 | 3 | ## Available Scripts 4 | 5 | In the project directory, you can run: 6 | 7 | ### `npm start` 8 | 9 | Runs the app in the development mode.
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 11 | 12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console. 14 | 15 | ### `npm test` 16 | 17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 19 | 20 | ### `npm run build` 21 | 22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance. 24 | 25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed! 27 | 28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 29 | 30 | ### `npm run eject` 31 | 32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 33 | 34 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 35 | 36 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 37 | 38 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 39 | 40 | ## Learn More 41 | 42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 43 | 44 | To learn React, check out the [React documentation](https://reactjs.org/). 45 | -------------------------------------------------------------------------------- /src/features/core/NewPost.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import Modal from "react-modal"; 3 | import { useSelector, useDispatch } from "react-redux"; 4 | import { AppDispatch } from "../../app/store"; 5 | 6 | import styles from "./Core.module.css"; 7 | 8 | import { File } from "../types"; 9 | 10 | import { 11 | selectOpenNewPost, 12 | resetOpenNewPost, 13 | fetchPostStart, 14 | fetchPostEnd, 15 | fetchAsyncNewPost, 16 | } from "../post/postSlice"; 17 | 18 | import { Button, TextField, IconButton } from "@material-ui/core"; 19 | import { MdAddAPhoto } from "react-icons/md"; 20 | 21 | const customStyles = { 22 | content: { 23 | top: "55%", 24 | left: "50%", 25 | 26 | width: 280, 27 | height: 220, 28 | padding: "50px", 29 | 30 | transform: "translate(-50%, -50%)", 31 | }, 32 | }; 33 | 34 | const NewPost: React.FC = () => { 35 | const dispatch: AppDispatch = useDispatch(); 36 | const openNewPost = useSelector(selectOpenNewPost); 37 | 38 | const [image, setImage] = useState(null); 39 | const [title, setTitle] = useState(""); 40 | 41 | const handlerEditPicture = () => { 42 | const fileInput = document.getElementById("imageInput"); 43 | fileInput?.click(); 44 | }; 45 | 46 | const newPost = async (e: React.MouseEvent) => { 47 | e.preventDefault(); 48 | const packet = { title: title, img: image }; 49 | await dispatch(fetchPostStart()); 50 | await dispatch(fetchAsyncNewPost(packet)); 51 | await dispatch(fetchPostEnd()); 52 | setTitle(""); 53 | setImage(null); 54 | dispatch(resetOpenNewPost()); 55 | }; 56 | 57 | return ( 58 | <> 59 | { 62 | await dispatch(resetOpenNewPost()); 63 | }} 64 | style={customStyles} 65 | > 66 |
67 |

SNS clone

68 | 69 |
70 | setTitle(e.target.value)} 74 | /> 75 | 76 | setImage(e.target.files![0])} 81 | /> 82 |
83 | 84 | 85 | 86 |
87 | 95 | 96 |
97 | 98 | ); 99 | }; 100 | 101 | export default NewPost; 102 | -------------------------------------------------------------------------------- /src/features/core/EditProfile.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import Modal from "react-modal"; 3 | import styles from "./Core.module.css"; 4 | 5 | import { useSelector, useDispatch } from "react-redux"; 6 | import { AppDispatch } from "../../app/store"; 7 | 8 | import { File } from "../types"; 9 | 10 | import { 11 | editNickname, 12 | selectProfile, 13 | selectOpenProfile, 14 | resetOpenProfile, 15 | fetchCredStart, 16 | fetchCredEnd, 17 | fetchAsyncUpdateProf, 18 | } from "../auth/authSlice"; 19 | 20 | import { Button, TextField, IconButton } from "@material-ui/core"; 21 | import { MdAddAPhoto } from "react-icons/md"; 22 | 23 | const customStyles = { 24 | content: { 25 | top: "55%", 26 | left: "50%", 27 | 28 | width: 280, 29 | height: 220, 30 | padding: "50px", 31 | 32 | transform: "translate(-50%, -50%)", 33 | }, 34 | }; 35 | 36 | const EditProfile: React.FC = () => { 37 | const dispatch: AppDispatch = useDispatch(); 38 | const openProfile = useSelector(selectOpenProfile); 39 | const profile = useSelector(selectProfile); 40 | const [image, setImage] = useState(null); 41 | 42 | const updateProfile = async (e: React.MouseEvent) => { 43 | e.preventDefault(); 44 | const packet = { id: profile.id, nickName: profile.nickName, img: image }; 45 | 46 | await dispatch(fetchCredStart()); 47 | await dispatch(fetchAsyncUpdateProf(packet)); 48 | await dispatch(fetchCredEnd()); 49 | await dispatch(resetOpenProfile()); 50 | }; 51 | 52 | const handlerEditPicture = () => { 53 | const fileInput = document.getElementById("imageInput"); 54 | fileInput?.click(); 55 | }; 56 | 57 | return ( 58 | <> 59 | { 62 | await dispatch(resetOpenProfile()); 63 | }} 64 | style={customStyles} 65 | > 66 |
67 |

SNS clone

68 | 69 |
70 | dispatch(editNickname(e.target.value))} 75 | /> 76 | 77 | setImage(e.target.files![0])} 82 | /> 83 |
84 | 85 | 86 | 87 |
88 | 97 | 98 |
99 | 100 | ); 101 | }; 102 | 103 | export default EditProfile; 104 | -------------------------------------------------------------------------------- /src/features/post/Post.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import styles from "./Post.module.css"; 3 | 4 | import { makeStyles } from "@material-ui/core/styles"; 5 | import { Avatar, Divider, Checkbox } from "@material-ui/core"; 6 | import { Favorite, FavoriteBorder } from "@material-ui/icons"; 7 | 8 | import AvatarGroup from "@material-ui/lab/AvatarGroup"; 9 | 10 | import { useSelector, useDispatch } from "react-redux"; 11 | import { AppDispatch } from "../../app/store"; 12 | 13 | import { selectProfiles } from "../auth/authSlice"; 14 | 15 | import { 16 | selectComments, 17 | fetchPostStart, 18 | fetchPostEnd, 19 | fetchAsyncPostComment, 20 | fetchAsyncPatchLiked, 21 | } from "./postSlice"; 22 | 23 | import { PROPS_POST } from "../types"; 24 | 25 | const useStyles = makeStyles((theme) => ({ 26 | small: { 27 | width: theme.spacing(3), 28 | height: theme.spacing(3), 29 | marginRight: theme.spacing(1), 30 | }, 31 | })); 32 | 33 | const Post: React.FC = ({ 34 | postId, 35 | loginId, 36 | userPost, 37 | title, 38 | imageUrl, 39 | liked, 40 | }) => { 41 | const classes = useStyles(); 42 | const dispatch: AppDispatch = useDispatch(); 43 | const profiles = useSelector(selectProfiles); 44 | const comments = useSelector(selectComments); 45 | const [text, setText] = useState(""); 46 | 47 | const commentsOnPost = comments.filter((com) => { 48 | return com.post === postId; 49 | }); 50 | 51 | const prof = profiles.filter((prof) => { 52 | return prof.userProfile === userPost; 53 | }); 54 | 55 | const postComment = async (e: React.MouseEvent) => { 56 | e.preventDefault(); 57 | const packet = { text: text, post: postId }; 58 | await dispatch(fetchPostStart()); 59 | await dispatch(fetchAsyncPostComment(packet)); 60 | await dispatch(fetchPostEnd()); 61 | setText(""); 62 | }; 63 | 64 | const handlerLiked = async () => { 65 | const packet = { 66 | id: postId, 67 | title: title, 68 | current: liked, 69 | new: loginId, 70 | }; 71 | await dispatch(fetchPostStart()); 72 | await dispatch(fetchAsyncPatchLiked(packet)); 73 | await dispatch(fetchPostEnd()); 74 | }; 75 | 76 | if (title) { 77 | return ( 78 |
79 |
80 | 81 |

{prof[0]?.nickName}

82 |
83 | 84 | 85 |

86 | } 89 | checkedIcon={} 90 | checked={liked.some((like) => like === loginId)} 91 | onChange={handlerLiked} 92 | /> 93 | {prof[0]?.nickName} {title} 94 | 95 | {liked.map((like) => ( 96 | prof.userProfile === like)?.img} 100 | /> 101 | ))} 102 | 103 |

104 | 105 | 106 |
107 | {commentsOnPost.map((comment) => ( 108 |
109 | prof.userProfile === comment.userComment 113 | )?.img 114 | } 115 | className={classes.small} 116 | /> 117 |

118 | 119 | { 120 | profiles.find( 121 | (prof) => prof.userProfile === comment.userComment 122 | )?.nickName 123 | } 124 | 125 | {comment.text} 126 |

127 |
128 | ))} 129 |
130 | 131 |
132 | setText(e.target.value)} 138 | /> 139 | 147 |
148 |
149 | ); 150 | } 151 | return null; 152 | }; 153 | 154 | export default Post; 155 | -------------------------------------------------------------------------------- /src/features/post/postSlice.ts: -------------------------------------------------------------------------------- 1 | import { createSlice, createAsyncThunk } from "@reduxjs/toolkit"; 2 | import { RootState } from "../../app/store"; 3 | import axios from "axios"; 4 | import { PROPS_NEWPOST, PROPS_LIKED, PROPS_COMMENT } from "../types"; 5 | 6 | const apiUrlPost = `${process.env.REACT_APP_DEV_API_URL}api/post/`; 7 | const apiUrlComment = `${process.env.REACT_APP_DEV_API_URL}api/comment/`; 8 | 9 | export const fetchAsyncGetPosts = createAsyncThunk("post/get", async () => { 10 | const res = await axios.get(apiUrlPost, { 11 | headers: { 12 | Authorization: `JWT ${localStorage.localJWT}`, 13 | }, 14 | }); 15 | return res.data; 16 | }); 17 | 18 | export const fetchAsyncNewPost = createAsyncThunk( 19 | "post/post", 20 | async (newPost: PROPS_NEWPOST) => { 21 | const uploadData = new FormData(); 22 | uploadData.append("title", newPost.title); 23 | newPost.img && uploadData.append("img", newPost.img, newPost.img.name); 24 | const res = await axios.post(apiUrlPost, uploadData, { 25 | headers: { 26 | "Content-Type": "application/json", 27 | Authorization: `JWT ${localStorage.localJWT}`, 28 | }, 29 | }); 30 | return res.data; 31 | } 32 | ); 33 | 34 | export const fetchAsyncPatchLiked = createAsyncThunk( 35 | "post/patch", 36 | async (liked: PROPS_LIKED) => { 37 | const currentLiked = liked.current; 38 | const uploadData = new FormData(); 39 | 40 | let isOverlapped = false; 41 | currentLiked.forEach((current) => { 42 | if (current === liked.new) { 43 | isOverlapped = true; 44 | } else { 45 | uploadData.append("liked", String(current)); 46 | } 47 | }); 48 | 49 | if (!isOverlapped) { 50 | uploadData.append("liked", String(liked.new)); 51 | } else if (currentLiked.length === 1) { 52 | uploadData.append("title", liked.title); 53 | const res = await axios.put(`${apiUrlPost}${liked.id}/`, uploadData, { 54 | headers: { 55 | "Content-Type": "application/json", 56 | Authorization: `JWT ${localStorage.localJWT}`, 57 | }, 58 | }); 59 | return res.data; 60 | } 61 | const res = await axios.patch(`${apiUrlPost}${liked.id}/`, uploadData, { 62 | headers: { 63 | "Content-Type": "application/json", 64 | Authorization: `JWT ${localStorage.localJWT}`, 65 | }, 66 | }); 67 | return res.data; 68 | } 69 | ); 70 | 71 | export const fetchAsyncGetComments = createAsyncThunk( 72 | "comment/get", 73 | async () => { 74 | const res = await axios.get(apiUrlComment, { 75 | headers: { 76 | Authorization: `JWT ${localStorage.localJWT}`, 77 | }, 78 | }); 79 | return res.data; 80 | } 81 | ); 82 | 83 | export const fetchAsyncPostComment = createAsyncThunk( 84 | "comment/post", 85 | async (comment: PROPS_COMMENT) => { 86 | const res = await axios.post(apiUrlComment, comment, { 87 | headers: { 88 | Authorization: `JWT ${localStorage.localJWT}`, 89 | }, 90 | }); 91 | return res.data; 92 | } 93 | ); 94 | 95 | export const postSlice = createSlice({ 96 | name: "post", 97 | initialState: { 98 | isLoadingPost: false, 99 | openNewPost: false, 100 | posts: [ 101 | { 102 | id: 0, 103 | title: "", 104 | userPost: 0, 105 | created_on: "", 106 | img: "", 107 | liked: [0], 108 | }, 109 | ], 110 | comments: [ 111 | { 112 | id: 0, 113 | text: "", 114 | userComment: 0, 115 | post: 0, 116 | }, 117 | ], 118 | }, 119 | reducers: { 120 | fetchPostStart(state) { 121 | state.isLoadingPost = true; 122 | }, 123 | fetchPostEnd(state) { 124 | state.isLoadingPost = false; 125 | }, 126 | setOpenNewPost(state) { 127 | state.openNewPost = true; 128 | }, 129 | resetOpenNewPost(state) { 130 | state.openNewPost = false; 131 | }, 132 | }, 133 | extraReducers: (builder) => { 134 | builder.addCase(fetchAsyncGetPosts.fulfilled, (state, action) => { 135 | return { 136 | ...state, 137 | posts: action.payload, 138 | }; 139 | }); 140 | builder.addCase(fetchAsyncNewPost.fulfilled, (state, action) => { 141 | return { 142 | ...state, 143 | posts: [...state.posts, action.payload], 144 | }; 145 | }); 146 | builder.addCase(fetchAsyncGetComments.fulfilled, (state, action) => { 147 | return { 148 | ...state, 149 | comments: action.payload, 150 | }; 151 | }); 152 | builder.addCase(fetchAsyncPostComment.fulfilled, (state, action) => { 153 | return { 154 | ...state, 155 | comments: [...state.comments, action.payload], 156 | }; 157 | }); 158 | builder.addCase(fetchAsyncPatchLiked.fulfilled, (state, action) => { 159 | return { 160 | ...state, 161 | posts: state.posts.map((post) => 162 | post.id === action.payload.id ? action.payload : post 163 | ), 164 | }; 165 | }); 166 | }, 167 | }); 168 | 169 | export const { 170 | fetchPostStart, 171 | fetchPostEnd, 172 | setOpenNewPost, 173 | resetOpenNewPost, 174 | } = postSlice.actions; 175 | 176 | export const selectIsLoadingPost = (state: RootState) => 177 | state.post.isLoadingPost; 178 | export const selectOpenNewPost = (state: RootState) => state.post.openNewPost; 179 | export const selectPosts = (state: RootState) => state.post.posts; 180 | export const selectComments = (state: RootState) => state.post.comments; 181 | 182 | export default postSlice.reducer; 183 | -------------------------------------------------------------------------------- /src/features/auth/authSlice.ts: -------------------------------------------------------------------------------- 1 | import { createSlice, createAsyncThunk } from "@reduxjs/toolkit"; 2 | import { RootState } from "../../app/store"; 3 | import axios from "axios"; 4 | import { PROPS_AUTHEN, PROPS_PROFILE, PROPS_NICKNAME } from "../types"; 5 | 6 | const apiUrl = process.env.REACT_APP_DEV_API_URL; 7 | 8 | export const fetchAsyncLogin = createAsyncThunk( 9 | "auth/post", 10 | async (authen: PROPS_AUTHEN) => { 11 | const res = await axios.post(`${apiUrl}authen/jwt/create`, authen, { 12 | headers: { 13 | "Content-Type": "application/json", 14 | }, 15 | }); 16 | return res.data; 17 | } 18 | ); 19 | 20 | export const fetchAsyncRegister = createAsyncThunk( 21 | "auth/register", 22 | async (auth: PROPS_AUTHEN) => { 23 | const res = await axios.post(`${apiUrl}api/register/`, auth, { 24 | headers: { 25 | "Content-Type": "application/json", 26 | }, 27 | }); 28 | return res.data; 29 | } 30 | ); 31 | 32 | export const fetchAsyncCreateProf = createAsyncThunk( 33 | "profile/post", 34 | async (nickName: PROPS_NICKNAME) => { 35 | const res = await axios.post(`${apiUrl}api/profile/`, nickName, { 36 | headers: { 37 | "Content-Type": "application/json", 38 | Authorization: `JWT ${localStorage.localJWT}`, 39 | }, 40 | }); 41 | return res.data; 42 | } 43 | ); 44 | 45 | export const fetchAsyncUpdateProf = createAsyncThunk( 46 | "profile/put", 47 | async (profile: PROPS_PROFILE) => { 48 | const uploadData = new FormData(); 49 | uploadData.append("nickName", profile.nickName); 50 | profile.img && uploadData.append("img", profile.img, profile.img.name); 51 | const res = await axios.put( 52 | `${apiUrl}api/profile/${profile.id}/`, 53 | uploadData, 54 | { 55 | headers: { 56 | "Content-Type": "application/json", 57 | Authorization: `JWT ${localStorage.localJWT}`, 58 | }, 59 | } 60 | ); 61 | return res.data; 62 | } 63 | ); 64 | 65 | export const fetchAsyncGetMyProf = createAsyncThunk("profile/get", async () => { 66 | const res = await axios.get(`${apiUrl}api/myprofile/`, { 67 | headers: { 68 | Authorization: `JWT ${localStorage.localJWT}`, 69 | }, 70 | }); 71 | return res.data[0]; 72 | }); 73 | 74 | export const fetchAsyncGetProfs = createAsyncThunk("profiles/get", async () => { 75 | const res = await axios.get(`${apiUrl}api/profile/`, { 76 | headers: { 77 | Authorization: `JWT ${localStorage.localJWT}`, 78 | }, 79 | }); 80 | return res.data; 81 | }); 82 | 83 | export const authSlice = createSlice({ 84 | name: "auth", 85 | initialState: { 86 | openSignIn: true, 87 | openSignUp: false, 88 | openProfile: false, 89 | isLoadingAuth: false, 90 | myprofile: { 91 | id: 0, 92 | nickName: "", 93 | userProfile: 0, 94 | created_on: "", 95 | img: "", 96 | }, 97 | profiles: [ 98 | { 99 | id: 0, 100 | nickName: "", 101 | userProfile: 0, 102 | created_on: "", 103 | img: "", 104 | }, 105 | ], 106 | }, 107 | reducers: { 108 | fetchCredStart(state) { 109 | state.isLoadingAuth = true; 110 | }, 111 | fetchCredEnd(state) { 112 | state.isLoadingAuth = false; 113 | }, 114 | setOpenSignIn(state) { 115 | state.openSignIn = true; 116 | }, 117 | resetOpenSignIn(state) { 118 | state.openSignIn = false; 119 | }, 120 | setOpenSignUp(state) { 121 | state.openSignUp = true; 122 | }, 123 | resetOpenSignUp(state) { 124 | state.openSignUp = false; 125 | }, 126 | setOpenProfile(state) { 127 | state.openProfile = true; 128 | }, 129 | resetOpenProfile(state) { 130 | state.openProfile = false; 131 | }, 132 | editNickname(state, action) { 133 | state.myprofile.nickName = action.payload; 134 | }, 135 | }, 136 | extraReducers: (builder) => { 137 | builder.addCase(fetchAsyncLogin.fulfilled, (state, action) => { 138 | localStorage.setItem("localJWT", action.payload.access); 139 | }); 140 | builder.addCase(fetchAsyncCreateProf.fulfilled, (state, action) => { 141 | state.myprofile = action.payload; 142 | }); 143 | builder.addCase(fetchAsyncGetMyProf.fulfilled, (state, action) => { 144 | state.myprofile = action.payload; 145 | }); 146 | builder.addCase(fetchAsyncGetProfs.fulfilled, (state, action) => { 147 | state.profiles = action.payload; 148 | }); 149 | builder.addCase(fetchAsyncUpdateProf.fulfilled, (state, action) => { 150 | state.myprofile = action.payload; 151 | state.profiles = state.profiles.map((prof) => 152 | prof.id === action.payload.id ? action.payload : prof 153 | ); 154 | }); 155 | }, 156 | }); 157 | 158 | export const { 159 | fetchCredStart, 160 | fetchCredEnd, 161 | setOpenSignIn, 162 | resetOpenSignIn, 163 | setOpenSignUp, 164 | resetOpenSignUp, 165 | setOpenProfile, 166 | resetOpenProfile, 167 | editNickname, 168 | } = authSlice.actions; 169 | 170 | export const selectIsLoadingAuth = (state: RootState) => 171 | state.auth.isLoadingAuth; 172 | export const selectOpenSignIn = (state: RootState) => state.auth.openSignIn; 173 | export const selectOpenSignUp = (state: RootState) => state.auth.openSignUp; 174 | export const selectOpenProfile = (state: RootState) => state.auth.openProfile; 175 | export const selectProfile = (state: RootState) => state.auth.myprofile; 176 | export const selectProfiles = (state: RootState) => state.auth.profiles; 177 | 178 | export default authSlice.reducer; 179 | -------------------------------------------------------------------------------- /src/serviceWorker.ts: -------------------------------------------------------------------------------- 1 | // This optional code is used to register a service worker. 2 | // register() is not called by default. 3 | 4 | // This lets the app load faster on subsequent visits in production, and gives 5 | // it offline capabilities. However, it also means that developers (and users) 6 | // will only see deployed updates on subsequent visits to a page, after all the 7 | // existing tabs open on the page have been closed, since previously cached 8 | // resources are updated in the background. 9 | 10 | // To learn more about the benefits of this model and instructions on how to 11 | // opt-in, read https://bit.ly/CRA-PWA 12 | 13 | const isLocalhost = Boolean( 14 | window.location.hostname === 'localhost' || 15 | // [::1] is the IPv6 localhost address. 16 | window.location.hostname === '[::1]' || 17 | // 127.0.0.0/8 are considered localhost for IPv4. 18 | window.location.hostname.match( 19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 20 | ) 21 | ); 22 | 23 | type Config = { 24 | onSuccess?: (registration: ServiceWorkerRegistration) => void; 25 | onUpdate?: (registration: ServiceWorkerRegistration) => void; 26 | }; 27 | 28 | export function register(config?: Config) { 29 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 30 | // The URL constructor is available in all browsers that support SW. 31 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href); 32 | if (publicUrl.origin !== window.location.origin) { 33 | // Our service worker won't work if PUBLIC_URL is on a different origin 34 | // from what our page is served on. This might happen if a CDN is used to 35 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 36 | return; 37 | } 38 | 39 | window.addEventListener('load', () => { 40 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 41 | 42 | if (isLocalhost) { 43 | // This is running on localhost. Let's check if a service worker still exists or not. 44 | checkValidServiceWorker(swUrl, config); 45 | 46 | // Add some additional logging to localhost, pointing developers to the 47 | // service worker/PWA documentation. 48 | navigator.serviceWorker.ready.then(() => { 49 | console.log( 50 | 'This web app is being served cache-first by a service ' + 51 | 'worker. To learn more, visit https://bit.ly/CRA-PWA' 52 | ); 53 | }); 54 | } else { 55 | // Is not localhost. Just register service worker 56 | registerValidSW(swUrl, config); 57 | } 58 | }); 59 | } 60 | } 61 | 62 | function registerValidSW(swUrl: string, config?: Config) { 63 | navigator.serviceWorker 64 | .register(swUrl) 65 | .then(registration => { 66 | registration.onupdatefound = () => { 67 | const installingWorker = registration.installing; 68 | if (installingWorker == null) { 69 | return; 70 | } 71 | installingWorker.onstatechange = () => { 72 | if (installingWorker.state === 'installed') { 73 | if (navigator.serviceWorker.controller) { 74 | // At this point, the updated precached content has been fetched, 75 | // but the previous service worker will still serve the older 76 | // content until all client tabs are closed. 77 | console.log( 78 | 'New content is available and will be used when all ' + 79 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' 80 | ); 81 | 82 | // Execute callback 83 | if (config && config.onUpdate) { 84 | config.onUpdate(registration); 85 | } 86 | } else { 87 | // At this point, everything has been precached. 88 | // It's the perfect time to display a 89 | // "Content is cached for offline use." message. 90 | console.log('Content is cached for offline use.'); 91 | 92 | // Execute callback 93 | if (config && config.onSuccess) { 94 | config.onSuccess(registration); 95 | } 96 | } 97 | } 98 | }; 99 | }; 100 | }) 101 | .catch(error => { 102 | console.error('Error during service worker registration:', error); 103 | }); 104 | } 105 | 106 | function checkValidServiceWorker(swUrl: string, config?: Config) { 107 | // Check if the service worker can be found. If it can't reload the page. 108 | fetch(swUrl, { 109 | headers: { 'Service-Worker': 'script' }, 110 | }) 111 | .then(response => { 112 | // Ensure service worker exists, and that we really are getting a JS file. 113 | const contentType = response.headers.get('content-type'); 114 | if ( 115 | response.status === 404 || 116 | (contentType != null && contentType.indexOf('javascript') === -1) 117 | ) { 118 | // No service worker found. Probably a different app. Reload the page. 119 | navigator.serviceWorker.ready.then(registration => { 120 | registration.unregister().then(() => { 121 | window.location.reload(); 122 | }); 123 | }); 124 | } else { 125 | // Service worker found. Proceed as normal. 126 | registerValidSW(swUrl, config); 127 | } 128 | }) 129 | .catch(() => { 130 | console.log( 131 | 'No internet connection found. App is running in offline mode.' 132 | ); 133 | }); 134 | } 135 | 136 | export function unregister() { 137 | if ('serviceWorker' in navigator) { 138 | navigator.serviceWorker.ready 139 | .then(registration => { 140 | registration.unregister(); 141 | }) 142 | .catch(error => { 143 | console.error(error.message); 144 | }); 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /src/features/core/Core.tsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect } from "react"; 2 | import Auth from "../auth/Auth"; 3 | 4 | import styles from "./Core.module.css"; 5 | import { useSelector, useDispatch } from "react-redux"; 6 | import { AppDispatch } from "../../app/store"; 7 | 8 | import { withStyles } from "@material-ui/core/styles"; 9 | import { 10 | Button, 11 | Grid, 12 | Avatar, 13 | Badge, 14 | CircularProgress, 15 | } from "@material-ui/core"; 16 | 17 | import { MdAddAPhoto } from "react-icons/md"; 18 | 19 | import { 20 | editNickname, 21 | selectProfile, 22 | selectIsLoadingAuth, 23 | setOpenSignIn, 24 | resetOpenSignIn, 25 | setOpenSignUp, 26 | resetOpenSignUp, 27 | setOpenProfile, 28 | resetOpenProfile, 29 | fetchAsyncGetMyProf, 30 | fetchAsyncGetProfs, 31 | } from "../auth/authSlice"; 32 | 33 | import { 34 | selectPosts, 35 | selectIsLoadingPost, 36 | setOpenNewPost, 37 | resetOpenNewPost, 38 | fetchAsyncGetPosts, 39 | fetchAsyncGetComments, 40 | } from "../post/postSlice"; 41 | 42 | import Post from "../post/Post"; 43 | import EditProfile from "./EditProfile"; 44 | import NewPost from "./NewPost"; 45 | 46 | const StyledBadge = withStyles((theme) => ({ 47 | badge: { 48 | backgroundColor: "#44b700", 49 | color: "#44b700", 50 | boxShadow: `0 0 0 2px ${theme.palette.background.paper}`, 51 | "&::after": { 52 | position: "absolute", 53 | top: 0, 54 | left: 0, 55 | width: "100%", 56 | height: "100%", 57 | borderRadius: "50%", 58 | animation: "$ripple 1.2s infinite ease-in-out", 59 | border: "1px solid currentColor", 60 | content: '""', 61 | }, 62 | }, 63 | "@keyframes ripple": { 64 | "0%": { 65 | transform: "scale(.8)", 66 | opacity: 1, 67 | }, 68 | "100%": { 69 | transform: "scale(2.4)", 70 | opacity: 0, 71 | }, 72 | }, 73 | }))(Badge); 74 | 75 | const Core: React.FC = () => { 76 | const dispatch: AppDispatch = useDispatch(); 77 | const profile = useSelector(selectProfile); 78 | const posts = useSelector(selectPosts); 79 | const isLoadingPost = useSelector(selectIsLoadingPost); 80 | const isLoadingAuth = useSelector(selectIsLoadingAuth); 81 | 82 | useEffect(() => { 83 | const fetchBootLoader = async () => { 84 | if (localStorage.localJWT) { 85 | dispatch(resetOpenSignIn()); 86 | const result = await dispatch(fetchAsyncGetMyProf()); 87 | if (fetchAsyncGetMyProf.rejected.match(result)) { 88 | dispatch(setOpenSignIn()); 89 | return null; 90 | } 91 | await dispatch(fetchAsyncGetPosts()); 92 | await dispatch(fetchAsyncGetProfs()); 93 | await dispatch(fetchAsyncGetComments()); 94 | } 95 | }; 96 | fetchBootLoader(); 97 | }, [dispatch]); 98 | 99 | return ( 100 |
101 | 102 | 103 | 104 |
105 |

SNS clone

106 | {profile?.nickName ? ( 107 | <> 108 | 117 |
118 | {(isLoadingPost || isLoadingAuth) && } 119 | 130 | 148 |
149 | 150 | ) : ( 151 |
152 | 160 | 168 |
169 | )} 170 |
171 | 172 | {profile?.nickName && ( 173 | <> 174 |
175 | 176 | {posts 177 | .slice(0) 178 | .reverse() 179 | .map((post) => ( 180 | 181 | 189 | 190 | ))} 191 | 192 |
193 | 194 | )} 195 |
196 | ); 197 | }; 198 | 199 | export default Core; 200 | -------------------------------------------------------------------------------- /src/features/auth/Auth.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { AppDispatch } from "../../app/store"; 3 | import { useSelector, useDispatch } from "react-redux"; 4 | import styles from "./Auth.module.css"; 5 | import Modal from "react-modal"; 6 | import { Formik } from "formik"; 7 | import * as Yup from "yup"; 8 | import { TextField, Button, CircularProgress } from "@material-ui/core"; 9 | 10 | import { fetchAsyncGetPosts, fetchAsyncGetComments } from "../post/postSlice"; 11 | 12 | import { 13 | selectIsLoadingAuth, 14 | selectOpenSignIn, 15 | selectOpenSignUp, 16 | setOpenSignIn, 17 | resetOpenSignIn, 18 | setOpenSignUp, 19 | resetOpenSignUp, 20 | fetchCredStart, 21 | fetchCredEnd, 22 | fetchAsyncLogin, 23 | fetchAsyncRegister, 24 | fetchAsyncGetMyProf, 25 | fetchAsyncGetProfs, 26 | fetchAsyncCreateProf, 27 | } from "./authSlice"; 28 | 29 | const customStyles = { 30 | overlay: { 31 | backgroundColor: "#777777", 32 | }, 33 | content: { 34 | top: "55%", 35 | left: "50%", 36 | 37 | width: 280, 38 | height: 350, 39 | padding: "50px", 40 | 41 | transform: "translate(-50%, -50%)", 42 | }, 43 | }; 44 | 45 | const Auth: React.FC = () => { 46 | Modal.setAppElement("#root"); 47 | const openSignIn = useSelector(selectOpenSignIn); 48 | const openSignUp = useSelector(selectOpenSignUp); 49 | const isLoadingAuth = useSelector(selectIsLoadingAuth); 50 | const dispatch: AppDispatch = useDispatch(); 51 | 52 | return ( 53 | <> 54 | { 57 | await dispatch(resetOpenSignUp()); 58 | }} 59 | style={customStyles} 60 | > 61 | { 65 | await dispatch(fetchCredStart()); 66 | const resultReg = await dispatch(fetchAsyncRegister(values)); 67 | 68 | if (fetchAsyncRegister.fulfilled.match(resultReg)) { 69 | await dispatch(fetchAsyncLogin(values)); 70 | await dispatch(fetchAsyncCreateProf({ nickName: "anonymous" })); 71 | 72 | await dispatch(fetchAsyncGetProfs()); 73 | await dispatch(fetchAsyncGetPosts()); 74 | await dispatch(fetchAsyncGetComments()); 75 | await dispatch(fetchAsyncGetMyProf()); 76 | } 77 | await dispatch(fetchCredEnd()); 78 | await dispatch(resetOpenSignUp()); 79 | }} 80 | validationSchema={Yup.object().shape({ 81 | email: Yup.string() 82 | .email("email format is wrong") 83 | .required("email is must"), 84 | password: Yup.string().required("password is must").min(4), 85 | })} 86 | > 87 | {({ 88 | handleSubmit, 89 | handleChange, 90 | handleBlur, 91 | values, 92 | errors, 93 | touched, 94 | isValid, 95 | }) => ( 96 |
97 |
98 |
99 |

SNS clone

100 |
101 |
102 | {isLoadingAuth && } 103 |
104 |
105 | 106 | 114 |
115 | {touched.email && errors.email ? ( 116 |
{errors.email}
117 | ) : null} 118 | 119 | 127 | {touched.password && errors.password ? ( 128 |
{errors.password}
129 | ) : null} 130 |
131 |
132 | 133 | 141 |
142 |
143 | { 146 | await dispatch(setOpenSignIn()); 147 | await dispatch(resetOpenSignUp()); 148 | }} 149 | > 150 | You already have a account ? 151 | 152 |
153 |
154 |
155 | )} 156 |
157 |
158 | 159 | { 162 | await dispatch(resetOpenSignIn()); 163 | }} 164 | style={customStyles} 165 | > 166 | { 170 | await dispatch(fetchCredStart()); 171 | const result = await dispatch(fetchAsyncLogin(values)); 172 | if (fetchAsyncLogin.fulfilled.match(result)) { 173 | await dispatch(fetchAsyncGetProfs()); 174 | await dispatch(fetchAsyncGetPosts()); 175 | await dispatch(fetchAsyncGetComments()); 176 | await dispatch(fetchAsyncGetMyProf()); 177 | } 178 | await dispatch(fetchCredEnd()); 179 | await dispatch(resetOpenSignIn()); 180 | }} 181 | validationSchema={Yup.object().shape({ 182 | email: Yup.string() 183 | .email("email format is wrong") 184 | .required("email is must"), 185 | password: Yup.string().required("password is must").min(4), 186 | })} 187 | > 188 | {({ 189 | handleSubmit, 190 | handleChange, 191 | handleBlur, 192 | values, 193 | errors, 194 | touched, 195 | isValid, 196 | }) => ( 197 |
198 |
199 |
200 |

SNS clone

201 |
202 |
203 | {isLoadingAuth && } 204 |
205 |
206 | 207 | 215 | 216 | {touched.email && errors.email ? ( 217 |
{errors.email}
218 | ) : null} 219 |
220 | 221 | 229 | {touched.password && errors.password ? ( 230 |
{errors.password}
231 | ) : null} 232 |
233 |
234 | 242 |
243 |
244 | { 247 | await dispatch(resetOpenSignIn()); 248 | await dispatch(setOpenSignUp()); 249 | }} 250 | > 251 | You don't have a account ? 252 | 253 |
254 |
255 |
256 | )} 257 |
258 |
259 | 260 | ); 261 | }; 262 | 263 | export default Auth; 264 | --------------------------------------------------------------------------------