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

[deploy] add battlegrounds #37

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
40ac618
feat : battlegrounds page routing
Minggurazi Jul 14, 2023
ca3c5af
feat : add battlegrounds page
Minggurazi Jul 19, 2023
fd58d5a
feat : card-action 수정
Minggurazi Jul 19, 2023
ac33fe2
Merge branch 'develop' into feature/issue/14
Minggurazi Jul 19, 2023
d145672
feat : 배틀그라운드 페이지 구현
Minggurazi Jul 24, 2023
d851b70
Merge branch 'develop' into feature/issue/14
Minggurazi Jul 24, 2023
0aa1021
feat : 함수 모듈화에 따른 코드 수정
Minggurazi Jul 24, 2023
6a5301b
Merge branch 'develop' into feature/issue/14
Minggurazi Jul 25, 2023
c879dd5
feat : 모듈 분리로 인한 코드 업데이트 및 방장이 사용자 직접 추가 기능 구현
Minggurazi Jul 25, 2023
4521e33
feat : 게시글 조회 요청 api 호출 수정
Minggurazi Jul 25, 2023
2dacbb3
Merge branch 'develop' into feature/issue/14
PMtHk Jul 25, 2023
996ad30
add: remove valorant from request body (signup)
PMtHk Jul 26, 2023
e1b15c1
feat: navigate after logout
PMtHk Jul 26, 2023
193d9b9
feat: add lol unranked player
PMtHk Jul 26, 2023
6279e43
feat: modify totalUser with update action
PMtHk Jul 26, 2023
f5c2c0f
fix: error - notiAccordion not closed
PMtHk Jul 26, 2023
5470787
fix: disable buttons in mypage
PMtHk Jul 26, 2023
3cfced1
feat: add getPubgPlatform
PMtHk Jul 26, 2023
1c1f57d
feat : 배틀그라운드 닉네임으로 계정 존재 여부, 플랫폼 정보 가져오기 기능 구현 및 몇몇 버그 수정
Minggurazi Jul 26, 2023
66337cf
feat: add filterbar sticky props
PMtHk Jul 26, 2023
b6d5f3e
feat: use finished prop
PMtHk Jul 26, 2023
f18071e
fix: update dummyCard width
PMtHk Jul 26, 2023
c094088
fix : 게임 플랫폼 이미지 border 형식 통일
Minggurazi Jul 26, 2023
8ace7d4
feat : 게시글 작성자의 전적에 따라 정보 표기 색상 변경
Minggurazi Jul 26, 2023
96fd941
fix : 카드의 랭크 이미지 크기 수정
Minggurazi Jul 26, 2023
9fbade9
fix : expired 관련 코드 수정 및 몇몇 버그 수정
Minggurazi Jul 27, 2023
89c47e1
feat: add review modal
PMtHk Jul 27, 2023
a59409d
fix: token payload
PMtHk Jul 27, 2023
43875f8
fix : 카드 상세보기 height 버그 수정
Minggurazi Jul 27, 2023
1a3e64f
Feature/issue/34 (#35)
PMtHk Jul 27, 2023
3fd7bd9
Merge branch 'develop' into feature/issue/14
Minggurazi Jul 27, 2023
01cea61
fix : 테스트간 발생한 몇몇 버그 수정
Minggurazi Jul 27, 2023
e1b7fcb
Add Battlegrounds Page (#36)
Minggurazi Jul 27, 2023
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
2 changes: 2 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const SetFavoriteGame = lazy(() => import('pages/register/SetFavGame'));

const MyPage = lazy(() => import('pages/mypage'));
const LeagueOfLegends = lazy(() => import('pages/leagueoflegends'));
const Battlegrounds = lazy(() => import('pages/battlegrounds'));

const App = () => {
const dispatch = useDispatch();
Expand Down Expand Up @@ -61,6 +62,7 @@ const App = () => {
<Route path="*" element={<Layout />}>
<Route path="mypage" element={<MyPage />} />
<Route path="lol/*" element={<LeagueOfLegends />} />
<Route path="pubg/*" element={<Battlegrounds />} />
<Route path="*" element={<NotFound />} />
</Route>
</Routes>
Expand Down
82 changes: 81 additions & 1 deletion src/apis/api/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { authAxios } from 'apis/utils';
import { getDatabase, push, ref, update, child, set } from 'firebase/database';
import {
getDatabase,
push,
ref,
update,
child,
set,
get,
} from 'firebase/database';

/**
* 게시글 생성
Expand Down Expand Up @@ -60,6 +68,7 @@ export const createCard = async (
nickname: userInput.name,
oauth2Id,
notiToken: notiToken || '',
isReviewed: false,
},
],
timestamp: new Date().toString(),
Expand Down Expand Up @@ -130,5 +139,76 @@ export const updateCard = async (
maxMember: updatedMaxMember,
});

await authAxios.put(`/api/chat/${currentGame}/${boardId}`, {
totalUser: updatedMaxMember,
});

return null;
};

export const finishCard = async (currentGame: string, boardId: number) => {
await authAxios.post(`/api/chat/${currentGame}/${boardId}/finish`);

return null;
};

/**
* 파티장이 직접 파티원 추가
* @param cardId 게시글id
* @param nicknameToAdd 추가하려는 사용자 닉네임
* @returns null
*/

export const addPartyMemberWithName = async (
cardId: number,
nicknameToAdd: string,
game: string,
) => {
await authAxios.post(`/api/chat/${game}/${cardId}/${nicknameToAdd}`);

return null;
};

/**
* 파티장이 파티원 강퇴
* @param cardId 게시글 id
* @param chatRoomId 채팅방 id
* @param nickname 강퇴하려는 사용자 닉네임
* @param game 해당 게임
*/
export const kickMemberFromParty = async (
cardId: number,
chatRoomId: string,
nickname: string,
game: string,
) => {
await authAxios.delete(`/api/chat/${game}/${cardId}/${nickname}/ban`);

const chatRoomsRef = ref(getDatabase(), 'chatRooms');
const messagesRef = ref(getDatabase(), 'messages');
const dataSnapshot: any = await get(child(chatRoomsRef, chatRoomId));

const prevMemberList = [...dataSnapshot.val().memberList];

const target = prevMemberList.find((member) => member.nickname === nickname);

const prevBannedList = dataSnapshot.val().bannedList
? [...dataSnapshot.val().bannedList]
: [];
const newMemberList = prevMemberList.filter(
(member) => member.nickname !== nickname,
);
const newBannedList = [...prevBannedList, target];

await update(ref(getDatabase(), `chatRooms/${chatRoomId}`), {
memberList: newMemberList,
bannedList: newBannedList,
});

await set(push(child(messagesRef, chatRoomId)), {
type: 'system',
timestamp: Date.now(),
user: { nickname, oauth2Id: '', notiToken: '' },
content: `${nickname} 님이 퇴장하였습니다.`,
});
};
69 changes: 69 additions & 0 deletions src/apis/api/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
DatabaseReference,
} from 'firebase/database';
import { notificationActions } from 'store/notification-slice';
import { useEffect, useState } from 'react';
import { promiseWrapper } from 'apis/utils/promiseWrapper';
import { RootState } from '../../store';

import { chatroomActions } from '../../store/chatroom-slice';
Expand All @@ -18,6 +20,7 @@ type Member = {
nickname: string;
oauth2Id: string;
notiToken: string;
isReviewed: boolean;
};
/** ------------------------------------------------------------
* 채팅방 차단 여부 확인
Expand Down Expand Up @@ -85,6 +88,7 @@ export const addMemberToFirebaseDB = async (
child(lastReadRef, `${newMember.oauth2Id}/${chatRoomId}`),
Date.now(),
);

await set(push(child(messagesRef, chatRoomId)), {
type: 'system',
timestamp: Date.now(),
Expand Down Expand Up @@ -248,3 +252,68 @@ export const getAllLastReads = async (

return null;
};

// 추가됨
export const getIsReviewed = (oauth2Id: string, chatRoomId: string) => {
const chatRoomsRef = ref(getDatabase(), 'chatRooms');

const [resource, setResource] = useState(null);

useEffect(() => {
const getData = async () => {
const promise = get(child(chatRoomsRef, chatRoomId)).then(
(dataSnapshot) => {
return dataSnapshot.val().memberList.find((member: Member) => {
return member.oauth2Id === oauth2Id;
}).isReviewed;
},
);

setResource(promiseWrapper(promise));
};

getData();
}, []);

return resource;
};

export const asyncGetIsReviewed = async (
oauth2Id: string,
chatRoomId: string,
) => {
const chatRoomsRef = ref(getDatabase(), 'chatRooms');

const isReviewed = await get(child(chatRoomsRef, chatRoomId)).then(
(dataSnapshot) => {
return dataSnapshot
.val()
.memberList.find((member: Member) => member.oauth2Id === oauth2Id)
.isReviewed;
},
);

return isReviewed;
};

// 추가됨
export const doReview = async (oauth2Id: string, chatRoomId: string) => {
const chatRoomsRef = ref(getDatabase(), 'chatRooms');

const dataSnapshot = await get(
child(chatRoomsRef, `${chatRoomId}/memberList`),
);

const prevMemberList = [...dataSnapshot.val()];
const newMemberList = prevMemberList.map((member: Member) => {
if (member.oauth2Id === oauth2Id) {
// eslint-disable-next-line no-param-reassign
member.isReviewed = true;
}
return member;
});

await update(ref(getDatabase(), `chatRooms/${chatRoomId}`), {
memberList: newMemberList,
});
};
65 changes: 0 additions & 65 deletions src/apis/api/leagueoflegends.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
import { useEffect, useState } from 'react';
import { authAxios, defaultAxios } from 'apis/utils';

import {
ref,
getDatabase,
child,
get,
update,
set,
push,
} from 'firebase/database';

import { promiseWrapper } from 'apis/utils/promiseWrapper';

/**
Expand Down Expand Up @@ -84,58 +74,3 @@ export const loadSummonerInfoIntoDB = async (summonerName: string) => {

return null;
};

/**
* 파티장이 소환사 명으로 파티인원 추가
* @param cardId 카드 번호
* @param nicknameToAdd 추가하려는 사용자 닉네임
* @returns null
*/

export const addPartyMemberWithSummonerName = async (
cardId: number,
nicknameToAdd: string,
) => {
await authAxios.post(`/api/chat/lol/${cardId}/${nicknameToAdd}`);

return null;
};

export const kickMemberFromParty = async (
cardId: number,
chatRoomId: string,
summonerName: string,
) => {
await authAxios.delete(`/api/chat/lol/${cardId}/${summonerName}/ban`);

const chatRoomsRef = ref(getDatabase(), 'chatRooms');
const messagesRef = ref(getDatabase(), 'messages');
const dataSnapshot: any = await get(child(chatRoomsRef, chatRoomId));

const prevMemberList = [...dataSnapshot.val().memberList];

const target = prevMemberList.find(
(member) => member.nickname === summonerName,
);
console.log(target);

const prevBannedList = dataSnapshot.val().bannedList
? [...dataSnapshot.val().bannedList]
: [];
const newMemberList = prevMemberList.filter(
(member) => member.nickname !== summonerName,
);
const newBannedList = [...prevBannedList, target];

await update(ref(getDatabase(), `chatRooms/${chatRoomId}`), {
memberList: newMemberList,
bannedList: newBannedList,
});

await set(push(child(messagesRef, chatRoomId)), {
type: 'system',
timestamp: Date.now(),
user: { nickname: summonerName, oauth2Id: '', notiToken: '' },
content: `${summonerName} 님이 퇴장하였습니다.`,
});
};
Loading
Loading