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

Feat/issue-28 #134

Merged
merged 10 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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: 3 additions & 0 deletions frontend/src/assets/Bookmark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions frontend/src/assets/DefaultUser.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 2 additions & 4 deletions frontend/src/components/roomPreview/CreateRoomPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ interface CreateRoomPreviewProps {
newRoom: { roomName: string; description:string; owner:string; category: string; capacity: number; };
}

const CreateRoomPreview: React.FC<CreateRoomPreviewProps> = ({ onClose, onAddRoom, roominfo, username, handleInputChange }) => {
const CreateRoomPreview: React.FC<CreateRoomPreviewProps> = ({ onClose, roominfo, username, handleInputChange }) => {
const handleAddRoomClick = async () => {
try {
const roomWithOwner = { ...roominfo, owner: username };
const roomWithOwner = { roomName: roominfo.roomName,category:roominfo.hashtag, capacity:roominfo.capacity, description:roominfo.description, owner: username };
console.log(roomWithOwner);
await axios.post('http://localhost:8002/chatroom-service/create', roomWithOwner);

onAddRoom();
onClose();
} catch (error) {
console.error('Error creating room:', error);
Expand Down
111 changes: 95 additions & 16 deletions frontend/src/components/roomPreview/RoomPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { useQuery } from '@tanstack/react-query';
import { useEffect } from 'react';
// import { useNotification } from 'web-notification';
import axios from "axios"
import { GetAllRoomsApis } from '../../hooks/useGetAllRoom';
import { GetAllRoomsApis } from '../../hooks/react-query/useGetAllRoom';
import { useNavigate } from 'react-router-dom';

import styled from '@emotion/styled';
import BookmarkSVG from "../../assets/Bookmark.svg"
import DefaultUserSVG from "../../assets/DefaultUser.svg"

export const RoomPreview = ({roomId, roomName, description, hashtag}:{roomId:string, roomName:string, description:string, hashtag: string}) =>{

Expand All @@ -31,21 +33,98 @@ export const RoomPreview = ({roomId, roomName, description, hashtag}:{roomId:str
}

return(
<main className="ChattingRoom-wrapper" onClick={handlieRoomClick}>
<section className="ChattingRoom-container">
<RoomPreviewWrapper onClick={handlieRoomClick}>
{/* 이미지 썸네일 */}
<div className="ChattingRoom-image">
{thumbnailUrl && <img src={thumbnailUrl} alt="썸네일" />}
</div>
<PreviewImg>
{ thumbnailUrl ? <img src={thumbnailUrl} alt="썸네일" />:<img src={DefaultUserSVG} alt="DefaultUserSVG"/> }
</PreviewImg>

{/* 채팅룸 설명 */}
<div className="ChattingRoom-detail">
<span className="ChattingRoom-title">{roomName}</span><br/>
<span className="ChattingRoom-bookmark">즐겨찾기</span><br/>
<span className="ChattingRoom-info">{description}</span><br/>
<span className=" ChattingRoom-category">{hashtag}</span>
</div>
</section>
</main>
<RoomPreviewDetail>
<title>
<h1>{roomName}</h1>
<img src={BookmarkSVG} alt="BookmarkSVG"/>
</title>
<p>{description}</p>
<em>{hashtag}</em>
</RoomPreviewDetail>
</RoomPreviewWrapper>
)
}
}

const RoomPreviewWrapper = styled.main`
width: 100%;
min-width: 6.25rem;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 1rem;

cursor: pointer;
transition: 0.3s ease;

&:hover {
filter: brightness(0.9);
}
`

const RoomPreviewDetail = styled.section`
display: flex;
width: 100%;
height: 5.3125rem;
padding: 0.625rem 1.5rem;
flex-direction: column;
justify-content: center;
align-items: center;
flex-shrink: 0;
gap: 0.25rem;

box-sizing: border-box;
color: var(--color-rangoongreen);

border-radius: 0.0625rem;
border: 1px solid var(--color-mercury);
background: var(--color-white);

title{
display: flex;
align-items: center;
justify-content: center;
align-self: stretch;
}

h1 {
flex: 1 0 0;
margin: 0;
font-size: var(--font-size-sm);
font-weight: 700;
align-self: stretch;
align-self: center;
}

p {
margin: 0;
font-size: var(--font-size-xxs);
align-self: stretch;
}

em{
font-size: 0.5rem;
font-weight: 700;
align-self: stretch;
}
`

const PreviewImg = styled.div`
width: 100%;
min-width: 6.25rem;
height: 8.6875rem;
flex-shrink: 0;
border-radius: 0.3125rem;
background: var(--color-white);
display: flex;
justify-content: center;
align-items: center;
filter: drop-shadow(0px 4px 4px rgba(0, 0, 0, 0.25));
`
27 changes: 16 additions & 11 deletions frontend/src/components/roomPreview/RoomPreviewList.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { RoomPreview } from "./RoomPreview";
import styled from '@emotion/styled';
import { RoomsInfo } from '../../stores/useRoomStore';
import { useEffect } from "react";

const RoomPreviewList = () => {
const roomsInfo = RoomsInfo.getState();
console.log(roomsInfo.rooms);
const RoomPreviewList = ({ roomsPreviewListData, refetchRooms }) => {

useEffect(() => {
console.log(roomsPreviewListData);
}, [roomsPreviewListData]);

return (
<RoomPreviewListWrapper>
<RoomPreviewListSection>

{/* Grid */}
<ChattingRoomListGridContainer>
{roomsInfo.rooms.map((item, index) => (
{roomsPreviewListData?.map((item, index) => (
<RoomPreview
key={index}
roomId={item.roomId}
Expand All @@ -23,7 +25,6 @@ const RoomPreviewList = () => {
))}
</ChattingRoomListGridContainer>

</RoomPreviewListSection>
</RoomPreviewListWrapper>
)
};
Expand All @@ -32,14 +33,18 @@ export default RoomPreviewList;


const RoomPreviewListWrapper = styled.main`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 쓸모 없는거같은데?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

삭제했습니다! 감사합니다


`

const RoomPreviewListSection = styled.section`
height: 100%;
width: 100%;
`

export const ChattingRoomListGridContainer = styled.div`
const ChattingRoomListGridContainer = styled.div`
height: 100%;
width: 100%;
box-sizing: border-box;
display: grid;
align-items: start;
justify-items: start;
grid-template-columns: repeat(5, 1fr);
gap: 16px;
padding: 1.25rem;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

padding값이 오버하게 들어가서 흘러넘치는거일수도있음.
현재 height랑 width는 100% + 1.25rem; 넓이를 가지고 있기 때문에 이 부분 수정하는게 맞을꺼 같음.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

box-sizing: border-box; 했는데도 padding 이 튀어나오는게 맨 위 Container 문제였습니다.

image

image

12px 차이가 나는데 찾아보고있습니다.
export const Container = styled.divwidth: 100vw; << 여기서 스크롤이 생기는데 height: 100vh;;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추후에 더 확인해보겠습니다.

`;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios,{ AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
import { UserInfo } from '../stores/UserInfoStore';
import { UserInfo } from '../../stores/UserInfoStore';
import { useQuery } from '@tanstack/react-query';


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from 'axios';
import { RoomsInfo } from '../stores/useRoomStore';
import { RoomsInfo } from '../../stores/useRoomStore';
import { useStore } from 'zustand';

export const GetAllRoomsApis = {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/SigninPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Button } from "../components/common/Button";
import { NaverLoginButton } from "../components/auth/NaverLoginButton";
import { useStore } from "zustand";
import { UserInfoStore } from "../stores/UserInfoStore";
import { AuthApis } from "../hooks/useAuthQuery";
import { AuthApis } from "../hooks/react-query/useAuthQuery";
import styled from "@emotion/styled"
import LogoSVG from "../assets/Logo.svg"
import TadakTadakSVG from "../assets/TadakTadak.svg"
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/SignupPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useStore } from "zustand";
import { UserInfoStore } from "../stores/UserInfoStore";
import styled from '@emotion/styled';

import { AuthApis } from "../hooks/useAuthQuery";
import { AuthApis } from "../hooks/react-query/useAuthQuery";

type isValid = {
passwordIsValid: boolean;
Expand Down
64 changes: 24 additions & 40 deletions frontend/src/pages/WelcomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ import { RoomInfo, RoomsInfo } from '../stores/useRoomStore';
import { UserInfoStore } from '../stores/UserInfoStore';
import RoomPreviewList from '../components/roomPreview/RoomPreviewList';
import CreateRoomPreview from '../components/roomPreview/CreateRoomPreview';
import { GetAllRoomsApis } from '../hooks/useGetAllRoom';
import { GetAllRoomsApis } from '../hooks/react-query/useGetAllRoom';

const WelcomePage = () => {
const navigate = useNavigate();
const clientConnected = useRef(false);
const userinfo = useStore(UserInfoStore);
const roominfo = useStore(RoomInfo);
const [loginText, setLoginText] = useState('Login');
const [showToast, setShowToast] = useState(false);
const [CreateRoom, setCreateRoom] = useState(false);
const { connect, unconnect } = useLoginWebSocket();
const navigate = useNavigate();
const accessToken = localStorage.getItem('Accesstoken');
const isLoggedIn = accessToken !== null;
const clientConnected = useRef(false);
const [CreateRoom, setCreateRoom] = useState(false);
const userinfo = useStore(UserInfoStore);
const roominfo = useStore(RoomInfo);

const handleCreateRoom = () => {
setCreateRoom(true);
Expand All @@ -36,7 +36,6 @@ const WelcomePage = () => {
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const { name, value } = e.target;
roominfo.update(name, value);
console.log(roominfo);
};

const {
Expand All @@ -50,10 +49,25 @@ const WelcomePage = () => {
enabled: isLoggedIn,
});


const {
data: roomsPreviewListData,
isLoading: roomsIsLoading,
isError: roomsIsError,
refetch: refetchRooms,
} = useQuery({
queryKey: ['roomPreviewListData'],
queryFn: GetAllRoomsApis.getAllRooms,
staleTime: 3000,
enabled: isLoggedIn,
refetchInterval: 3000,
});

useEffect(() => {
if (isLoggedIn && userData) {
setLoginText('Logout');
connect(userData.username);
userinfo.updateUsername(userData.username);
} else {
setLoginText('Login');
}
Expand Down Expand Up @@ -82,37 +96,6 @@ const WelcomePage = () => {
}
};

useEffect(() => {
const fetchData = async () => {
try {
const data = await getUserData();
userinfo.updateUsername(data.username);
} catch (error) {
console.error(error);
}
};

fetchData();
}, []);

useEffect(() => {
const fetchData = async () => {
try {
const res = await GetAllRoomsApis.getAllRooms();
} catch (error) {
console.error('Error fetching rooms:', error);
}
};

fetchData();

const intervalId = setInterval(() => {
fetchData();
}, 10000);

return () => clearInterval(intervalId);
}, []);

return (
<>
{/* 전체 컴포넌트와 토스트 컴포넌트 함께 보여주기 */}
Expand Down Expand Up @@ -167,7 +150,7 @@ const WelcomePage = () => {
/>
</SideWrapper>
<MainContainer>
<RoomPreviewList />
<RoomPreviewList roomsPreviewListData={roomsPreviewListData} refetchRooms={refetchRooms}/>
{CreateRoom && (
<CreateRoomPreview
onClose={() => setCreateRoom(false)}
Expand All @@ -182,7 +165,6 @@ const WelcomePage = () => {
{showToast && <Toast messageType="logout" type="success" />}
</>
);

};

export default WelcomePage;
Expand All @@ -206,6 +188,8 @@ const LogoDiv = styled.div`
`;

const MainContainer = styled.div`
height:100%;
width: calc(100% - 11.5rem);
${FlexCenterWrapper}
`;