-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from yu-senier-project/feat/alarm
feat : 알림창 구현 + 알림 왔을 때 ui 생성
- Loading branch information
Showing
24 changed files
with
547 additions
and
42 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,12 @@ | ||
import apiClient from "../util/BaseUrl"; | ||
|
||
// 모든 알람 불러오는 api 호출 함수 (무한스크롤) | ||
export const getAllAlarms = async (cursor) => { | ||
let data; | ||
if (cursor === 0) { | ||
data = await apiClient.get(`/api/v1/notification/all`); | ||
} else { | ||
data = await apiClient.get(`/api/v1/notification/all?cursor=${cursor}`); | ||
} | ||
return data?.data; | ||
}; |
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,23 @@ | ||
import React, { useEffect, useState, useRef } from "react"; | ||
import "../../styles/alarm/alarm.scss"; | ||
import { FaRegBell } from "react-icons/fa6"; | ||
import CloseButton from "../basic/CloseButton"; | ||
import { useAlarm } from "../../hooks/useAlarm"; | ||
export const Alarm = () => { | ||
const { message, className, newAlarm, handleClose } = useAlarm(); | ||
|
||
return ( | ||
<div className={`Alarm ${className}`}> | ||
<div className="Alarm-top"> | ||
<div className="Alarm-top-left"> | ||
<FaRegBell /> | ||
<span style={{ marginLeft: "10px" }}>알림</span> | ||
</div> | ||
<div className="Alarm-top-right"> | ||
<CloseButton size={15} onCloseButton={handleClose} /> | ||
</div> | ||
</div> | ||
<div className="Alarm-text">{message}</div> | ||
</div> | ||
); | ||
}; |
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,21 @@ | ||
import React from "react"; | ||
import User from "/image/dp.jpg"; | ||
import { detailDate } from "../../util/detailDate"; | ||
|
||
export const AlarmItem = ({ text, createdAt, postId, type }) => { | ||
return ( | ||
<div className="AlarmItem"> | ||
<div className="AlarmItem-left"> | ||
{/* 이미지랑 텍스트 */} | ||
<div> | ||
<img src={User} alt="유저이미지" /> | ||
</div> | ||
<p>{text}</p> | ||
</div> | ||
<div className="AlarmItem-right"> | ||
{/* 시간 */} | ||
<p style={{ color: "lightgrey" }}>{detailDate(new Date(createdAt))}</p> | ||
</div> | ||
</div> | ||
); | ||
}; |
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,45 @@ | ||
import React, { useEffect, useRef } from "react"; | ||
import { useGetAlarmAll } from "../../react-query/useAlarm"; | ||
import { AlarmItem } from "./AlarmItem"; | ||
import { useIntersectionObserve } from "../../hooks/useIntersectionObserve"; | ||
|
||
export const AlarmList = () => { | ||
// 알람 데이터 받아오기 | ||
const { data, isLoading, hasNextPage, fetchNextPage, isFetchingNextPage } = | ||
useGetAlarmAll(); | ||
|
||
// 감시할 요소 저장할 ref | ||
const nextFetchTargetRef = useRef(null); | ||
|
||
// IntersectionObserve 커스텀 훅 가져옴 | ||
useIntersectionObserve({ | ||
ref: nextFetchTargetRef, | ||
fetchNextPage, | ||
hasNextPage, | ||
data, | ||
}); | ||
|
||
if (isLoading) return "로딩중..."; | ||
|
||
return ( | ||
<div className="AlarmList"> | ||
{data && | ||
Array.isArray(data) && | ||
data | ||
.flat() | ||
.map((item) => ( | ||
<AlarmItem | ||
id={item.notificationId} | ||
text={item.message} | ||
createdAt={item.createdAt} | ||
postId={item.subjectId} | ||
type={item.type} | ||
/> | ||
))} | ||
{isFetchingNextPage && "로딩중..."} | ||
{!isFetchingNextPage && hasNextPage && ( | ||
<div ref={nextFetchTargetRef}>더 불러오기</div> | ||
)} | ||
</div> | ||
); | ||
}; |
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
Oops, something went wrong.