- 
                Notifications
    
You must be signed in to change notification settings  - Fork 13
 
Next 정진호 sprint8 #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            zinojung
  wants to merge
  6
  commits into
  codeit-sprint-fullstack:next-정진호
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
zinojung:next-정진호-sprint8
  
      
      
   
  
    
  
  
  
 
  
      
    base: next-정진호
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          The head ref may contain hidden characters: "next-\uC815\uC9C4\uD638-sprint8"
  
     Open
                    Next 정진호 sprint8 #57
Changes from all commits
      Commits
    
    
            Show all changes
          
          
            6 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      8fbedfe
              
                기존 작업분 이동
              
              
                zinojung 239f5ce
              
                feat: article(자유게시판)  페이지 구현
              
              
                zinojung 8bfc719
              
                .next 디렉토리 제거
              
              
                zinojung 70caa8a
              
                feat: article 페이지에 tanstack query 적용
              
              
                zinojung 5d1b46b
              
                feat: article 페이지에 검색기능 구현
              
              
                zinojung 4f247cd
              
                feat: article 수정 기능 구현
              
              
                zinojung File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
This file was deleted.
      
      Oops, something went wrong.
      
    
  This file was deleted.
      
      Oops, something went wrong.
      
    
  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
| 
     | 
||
| # dependencies | ||
| /node_modules | ||
| /.pnp | ||
| .pnp.* | ||
| .yarn/* | ||
| !.yarn/patches | ||
| !.yarn/plugins | ||
| !.yarn/releases | ||
| !.yarn/versions | ||
| 
     | 
||
| # testing | ||
| /coverage | ||
| 
     | 
||
| # next.js | ||
| /.next/ | ||
| .next/ | ||
| /out/ | ||
| 
     | 
||
| # production | ||
| /build | ||
| 
     | 
||
| # misc | ||
| .DS_Store | ||
| *.pem | ||
| 
     | 
||
| # debug | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
| .pnpm-debug.log* | ||
| 
     | 
||
| # env files (can opt-in for committing if needed) | ||
| .env* | ||
| 
     | 
||
| # vercel | ||
| .vercel | ||
| 
     | 
||
| # typescript | ||
| *.tsbuildinfo | ||
| next-env.d.ts | ||
| 
     | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import axios from "axios"; | ||
| 
     | 
||
| const baseURL = "https://four-sprint-mission-be.onrender.com"; | ||
| 
     | 
||
| const client = axios.create({ | ||
| baseURL, | ||
| }); | ||
| 
     | 
||
| const getProducts = async ({ | ||
| page = 1, | ||
| pageSize = 10, | ||
| orderBy = "recent", | ||
| keyword = "", | ||
| } = {}) => { | ||
| const url = `/products?page=${page}&pageSize=${pageSize}&orderBy=${orderBy}&keyword=${keyword}`; | ||
| const response = await client.get(url); | ||
| const data = response.data; | ||
| 
     | 
||
| return data; | ||
| }; | ||
| 
     | 
||
| const getArticles = async ({ | ||
| limit = 10, | ||
| sort = "latest", | ||
| skip = 0, | ||
| keyword = "", | ||
| } = {}) => { | ||
| const params = { limit, sort, skip, keyword }; | ||
| const url = `/articles?`; | ||
| const res = await client.get(url, { params }); | ||
| 
     | 
||
| return res.data.articles; | ||
| }; | ||
| 
     | 
||
| const getArticle = async (articleId) => { | ||
| const url = `/articles/${articleId}`; | ||
| const response = await client.get(url); | ||
| const data = response.data; | ||
| 
     | 
||
| return data; | ||
| }; | ||
| 
     | 
||
| const postArticle = async (articleData) => { | ||
| const url = `/articles`; | ||
| const response = await client.post(url, articleData); | ||
| return response.data; | ||
| }; | ||
| 
     | 
||
| // 게시글 삭제 | ||
| const deleteArticle = async (articleId) => { | ||
| const url = `/articles/${articleId}`; | ||
| const res = await client.delete(url); | ||
| return res.data; | ||
| }; | ||
| 
     | 
||
| const editArticle = async (articleId, newArticle) => { | ||
| const url = `/articles/${articleId}`; | ||
| const res = await client.patch(url, newArticle); | ||
| return res.data; | ||
| }; | ||
| 
     | 
||
| const getCommentsOfArticle = async ({ articleId, limit = 10, cursor = 0 }) => { | ||
| const url = `/articles/${articleId}/commets?limit=${limit}&cursor=${cursor}`; | ||
| const response = await client.get(url); | ||
| const data = response.data; | ||
| 
     | 
||
| return data; | ||
| }; | ||
| 
     | 
||
| const api = { | ||
| getProducts, | ||
| getArticles, | ||
| getArticle, | ||
| getCommentsOfArticle, | ||
| postArticle, | ||
| deleteArticle, | ||
| editArticle, | ||
| }; | ||
| 
     | 
||
| export default api; | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import React from "react"; | ||
| 
     | 
||
| function Footer() { | ||
| return ( | ||
| <footer className="flex justify-evenly items-center h-32 bg-blue-950 text-white"> | ||
| <p>codeit - 2025</p> | ||
| <p>Privacy Policy</p> | ||
| <p>FAQ</p> | ||
| <p>instagram</p> | ||
| </footer> | ||
| ); | ||
| } | ||
| 
     | 
||
| export default Footer; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import Link from "next/link"; | ||
| import React from "react"; | ||
| import Image from "next/image"; | ||
| import Logo from "@/assets/img/logo.png"; | ||
| import Button from "@/components/Button"; | ||
| 
     | 
||
| function Header() { | ||
| return ( | ||
| <header className="h-20 px-36 flex items-center justify-between border-b-2"> | ||
| {/* 로고 */} | ||
| <Link href="/"> | ||
| <Image alt="logo" src={Logo} className="w-[140px] h-auto" /> | ||
| </Link> | ||
| <ol className="flex flex-1 px-10 justify-start gap-x-10 font-medium"> | ||
| <Link href="/articles"> | ||
| <li>자유게시판</li> | ||
| </Link> | ||
| <Link href="/market"> | ||
| <li>중고마켓</li> | ||
| </Link> | ||
| </ol> | ||
| 
     | 
