-
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.
Browse files
Browse the repository at this point in the history
#38 add mate
- Loading branch information
Showing
23 changed files
with
465 additions
and
9 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
File renamed without changes.
File renamed without changes.
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 Modal from "@/components/Modal"; | ||
import AddMateSection from "@/templates/AddMateSection"; | ||
|
||
const AddMateModalPage = () => { | ||
return ( | ||
<Modal> | ||
<AddMateSection /> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default AddMateModalPage; |
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,5 @@ | ||
const Default = () => { | ||
return null; | ||
}; | ||
|
||
export default Default; |
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,11 @@ | ||
import AddMateSection from "@/templates/AddMateSection"; | ||
|
||
const AddMatePage = () => { | ||
return ( | ||
<section className="pt-[120px] flex items-center justify-center"> | ||
<AddMateSection /> | ||
</section> | ||
); | ||
}; | ||
|
||
export default AddMatePage; |
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,20 @@ | ||
import { getServerSession } from "next-auth"; | ||
import { authOptions } from "../auth/[...nextauth]/route"; | ||
|
||
export async function POST(request: Request) { | ||
const { jogakTokens } = await getServerSession(authOptions); | ||
const { userID } = await request.json(); | ||
|
||
const res = await fetch( | ||
`${process.env.SERVER_URL}/user/friend?socialID=${userID}`, | ||
{ | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${jogakTokens.accessToken}`, | ||
}, | ||
} | ||
); | ||
|
||
return res; | ||
} |
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 { getServerSession } from "next-auth"; | ||
import { authOptions } from "../auth/[...nextauth]/route"; | ||
|
||
export async function POST(request: Request) { | ||
const { jogakTokens } = await getServerSession(authOptions); | ||
|
||
const { responseType, userID } = await request.json(); | ||
|
||
const res = await fetch( | ||
`${process.env.SERVER_URL}/user/friend-reply?socialID=${userID}&reply=${responseType}`, | ||
{ | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${jogakTokens.accessToken}`, | ||
}, | ||
} | ||
); | ||
|
||
return res; | ||
} |
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,19 @@ | ||
import { getServerSession } from "next-auth"; | ||
import { authOptions } from "../auth/[...nextauth]/route"; | ||
|
||
export async function POST(request: Request) { | ||
const { jogakTokens } = await getServerSession(authOptions); | ||
|
||
const { debouncedSearchText } = await request.json(); | ||
const res = await fetch( | ||
`${process.env.SERVER_URL}/user/search?nickname=${debouncedSearchText}`, | ||
{ | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${jogakTokens.accessToken}`, | ||
}, | ||
} | ||
); | ||
|
||
return res; | ||
} |
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,145 @@ | ||
"use client"; | ||
|
||
import useMouseDownOutside from "@/hooks/useMouseDownOutside"; | ||
import usePushNotification from "@/hooks/usePushNotification"; | ||
import { useEffect, useRef, useState } from "react"; | ||
import type { FriendsType } from "@/types"; | ||
import { useSession } from "next-auth/react"; | ||
|
||
interface PushNotiPropsType { | ||
info: FriendsType | any; | ||
handleResponse: (r: string, u: string, n: string) => void; | ||
setIsAppear?: any; | ||
handleFilterPushMsg: (u: string) => void; | ||
} | ||
|
||
const PushNoti = ({ | ||
info, | ||
handleResponse, | ||
setIsAppear, | ||
handleFilterPushMsg, | ||
}: PushNotiPropsType) => { | ||
return ( | ||
<div className="p-2 border-b-2 border-white"> | ||
<p className="pb-3">{info?.nickname}님이 친구 요청을 보냈습니다.</p> | ||
<div> | ||
<button | ||
onClick={() => { | ||
handleResponse("reject", info.socialID, info.nickname); | ||
handleFilterPushMsg(info.socialID); | ||
setIsAppear(false); | ||
}} | ||
className="border-[1px] border-white px-3 py-1" | ||
> | ||
거절 | ||
</button> | ||
<button | ||
onClick={() => { | ||
handleResponse("accept", info.socialID, info.nickname); | ||
handleFilterPushMsg(info.socialID); | ||
setIsAppear(false); | ||
}} | ||
className="bg-white border-[1px] text-main_black px-3 py-1" | ||
> | ||
수락 | ||
</button> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
const Notification = () => { | ||
const notificationRef = useRef<HTMLDivElement>(null); | ||
const { isOpen, setIsOpen } = useMouseDownOutside(notificationRef); | ||
const { pushMsg, isAppear, setIsAppear } = usePushNotification(); | ||
const [receivedReq, setReceivedReq] = useState<FriendsType[]>([]); | ||
const { data: session } = useSession(); | ||
|
||
const handleResponse = async ( | ||
responseType: string, | ||
userID: string, | ||
nickname: string | ||
) => { | ||
const res = await fetch("api/replyMate", { | ||
method: "POST", | ||
body: JSON.stringify({ | ||
userID, | ||
responseType, | ||
}), | ||
}); | ||
if (res.ok) { | ||
if (responseType === "reject") alert("거절하셨습니다."); | ||
if (responseType === "accept") | ||
alert(`${nickname}님과 친구가 되었습니다.`); | ||
} | ||
}; | ||
const handleFilterPushMsg = (userID: string) => { | ||
const filteredReceivedReq = receivedReq.filter((item) => { | ||
return item.socialID !== userID; | ||
}); | ||
setReceivedReq(filteredReceivedReq); | ||
}; | ||
|
||
useEffect(() => { | ||
const getReceivedReq = async () => { | ||
const res = await fetch( | ||
`${process.env.NEXT_PUBLIC_SERVER_URL}/user/profile`, | ||
{ | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${session?.jogakTokens.accessToken}`, | ||
}, | ||
} | ||
); | ||
const data = await res.json(); | ||
setReceivedReq(data.receivedFriendRequest); | ||
}; | ||
if (session?.jogakTokens.accessToken) { | ||
getReceivedReq(); | ||
} | ||
if (pushMsg) { | ||
setReceivedReq((prev: any) => { | ||
return [...prev, pushMsg]; | ||
}); | ||
} | ||
}, [session?.jogakTokens.accessToken, pushMsg]); | ||
|
||
return ( | ||
<section ref={notificationRef} className="relative"> | ||
<div | ||
className="border-[1px] border-white p-3 cursor-pointer flex" | ||
onClick={() => setIsOpen((prev) => !prev)} | ||
> | ||
<p className="grow">알림</p> | ||
<div className="border-[1px] border-white w-[24px] text-center"> | ||
{receivedReq.length} | ||
</div> | ||
</div> | ||
{isOpen && ( | ||
<div className="absolute w-[200px] h-[400px] border-[1px] border-white bg-main_black"> | ||
{receivedReq.map((item, index) => ( | ||
<PushNoti | ||
key={index} | ||
info={item} | ||
handleResponse={handleResponse} | ||
setIsAppear={setIsAppear} | ||
handleFilterPushMsg={handleFilterPushMsg} | ||
/> | ||
))} | ||
</div> | ||
)} | ||
{isAppear && ( | ||
<div className="fixed top-[50px] left-[300px] bg-main_black z-30"> | ||
<PushNoti | ||
info={pushMsg} | ||
handleResponse={handleResponse} | ||
setIsAppear={setIsAppear} | ||
handleFilterPushMsg={handleFilterPushMsg} | ||
/> | ||
</div> | ||
)} | ||
</section> | ||
); | ||
}; | ||
|
||
export default Notification; |
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
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,17 @@ | ||
import { useState, useEffect } from "react"; | ||
|
||
const useDebounce = (value: string, delay: number) => { | ||
const [debouncedValue, setDebouncedValue] = useState<string>(value); | ||
|
||
useEffect(() => { | ||
const timer = setTimeout(() => { | ||
setDebouncedValue(value); | ||
}, delay); | ||
|
||
return () => clearTimeout(timer); | ||
}, [value, delay]); | ||
|
||
return debouncedValue; | ||
}; | ||
|
||
export default useDebounce; |
Oops, something went wrong.