Skip to content

Commit

Permalink
[#57]Refactor:최적화
Browse files Browse the repository at this point in the history
  • Loading branch information
HyunJungJo98 committed Mar 25, 2022
1 parent 24fff95 commit e352a86
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 78 deletions.
2 changes: 1 addition & 1 deletion frontend/sweet-red-beans/.prettierrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 4,
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"bracketSameLine": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ const DMListThumbnail = ({ dm }) => {
<div
className={
currentRoom ? style.currentThumbnail : style.thumbnail
}
>
}>
<img
src={
dm.user_status === '정지' || dm.user_status === '탈퇴'
Expand All @@ -55,7 +54,7 @@ const DMListThumbnail = ({ dm }) => {
<div>{dm.recent_message}</div>
</div>
<div>
{dm.recent_message_date === null
{dm.recent_message_date === '2020-01-01T00:00:00'
? ''
: parseDate(dm.recent_message_date)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const GeneralBoard = ({ searchWords, sort }) => {
{infos.slice(offset, offset + limit).map((item, index) => (
<article key={index}>
<Link
to={`/generalBoard/${item.post_id}`}
to={`/community/general/${item.post_id}`}
style={{ textDecoration: 'none' }}>
<div>{item.title}</div>
</Link>
Expand All @@ -80,7 +80,7 @@ const GeneralBoard = ({ searchWords, sort }) => {
</div>

<div className={style.writeButtonArea}>
<Link to={`/generalBoardWrite`}>
<Link to={`/community/generalWrite`}>
<button>글쓰기</button>
</Link>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ const GeneralBoardDetailPage = () => {
</div>

<div className={style.preButton}>
<Link to={`/generalBoard`}>
<Link to={`/general`}>
<button>목록으로 돌아가기</button>
</Link>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const GeneralBoardWritePage = () => {
.then((response) => {
if (response.data.result) {
alert('게시글이 성공적으로 작성되었습니다.');
navigation('/generalBoard');
navigation('/community/general');
} else {
alert('게시글 작성을 실패했습니다.');
}
Expand All @@ -70,7 +70,7 @@ const GeneralBoardWritePage = () => {
.then((response) => {
if (response.data.result) {
alert('게시글이 성공적으로 작성되었습니다.');
navigation('/generalBoard');
navigation('/community/general');
} else {
alert('게시글 작성을 실패했습니다.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const InformationShareDetailPage = () => {

const [commentContent, setCommentContent] = useState('');

const [views, setViews] = useState(-1);

//처음 조회
useEffect(() => {
document.documentElement.scrollTop = 0;
Expand All @@ -33,11 +35,13 @@ const InformationShareDetailPage = () => {
.then((response) => {
setDetailInfo(response.data);
setComments(response.data.comment);
setViews(response.data.views);
})
.catch((error) => console.log(error));
}, []);

useEffect(() => {
console.log('댓글 추가');
setCommentsIsHere(true);
}, [comments]);

Expand Down Expand Up @@ -111,7 +115,7 @@ const InformationShareDetailPage = () => {
.then((response) => {
if (response.data.result) {
console.log('댓글 작성됨');
navigation(0);
// navigation(0);
} else {
alert('댓글 작성에 실패했습니다.');
}
Expand All @@ -122,6 +126,19 @@ const InformationShareDetailPage = () => {
}
});
}
axios
.get('http://localhost:8080/information-share/detail', {
withCredentials: true,
params: {
post_id: postid,
user_id: '1',
},
})
.then((response) => {
setDetailInfo(response.data);
setComments(response.data.comment);
})
.catch((error) => console.log(error));
};

return (
Expand All @@ -145,7 +162,8 @@ const InformationShareDetailPage = () => {
: detailInfo.nickname}
</div>
<div>{parseDate(detailInfo.written_date)}</div>
<div>{detailInfo.views}</div>

<div>{views}</div>
</div>

<div className={style.contentArea}>
Expand Down Expand Up @@ -185,7 +203,7 @@ const InformationShareDetailPage = () => {
</div>

<div className={style.preButton}>
<Link to={`/informationShare`}>
<Link to={`/community/informationShare`}>
<button>목록으로 돌아가기</button>
</Link>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ const InformationShareWritePage = () => {
.then((response) => {
if (response.data.result) {
alert('게시글이 성공적으로 작성되었습니다.');
navigation('/informationShare');
navigation('/community/informationShare');
} else {
alert('게시글 작성을 실패했습니다.');
}
Expand Down Expand Up @@ -204,7 +204,7 @@ const InformationShareWritePage = () => {
.then((response) => {
if (response.data.result) {
alert('게시글이 성공적으로 작성되었습니다.');
navigation('/informationShare');
navigation('/community/informationShare');
} else {
alert('게시글 작성을 실패했습니다.');
}
Expand Down Expand Up @@ -257,8 +257,7 @@ const InformationShareWritePage = () => {
<div className={style.filter}>
<select
onChange={cinemaNameChange}
value={cinemaName}
>
value={cinemaName}>
{cinemaNames.map((item) => (
<option value={item} key={item}>
{item}
Expand All @@ -272,8 +271,7 @@ const InformationShareWritePage = () => {
<div className={style.filter}>
<select
onChange={cinemaAreaChange}
value={cinemaArea}
>
value={cinemaArea}>
{cinemaAreas.map((item) => (
<option value={item} key={item}>
{item}
Expand All @@ -288,8 +286,7 @@ const InformationShareWritePage = () => {
<div className={style.filter}>
<select
onChange={cinemaBranchChange}
value={cinemaBranch}
>
value={cinemaBranch}>
{cinemaBranches.map((item) => (
<option value={item} key={item}>
{item}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const InformationShares = ({
{infos.slice(offset, offset + limit).map((item, index) => (
<article key={index}>
<Link
to={`/informationShare/${item.post_id}`}
to={`/community/informationShare/${item.post_id}`}
style={{ textDecoration: 'none' }}>
<div>{item.title}</div>
</Link>
Expand All @@ -147,7 +147,7 @@ const InformationShares = ({
</div>

<div className={style.writeButtonArea}>
<Link to={`/informationShareWrite`}>
<Link to={`/community/informationShareWrite`}>
<button>글쓰기</button>
</Link>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,27 @@ const MainContent = () => {
<Route path="/event/*" element={<EventPage />} />
<Route path="/event/:id" element={<EventDetailPage />} />
<Route
path="/informationShare/*"
path="/community/informationShare/*"
element={<InformationSharePage />}
/>
<Route
path="/informationShareWrite"
path="/community/informationShareWrite"
element={<InformationShareWritePage />}
/>
<Route
path="/informationShare/:postid"
path="/community/informationShare/:postid"
element={<InformationShareDetailPage />}
/>
<Route path="/generalBoard/*" element={<GeneralBoardPage />} />
<Route
path="/generalBoardWrite"
path="/community/general/*"
element={<GeneralBoardPage />}
/>
<Route
path="/community/generalWrite"
element={<GeneralBoardWritePage />}
/>
<Route
path="/generalBoard/:postid"
path="/community/general/:postid"
element={<GeneralBoardDetailPage />}
/>
<Route path="/transaction/*" element={<TransactionPage />} />
Expand Down
92 changes: 45 additions & 47 deletions frontend/sweet-red-beans/src/components/MainPage/MainPosts.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,54 @@ import { Link } from 'react-router-dom';
import { useNavigate } from 'react-router';

const MainPosts = () => {
const navigation = useNavigate();
const [dailyPosts, setDailyPosts] = useState([]);
const navigation = useNavigate();
const [dailyPosts, setDailyPosts] = useState([]);

useEffect(() => {
axios
.get('http://localhost:8080/main/daily-community', {
withCredentials: true,
params: {
community_category: '정보공유',
},
})
.then((response) => {
console.log(response.data);
setDailyPosts(response.data);
})
.catch((error) => console.log(error));
}, []);
useEffect(() => {
axios
.get('http://localhost:8080/main/daily-community', {
withCredentials: true,
params: {
community_category: '정보공유',
},
})
.then((response) => {
console.log(response.data);
setDailyPosts(response.data);
})
.catch((error) => console.log(error));
}, []);

const writeClick = () => {
navigation('/informationShare');
};
const writeClick = () => {
navigation('/informationShare');
};

return (
<>
<div className={style.posts}>
{dailyPosts.length !== 0 ? (
<ul>
{dailyPosts.map((item, index) => (
<Link
to={`/informationShare/${item.post_id}`}
style={{ textDecoration: 'none' }}
key={index}>
<li>
<div className={style.title}>
{item.title}
</div>
</li>
</Link>
))}
</ul>
) : (
<div className={style.nullMessage}>
<div>지금 당장 글 쓰러 가기</div>
<div className={style.arrow} onClick={writeClick}></div>
<div>내 통장처럼 비어버린 오늘의 글...</div>
</div>
)}
</div>
</>
);
return (
<>
<div className={style.posts}>
{dailyPosts.length !== 0 ? (
<ul>
{dailyPosts.map((item, index) => (
<Link
to={`/informationShare/${item.post_id}`}
style={{ textDecoration: 'none' }}
key={index}>
<li>
<div className={style.title}>{item.title}</div>
</li>
</Link>
))}
</ul>
) : (
<div className={style.nullMessage}>
<div>지금 당장 글 쓰러 가기</div>
<div className={style.arrow} onClick={writeClick}></div>
<div>내 통장처럼 비어버린 오늘의 글...</div>
</div>
)}
</div>
</>
);
};

export default MainPosts;
2 changes: 1 addition & 1 deletion frontend/sweet-red-beans/src/components/TopBar/LogIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const LogIn = () => {
withCredentials: true,
})
.then((response) => {
if (!response.data.status) {
if (response.data.user_status === '정지') {
alert('정지된 상태입니다. 관리자에게 문의해주세요.');
setModalOpen(false);
} else if (response.data.result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ const NavigationBar = () => {
};

const imformationShareClick = () => {
navigation('/informationShare');
navigation('/community/informationShare');
};

const generalBoardClick = () => {
navigation('/GeneralBoard');
navigation('/community/general');
};

const DMClick = () => {
Expand Down

0 comments on commit e352a86

Please sign in to comment.