Skip to content
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

Fix/notice like 2 #110

Merged
merged 3 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
NEXT_PUBLIC_API=xxxx.poapper.com
NEXT_PUBLIC_ENV={local, dev, prod}


# only for local development
NODE_TLS_REJECT_UNAUTHORIZED=0
14 changes: 14 additions & 0 deletions certificates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,17 @@ Sudo password:
```

가이드 대로 본인의 root password를 입력하면, 루트 경로에 `certificates/`란 폴더에 `localhost-key.pem`과 `localhost.pem`이 생성되고, NextJS app을 https로 실행할 수 있다.

## NODE_TLS_REJECT_UNAUTHORIZED

ENV에 요 값을 아래와 같이 세팅해야 한다.

```
NODE_TLS_REJECT_UNAUTHORIZED=0
```

그래야 self-signed cert를 사용해도 SSR과 API 요청을 할 수 있다.

## Chrome Allow Insecure Localhost

또, 크롬에서도 insecure localhost에 대한 접속을 허용해줘야 한다. `chrome://flags/#allow-insecure-localhost` 경로로 이동해서 해당 옵션을 Enabled로 바꾸자.
6 changes: 3 additions & 3 deletions components/calendar/calendar.panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const CalendarPanel = ({ nextEvent }: { nextEvent: ICalendar }) => {
);
return (
<div style={{ marginBottom: 12 }}>
<NoticeCard>
<CalendarCard>
<div
style={{
fontWeight: 700,
Expand All @@ -26,14 +26,14 @@ const CalendarPanel = ({ nextEvent }: { nextEvent: ICalendar }) => {
{nextEvent.title}
<br />({`${moment(nextEvent.event_date).format('MM월 DD일 dddd')}`})
</div>
</NoticeCard>
</CalendarCard>
</div>
);
};

export default CalendarPanel;

const NoticeCard = styled.div`
const CalendarCard = styled.div`
background: #eeeeee;
border-radius: 0.4em;
padding: 18px;
Expand Down
30 changes: 16 additions & 14 deletions components/notice/notice.card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,24 @@ const NoticeCard: React.FC<NoticeCardProps> = ({ notice, user }) => {
const [isLike, setIsLike] = useState<boolean>(false);
const [likeCount, setLikeCount] = useState<number>(0);

const user_id = user ? user.uuid : null;
const notice_id = notice.id;

useEffect(() => {
const fetchLikeStatus = async () => {
if (!user) return;

const status = await PoPoAxios.get('/noticeLike/status', {
params: { user: user.uuid, notice: notice.id },
withCredentials: true,
});
const status = await PoPoAxios.get(
`/noticeLike/status/${user_id}/${notice_id}`,
{
withCredentials: true,
},
);
setIsLike(status.data);
};

const fetchLikeCount = async () => {
const count = await PoPoAxios.get('/noticeLike/count', {
params: { notice: notice.id },
});
const count = await PoPoAxios.get(`/noticeLike/count/${notice_id}`);
setLikeCount(count.data);
};

Expand All @@ -46,27 +49,26 @@ const NoticeCard: React.FC<NoticeCardProps> = ({ notice, user }) => {
return;
}

const data = { user_id: user.uuid, notice_id: notice.id };

if (isLike) {
await PoPoAxios.delete('/noticeLike', {
data,
await PoPoAxios.delete(`/noticeLike/${user_id}/${notice_id}`, {
withCredentials: true,
})
.then(() => setLikeCount(likeCount - 1))
.catch((err) => {
const errMsg = err.response.data.message;
alert(`공지 좋아요 취소에 실패했습니다.\n${errMsg}`);
console.log(data);
console.log(err);
});
} else {
await PoPoAxios.post('/noticeLike', data, { withCredentials: true })
await PoPoAxios.post(
'/noticeLike',
{ user_id: user_id, notice_id: notice_id },
{ withCredentials: true },
)
.then(() => setLikeCount(likeCount + 1))
.catch((err) => {
const errMsg = err.response.data.message;
alert(`공지 좋아요에 실패했습니다.\n${errMsg}`);
console.log(data);
console.log(err);
});
}
Expand Down