├── .firebase └── hosting.YnVpbGQ.cache ├── .firebaserc ├── .gitignore ├── README.md ├── firebase.json ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt ├── src ├── App.tsx ├── components │ ├── Carousel.tsx │ ├── Comments.tsx │ ├── Footer.tsx │ ├── Header.tsx │ ├── Loader.tsx │ ├── LoginForm.tsx │ ├── PostDetail.tsx │ ├── PostForm.tsx │ ├── PostList.tsx │ ├── Profile.tsx │ ├── Router.tsx │ └── SignupForm.tsx ├── context │ ├── AuthContext.tsx │ └── ThemeContext.tsx ├── firebaseApp.ts ├── index.css ├── index.tsx ├── pages │ ├── home │ │ └── index.tsx │ ├── login │ │ └── index.tsx │ ├── posts │ │ ├── detail.tsx │ │ ├── edit.tsx │ │ ├── index.tsx │ │ └── new.tsx │ ├── profile │ │ └── index.tsx │ └── signup │ │ └── index.tsx └── react-app-env.d.ts ├── tsconfig.json └── yarn.lock /.firebase/hosting.YnVpbGQ.cache: -------------------------------------------------------------------------------- 1 | asset-manifest.json,1689260176814,e069c21667a431b1115c5ea1fb7bd6214ab4640421e757341d8eb98c592b9022 2 | index.html,1689260176814,ac8a3c33c708130faf62b2b1c6e9e2ea226531c3a61956fec66ae622b4324987 3 | manifest.json,1689260164151,341d52628782f8ac9290bbfc43298afccb47b7cbfcee146ae30cf0f46bc30900 4 | favicon.ico,1689260164150,b72f7455f00e4e58792d2bca892abb068e2213838c0316d6b7a0d6d16acd1955 5 | robots.txt,1689260164151,391d14b3c2f8c9143a27a28c7399585142228d4d1bdbe2c87ac946de411fa9a2 6 | logo512.png,1689260164151,191fc21360b4ccfb1cda11a1efb97f489ed22672ca83f4064316802bbfdd750e 7 | logo192.png,1689260164150,caff018b7f1e8fd481eb1c50d75b0ef236bcd5078b1d15c8bb348453fee30293 8 | static/js/main.71252914.js.LICENSE.txt,1689260176833,6d25ad6a84c5fd9e32fa79c34139b0dbd57f244290e1449f78c48ee970cdb7cc 9 | static/css/main.8f46c29c.css,1689260176832,b3bd6951b4ef7cf4748bddae23221fa9f6951274c8f0554971a1ba0fecb0639e 10 | static/css/main.8f46c29c.css.map,1689260176833,d26cb3f6ae443511bc0d72da21b38c51f1bb9117c272bcb01f0dbf2952551299 11 | static/js/main.71252914.js,1689260176832,baa91832b8d57d01180044efcaf8837b8274f6f8216a91c27b641cb29c014f1b 12 | static/js/main.71252914.js.map,1689260176833,a1f74f8ac9489e6633bf391a1c3457a172bd28c85fabf8c07ab152ac114f8f8c 13 | -------------------------------------------------------------------------------- /.firebaserc: -------------------------------------------------------------------------------- 1 | { 2 | "projects": { 3 | "default": "fastcampus-react-blog" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /.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 | 25 | .env -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React Blog 2 | 3 | - React, Firebase를 이용한 리액트 블로그 프로젝트 입니다. 4 | - URL: [https://fastcampus-react-blog.web.app/](https://fastcampus-react-blog.web.app/) 5 | - [Pull Request](https://github.com/jen-frontend/fastcampus-react-blog/pulls?q=is%3Apr+is%3Aclosed) 탭에서 각 기능별 코드를 확인하실 수 있습니다. 6 | 7 |
8 | 9 | # 프로젝트 설명 10 | 11 | ## 주요 기능 12 | 13 | - CRUD 기능 구현 14 | - 사용자 인증 및 권한 관리 15 | - 라우팅과 페이지 구성 16 | 17 | ## 앱 구조 18 | 19 | - (create-react-app) SPA 20 | 21 | ## 상태관리 22 | 23 | - Context API 24 | - 권한관리 25 | - 테마관리(다크모드 기능) 26 | 27 | ## 애니메이션 & 스타일링 28 | 29 | - CSS 사용 (BEM 구조) 30 | - 캐러셀 transition 31 | 32 | ## 배포 33 | 34 | - Firebase 35 | 36 | ## 컴포넌트 37 | 38 | - 헤더, 푸터, 리스트, 폼, 캐러셀 39 | 40 | ## API 41 | 42 | - firebase의 firestore를 이용한 실시간 데이터 생성 43 | - firebase auth를 이용한 사용자 인증 개념 44 | 45 | ## 사용 스택 46 | 47 | - React 48 | - Firebase(로그인, 보안, 통신) 49 | - CSS 50 | - Vercel 51 | 52 | ## 기타 학습 개념 53 | 54 | - 폴더 구조 55 | - CRA 이용 프로젝트 세팅 56 | - React hooks(useEffect, useState, useContext, useCallback) 57 | - React-router-dom 라우터 58 | 59 |
60 | 61 | # 구현 기능 62 | 63 | ## 공통 페이지 64 | 65 | 1. 로그인 페이지 66 | - Firebase Auth 사용자 인증 기본 로그인 67 | 68 | 2. 메인페이지 69 | - 최신 글 목록, 특징 콘텐츠 보여주기 70 | 71 | 3. 글 목록 페이지 72 | - 블로그에 작성된 모든 글의 목록 보여주기 73 | - 해당 글 선택시 상세페이지 이동 74 | 75 | 4. 글 상세 페이지 76 | - 글 제목, 내용, 작성자, 작성일 등 표시 77 | 78 | 5. 글 수정 페이지(CRUD) 79 | 80 | 6. 카테고리 메뉴 81 | 82 | 7. 사용자 프로필 페이지(Velog,Medium st) 83 | 84 | ## 그 외 기능 85 | 86 | 1. 다크모드 87 | 2. 내가 쓴 글 88 | 3. 댓글 CRUD 89 | -------------------------------------------------------------------------------- /firebase.json: -------------------------------------------------------------------------------- 1 | { 2 | "hosting": { 3 | "public": "build", 4 | "ignore": [ 5 | "firebase.json", 6 | "**/.*", 7 | "**/node_modules/**" 8 | ], 9 | "rewrites": [ 10 | { 11 | "source": "**", 12 | "destination": "/index.html" 13 | } 14 | ] 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fastcampus-blog-app", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.14.1", 7 | "@testing-library/react": "^13.0.0", 8 | "@testing-library/user-event": "^13.2.1", 9 | "@types/jest": "^27.0.1", 10 | "@types/node": "^16.7.13", 11 | "@types/react": "^18.0.0", 12 | "@types/react-dom": "^18.0.0", 13 | "firebase": "^10.0.0", 14 | "react": "^18.2.0", 15 | "react-dom": "^18.2.0", 16 | "react-icons": "^4.10.1", 17 | "react-router-dom": "^6.14.1", 18 | "react-scripts": "5.0.1", 19 | "react-toastify": "^9.1.3", 20 | "typescript": "^4.4.2", 21 | "web-vitals": "^2.1.0" 22 | }, 23 | "scripts": { 24 | "start": "react-scripts start", 25 | "build": "react-scripts build", 26 | "test": "react-scripts test", 27 | "eject": "react-scripts eject" 28 | }, 29 | "eslintConfig": { 30 | "extends": [ 31 | "react-app", 32 | "react-app/jest" 33 | ] 34 | }, 35 | "browserslist": { 36 | "production": [ 37 | ">0.2%", 38 | "not dead", 39 | "not op_mini all" 40 | ], 41 | "development": [ 42 | "last 1 chrome version", 43 | "last 1 firefox version", 44 | "last 1 safari version" 45 | ] 46 | }, 47 | "devDependencies": { 48 | "@types/react-icons": "^3.0.0", 49 | "@types/react-router-dom": "^5.3.3" 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jen-frontend/fastcampus-react-blog/633684cc1f322582820a3811e40cec5bdd3f41e2/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 14 | 15 | 24 | Fastcampus React Blog 25 | 26 | 27 | 28 |
29 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jen-frontend/fastcampus-react-blog/633684cc1f322582820a3811e40cec5bdd3f41e2/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jen-frontend/fastcampus-react-blog/633684cc1f322582820a3811e40cec5bdd3f41e2/public/logo512.png -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/App.tsx: -------------------------------------------------------------------------------- 1 | import { useEffect, useState, useContext } from "react"; 2 | import { app } from "firebaseApp"; 3 | import { getAuth, onAuthStateChanged } from "firebase/auth"; 4 | import { ToastContainer } from "react-toastify"; 5 | import "react-toastify/dist/ReactToastify.css"; 6 | import ThemeContext from "context/ThemeContext"; 7 | 8 | import Router from "./components/Router"; 9 | import Loader from "components/Loader"; 10 | 11 | function App() { 12 | const context = useContext(ThemeContext); 13 | const auth = getAuth(app); 14 | // auth를 체크하기 전에 (initialize 전)에는 loader를 띄워주는 용도 15 | const [init, setInit] = useState(false); 16 | // auth의 currentUser가 있으면 authenticated로 변경 17 | const [isAuthenticated, setIsAuthenticated] = useState( 18 | !!auth?.currentUser 19 | ); 20 | 21 | useEffect(() => { 22 | onAuthStateChanged(auth, (user) => { 23 | if (user) { 24 | setIsAuthenticated(true); 25 | } else { 26 | setIsAuthenticated(false); 27 | } 28 | setInit(true); 29 | }); 30 | }, [auth]); 31 | 32 | return ( 33 |
34 | 35 | {init ? : } 36 |
37 | ); 38 | } 39 | 40 | export default App; 41 | -------------------------------------------------------------------------------- /src/components/Carousel.tsx: -------------------------------------------------------------------------------- 1 | import { useState } from "react"; 2 | 3 | const IMAGE_1_URL = 4 | "https://images.unsplash.com/photo-1464822759023-fed622ff2c3b?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1470&q=80"; 5 | const IMAGE_2_URL = 6 | "https://images.unsplash.com/photo-1606117331085-5760e3b58520?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1470&q=80"; 7 | const IMAGE_3_URL = 8 | "https://images.unsplash.com/photo-1667971286579-63a5222780ff?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1074&q=80"; 9 | 10 | export default function Carousel() { 11 | const [activeImage, setActiveImage] = useState(1); 12 | 13 | return ( 14 |
15 |
16 |
    17 | 24 |
  • 25 |
    26 | scenery 1 27 |
    28 |
    29 | 35 | 41 |
    42 |
  • 43 | 50 |
  • 51 |
    52 | scenery 2 53 |
    54 |
    55 | 61 | 67 |
    68 |
  • 69 | 76 |
  • 77 |
    78 | scenery 3 79 |
    80 |
    81 | 87 | 93 |
    94 |
  • 95 |
    96 | 101 | 106 | 111 |
    112 |
113 |
114 |
115 | ); 116 | } 117 | -------------------------------------------------------------------------------- /src/components/Comments.tsx: -------------------------------------------------------------------------------- 1 | import { useContext, useState } from "react"; 2 | import { CommentsInterface, PostProps } from "./PostList"; 3 | import { doc, updateDoc, arrayUnion, arrayRemove } from "firebase/firestore"; 4 | import { db } from "firebaseApp"; 5 | import AuthContext from "context/AuthContext"; 6 | import { toast } from "react-toastify"; 7 | 8 | interface CommentsProps { 9 | post: PostProps; 10 | getPost: (id: string) => Promise; 11 | } 12 | 13 | export default function Comments({ post, getPost }: CommentsProps) { 14 | const [comment, setComment] = useState(""); 15 | const { user } = useContext(AuthContext); 16 | 17 | const onChange = (e: React.ChangeEvent) => { 18 | const { 19 | target: { name, value }, 20 | } = e; 21 | 22 | if (name === "comment") { 23 | setComment(value); 24 | } 25 | }; 26 | 27 | const onSubmit = async (e: React.FormEvent) => { 28 | e.preventDefault(); 29 | 30 | try { 31 | if (post && post?.id) { 32 | const postRef = doc(db, "posts", post.id); 33 | if (user?.uid) { 34 | const commentObj = { 35 | content: comment, 36 | uid: user.uid, 37 | email: user.email, 38 | createdAt: new Date()?.toLocaleDateString("ko", { 39 | hour: "2-digit", 40 | minute: "2-digit", 41 | second: "2-digit", 42 | }), 43 | }; 44 | 45 | await updateDoc(postRef, { 46 | comments: arrayUnion(commentObj), 47 | updateDated: new Date()?.toLocaleDateString("ko", { 48 | hour: "2-digit", 49 | minute: "2-digit", 50 | second: "2-digit", 51 | }), 52 | }); 53 | // 문서 업데이트 54 | await getPost(post.id); 55 | } 56 | } 57 | toast.success("댓글을 생성했습니다."); 58 | setComment(""); 59 | } catch (e: any) { 60 | console.log(e); 61 | toast.error(e?.code); 62 | } 63 | }; 64 | 65 | const handleDeleteComment = async (data: CommentsInterface) => { 66 | const confirm = window.confirm("해당 댓글을 삭제하시겠습니까?"); 67 | if (confirm && post.id) { 68 | const postRef = doc(db, "posts", post.id); 69 | await updateDoc(postRef, { 70 | comments: arrayRemove(data), 71 | }); 72 | 73 | toast.success("댓글을 삭제했습니다."); 74 | // 문서 업데이트 75 | await getPost(post.id); 76 | } 77 | }; 78 | 79 | return ( 80 |
81 |
82 |
83 | 84 |