||
| {/* 로그인 버트 */} | ||
| <div> | ||
| <Button>로그인</Button> | ||
| </div> | ||
| </header> | ||
| ); | ||
| } | ||
| 
     | 
||
| export default Header; | 
        
          
          
            29 changes: 29 additions & 0 deletions
          
          29 
        
  app/(providers)/(root)/articles/[articleId]/_components/ArticleComments.jsx
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import Button from "@/components/Button"; | ||
| import React from "react"; | ||
| 
     | 
||
| function ArticleComments() { | ||
| return ( | ||
| <div> | ||
| <form className="flex flex-col gap-4"> | ||
| <label htmlFor="content" className="text-base font-semibold"> | ||
| 댓글 달기 | ||
| </label> | ||
| <textarea | ||
| id="content" | ||
| placeholder="댓글을 입력해주세요." | ||
| className="bg-gray-200 px-6 py-4 rounded-lg" | ||
| /> | ||
| <Button>등록</Button> | ||
| </form> | ||
| <div> | ||
| <p>사용 기간이 어떻게 되실까요?</p> | ||
| <Button>수정하기</Button> | ||
| <Button>삭제하기</Button> | ||
| <p>똑똑한 판다</p> | ||
| <p>1시간 전</p> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
| 
     | 
||
| export default ArticleComments; | 
        
          
          
            27 changes: 27 additions & 0 deletions
          
          27 
        
  app/(providers)/(root)/articles/[articleId]/_components/DeleteArticleButton.jsx
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| "use client"; | ||
| 
     | 
||
| import api from "@/api"; | ||
| import { useMutation, useQuery } from "@tanstack/react-query"; | ||
| import { useRouter } from "next/navigation"; | ||
| 
     | 
||
| function DeleteArticleButton({ children, articleId }) { | ||
| const router = useRouter(); | ||
| const { mutate: deleteArticle } = useMutation({ | ||
| mutationFn: () => api.deleteArticle(articleId), | ||
| onSuccess: () => { | ||
| router.replace("/articles"); | ||
| }, | ||
| }); | ||
| 
     | 
||
| const handClick = () => { | ||
| deleteArticle(); | ||
| }; | ||
| 
     | 
||
| return ( | ||
| <button className="cursor-pointer" onClick={handClick}> | ||
| {children} | ||
| </button> | ||
| ); | ||
| } | ||
| 
     | 
||
| export default DeleteArticleButton; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| "use client"; | ||
| 
     | 
||
| import api from "@/api"; | ||
| import Button from "@/components/Button"; | ||
| import Input from "@/components/Input"; | ||
| import { useMutation, useQuery } from "@tanstack/react-query"; | ||
| import { useParams, useRouter } from "next/navigation"; | ||
| import { useEffect, useState } from "react"; | ||
| 
     | 
||
| function ArticleEditPage() { | ||
| const router = useRouter(); | ||
| const params = useParams(); | ||
| const articleId = params.articleId; | ||
| const [title, setTitle] = useState(""); | ||
| const [content, setContent] = useState(""); | ||
| 
     | 
||
| const { data: article } = useQuery({ | ||
| queryFn: () => api.getArticle(articleId), | ||
| queryKey: ["articles"], | ||
| }); | ||
| 
     | 
||
| useEffect(() => { | ||
| if (article) { | ||
| setTitle(article.title || ""); | ||
| setContent(article.content || ""); | ||
| } | ||
| }, [article]); | ||
| 
     | 
||
| const { mutate: editArticle } = useMutation({ | ||
| mutationFn: (newArticle) => api.editArticle(articleId, newArticle), | ||
| onSuccess: () => { | ||
| router.push(`/articles/${articleId}`); | ||
| }, | ||
| }); | ||
| 
     | 
||
| const handleSubmit = (e) => { | ||
| e.preventDefault(); | ||
| const newArticle = { title, content }; | ||
| editArticle(newArticle); | ||
| }; | ||
| 
     | 
||
| return ( | ||
| <main className="flex flex-col gap-5 max-w-7xl m-auto my-8"> | ||
| <form onSubmit={handleSubmit}> | ||
| <div className="flex justify-between items-center mb-6"> | ||
| <h2 className="text-xl font-bold">게시글 수정</h2> | ||
| <Button>수정</Button> | ||
| </div> | ||
| <Input | ||
| type="text" | ||
| label="*제목" | ||
| name="title" | ||
| placeholder="제목을 입력해주세요." | ||
| value={title} | ||
| onChange={(e) => setTitle(e.target.value)} | ||
| /> | ||
| <Input | ||
| type="textarea" | ||
| label="*내용" | ||
| name="content" | ||
| placeholder="내용을 입력해주세요." | ||
| value={content} | ||
| onChange={(e) => setContent(e.target.value)} | ||
| /> | ||
| </form> | ||
| </main> | ||
| ); | ||
| } | ||
| 
     | 
||
| export default ArticleEditPage; | 
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이런건 그냥 간결하게 return response.data 로 빼도 될것 같아요~