-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/user/#2
- Loading branch information
Showing
8 changed files
with
1,589 additions
and
35 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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,24 @@ | ||
import axios from 'axios'; | ||
|
||
export async function fetchPersonInfo(personId) { | ||
const response = await axios.get(`/api/info/person/${personId}`); | ||
const data = await response.data; | ||
|
||
return data; | ||
} | ||
|
||
export async function fetchSingleInfo(infoId) { | ||
const response = await axios.get(`/api/info/${infoId}`); | ||
const data = await response.data; | ||
|
||
return data; | ||
} | ||
|
||
export async function updateInfo(infoId, info) { | ||
try { | ||
const response = await axios.put(`/api/info/${infoId}`, info); | ||
console.log(response.data); | ||
} catch { | ||
|
||
} | ||
} |
This file contains 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
This file contains 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,35 @@ | ||
import React from "react"; | ||
import ReactMarkdown from "react-markdown"; | ||
import remarkGfm from 'remark-gfm' | ||
import styled from 'styled-components'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
const InfoHeader = styled.div` | ||
display: flex; | ||
justify-content: space-between; | ||
`; | ||
|
||
const MyBtn = styled.button` | ||
border: none; | ||
background-color: white; | ||
`; | ||
|
||
export default function Info({ data }) { | ||
|
||
const navigate = useNavigate(); | ||
|
||
|
||
|
||
return ( | ||
<> | ||
<InfoHeader> | ||
<h2>{data.category}</h2> | ||
<MyBtn onClick={() => navigate(`/info/update/${data.id}`)}> [ 수정 ] </MyBtn> | ||
</InfoHeader> | ||
<hr /> | ||
<ReactMarkdown remarkPlugins={[remarkGfm]}> | ||
{data.content} | ||
</ReactMarkdown> | ||
</> | ||
) | ||
} |
This file contains 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,133 @@ | ||
import React, { useRef, useEffect, useState } from 'react'; | ||
import styled from 'styled-components'; | ||
import Headers from '../components/Headers'; | ||
import { useParams, useNavigate } from "react-router-dom"; | ||
import { fetchSingleInfo, updateInfo } from '../api/FetchInfo'; | ||
import ReactMarkdown from "react-markdown"; | ||
import remarkGfm from 'remark-gfm' | ||
|
||
const MainPageWrapper = styled.div` | ||
width: 100%; | ||
background: #cecece; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
font-family: 'bmdohyeon'; | ||
font-size: 2.5vmin; | ||
overflow-x:auto; | ||
@media screen and (max-width: 768px) { | ||
font-size: 4vmin; | ||
} | ||
`; | ||
|
||
const UpdateContainer = styled.div` | ||
background: white ; | ||
padding: 10px; | ||
margin: 0 auto; | ||
width: 100%; | ||
&::-webkit-scrollbar { | ||
display: none; | ||
} | ||
`; | ||
|
||
const Container = styled.div` | ||
position: relative; | ||
background: blue; | ||
padding: 10px; | ||
display: flex; | ||
flex-direction: row; | ||
justify-content:space-between; | ||
width:60vw; | ||
margin-top:30px; | ||
@media screen and (max-width: 768px) { | ||
flex-direction:column; | ||
} | ||
`; | ||
|
||
const UpdateHeader = styled.div` | ||
display: flex; | ||
justify-content: space-between; | ||
`; | ||
|
||
const RanderingBtn = styled.button` | ||
border: none; | ||
background-color: white; | ||
font-weight: bold; | ||
font-size: 1em; | ||
`; | ||
|
||
const UpdateForm = styled.form` | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
`; | ||
|
||
const UpdateTextArea = styled.textarea` | ||
width: 90%; | ||
border: 1; | ||
overflow: visible; | ||
text-overflow: ellipsis; | ||
resize: none; | ||
background-color: rgb(245, 245, 245); | ||
border: 1px solid rgb(235, 235, 235); | ||
padding: 7px; | ||
font-family: 'Noto Sans KR', sans-serif; | ||
`; | ||
|
||
const UpdateBtn = styled.button` | ||
width: 40%; | ||
margin-top: 10px; | ||
`; | ||
|
||
function UpdateInfo() { | ||
const params = useParams(); | ||
const [info, setInfo] = useState({ category: "", content: "" }); | ||
const [markdwon, setMarkdwon] = useState(""); | ||
const textarea = useRef(); | ||
const navigate = useNavigate(); | ||
|
||
const UpdateInfoHandler = (e) => { | ||
e.preventDefault(); | ||
updateInfo(params.infoId, { | ||
content: textarea.current.value | ||
}); | ||
|
||
navigate('/'); | ||
} | ||
|
||
useEffect(() => { | ||
const data = fetchSingleInfo(params.infoId); | ||
data.then((result) => setInfo(result)); | ||
}, []); | ||
|
||
return ( | ||
<div> | ||
<Headers /> | ||
<MainPageWrapper> | ||
<Container> | ||
<UpdateContainer> | ||
<UpdateHeader> | ||
<h2> | ||
{info.category} | ||
</h2> | ||
<RanderingBtn onClick={() => setMarkdwon(textarea.current.value)}> [ 랜더링 ] </RanderingBtn> | ||
</UpdateHeader> | ||
<UpdateForm onSubmit={UpdateInfoHandler}> | ||
<UpdateTextArea ref={textarea} cols={135} rows={25} defaultValue={info.content}></UpdateTextArea> | ||
<UpdateBtn type='submit'>수정</UpdateBtn> | ||
</UpdateForm> | ||
|
||
<hr /> | ||
<ReactMarkdown remarkPlugins={[remarkGfm]}> | ||
{markdwon} | ||
</ReactMarkdown> | ||
</UpdateContainer> | ||
</Container> | ||
</MainPageWrapper> | ||
</div> | ||
); | ||
} | ||
|
||
export default UpdateInfo; |
File renamed without changes.