Skip to content

Commit

Permalink
Merge pull request #163 from DizzyCode2024/feature/162
Browse files Browse the repository at this point in the history
[Feature/162] explore page 방 추천
  • Loading branch information
hwanheejung authored Aug 27, 2024
2 parents 21ca624 + f5edec7 commit 774d089
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 54 deletions.
3 changes: 2 additions & 1 deletion src/components/explore/ExploreMenu/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { spacing } from '@/lib/constants';
import { Text } from '@chakra-ui/react';

const ExploreMenu = () => {
Expand All @@ -9,7 +10,7 @@ const ExploreMenu = () => {
h={'4rem'}
display={'flex'}
alignItems={'center'}
pl={2}
pl={spacing.padding}
fontWeight={'bold'}
>
{'Discover'}
Expand Down
41 changes: 41 additions & 0 deletions src/components/explore/Home/SearchInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { spacing } from '@/lib/constants';
import { Button, Flex, Input } from '@chakra-ui/react';
import { useState } from 'react';
import { useSearchParams } from 'react-router-dom';

const SearchInput = () => {
const [value, setValue] = useState<string>('');

const [, setSearchParams] = useSearchParams();

const handleSubmit = () => {
setSearchParams({ keyword: value });
};

return (
<Flex
mt={spacing.gutter}
mb={spacing.offset}
mx={'10rem'}
alignItems={'center'}
gap={spacing.padding}
>
<Input
variant={'filled'}
placeholder={'Explore communities and join them!'}
height={'3rem'}
bg={'gray.700'}
fontSize={'md'}
value={value}
onChange={(e) => setValue(e.target.value)}
onSubmit={handleSubmit}
onKeyDown={(e: React.KeyboardEvent<HTMLInputElement>) =>
e.key === 'Enter' && handleSubmit()
}
/>
<Button onClick={handleSubmit}>{'Search'}</Button>
</Flex>
);
};

export default SearchInput;
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { spacing } from '@/lib/constants';
import { Box, Heading } from '@chakra-ui/react';
import { Box, Heading, Text } from '@chakra-ui/react';
import { useEffect } from 'react';
import useRoomStore from '@/lib/stores/useRoomStore';
import { useQuery, useQueryClient } from '@tanstack/react-query';
import { QUERY_KEYS, getAllRooms } from '@/lib/api';
import { IRoom } from '@/types';
import RoomBox from './RoomBox';
import SearchInput from './SearchInput';
import RoomBox from '../RoomBox';

const ExploreBody = () => {
const ExploreHome = () => {
const { setCurrentChannelPath } = useRoomStore();
useEffect(() => {
setCurrentChannelPath({
Expand All @@ -34,6 +35,15 @@ const ExploreBody = () => {

return (
<>
<Text
mt={spacing.offset}
textAlign={'center'}
color={'white'}
fontSize={'2xl'}
>
{'DizzyCode에서 커뮤니티 찾기'}
</Text>
<SearchInput />
<Heading ml={spacing.offset} size={'md'} color={'white'}>
{'추천 커뮤니티'}
</Heading>
Expand All @@ -51,12 +61,11 @@ const ExploreBody = () => {
roomId={room.roomId}
roomName={room.roomName}
open={room.open}
isMember={room.isMember}
/>
))}
</Box>
</>
);
};

export default ExploreBody;
export default ExploreHome;
40 changes: 40 additions & 0 deletions src/components/explore/Recommend/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { QUERY_KEYS, getRecommendations } from '@/lib/api';
import { spacing } from '@/lib/constants';
import { IRoom } from '@/types';
import { ChevronLeftIcon } from '@chakra-ui/icons';
import { Box, Flex } from '@chakra-ui/react';
import { useQuery } from '@tanstack/react-query';
import RoomBox from '../RoomBox';

const Recommend = ({ keyword }: { keyword: string }) => {
const { data } = useQuery<IRoom[]>({
queryKey: QUERY_KEYS.ROOM_RECOMMENDATION(keyword),
queryFn: () => getRecommendations(keyword, 5),
enabled: keyword !== '',
});

return (
<Box h={'100vh'} overflowY={'scroll'} overflowX={'hidden'}>
<ChevronLeftIcon
w={'2rem'}
h={'2rem'}
color={'white'}
ml={spacing.padding}
mt={spacing.padding}
onClick={() => window.history.back()}
/>
<Flex p={spacing.padding} direction={'column'} gap={spacing.padding}>
{data?.map((room) => (
<RoomBox
key={room.roomId}
roomId={room.roomId}
roomName={room.roomName}
open
/>
))}
</Flex>
</Box>
);
};

export default Recommend;
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@ import { QUERY_KEYS, getCategories } from '@/lib/api';
import { spacing } from '@/lib/constants';
import useEnterRoom from '@/lib/hooks/explore/useEnterRoom';
import { useCustomToast } from '@/lib/hooks/useCustomToast';
import { IRoomBox } from '@/types';
import { IRoom } from '@/types';
import { Box, Heading, Icon, Text } from '@chakra-ui/react';
import { useQuery } from '@tanstack/react-query';
import { useQuery, useQueryClient } from '@tanstack/react-query';
import { useEffect, useState } from 'react';
import { FaGlobeAmericas, FaLock } from 'react-icons/fa';
import { useNavigate } from 'react-router-dom';

const RoomBox = ({ roomId, roomName, open, isMember }: IRoomBox) => {
const RoomBox = ({ roomId, roomName, open }: IRoom) => {
const toast = useCustomToast();
const navigate = useNavigate();

// check if the user is a member of the room
const queryClient = useQueryClient();
const joinedRooms = queryClient.getQueryData<IRoom[]>(QUERY_KEYS.ROOMS) || [];

const isMember = joinedRooms.some((room) => room.roomId === roomId);

// roomId의 첫 번째 채널로 이동
const { data: roomInfo } = useQuery({
queryKey: QUERY_KEYS.CATWCHANNELS(roomId),
Expand Down
28 changes: 0 additions & 28 deletions src/components/explore/exploreHeader/ExploreSearch.tsx

This file was deleted.

21 changes: 13 additions & 8 deletions src/components/room/RoomList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@ import DMButton from './DMButton';
import ExploreButton from './ExploreButton';
import RoomButton from './RoomButton';

const Container = ({ children }: { children: React.ReactNode }) => (
<Box minWidth={'4rem'} height={'100vh'} bg={'gray.800'}>
{children}
</Box>
);

const RoomList = () => {
const queryClient = useQueryClient();
const rooms: IRoom[] =
queryClient.getQueryData<IRoom[]>(QUERY_KEYS.ROOMS) || [];

return (
<Container>
<Box
minWidth={'4rem'}
bg={'gray.800'}
overflowY={'scroll'}
height={'100vh'}
sx={{
'::-webkit-scrollbar': {
display: 'none',
},
}}
>
<Stack
display={'flex'}
justifyContent={'center'}
Expand All @@ -32,6 +36,7 @@ const RoomList = () => {
<Divider borderColor={'gray.500'} w={'3rem'} />

{/* Room */}

{rooms?.map((room) => (
<RoomButton
key={room.roomId}
Expand All @@ -47,7 +52,7 @@ const RoomList = () => {
{/* Explore Rooms */}
<ExploreButton />
</Stack>
</Container>
</Box>
);
};

Expand Down
7 changes: 7 additions & 0 deletions src/lib/api/afterLogin/exploreApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ export const getAllRooms = async (): Promise<IRoom[]> => {
const response = await axiosInstance.get('/rooms/all');
return response.data;
};

export const getRecommendations = async (value: string, k: number) => {
const response = await axiosInstance.get(
`/recommend?keyword=${value}&topN=${k}`,
);
return response.data;
};
1 change: 1 addition & 0 deletions src/lib/api/afterLogin/queryKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export const QUERY_KEYS = {
MEMBERS: (roomId: RoomId) => ['members', roomId],
DM_ROOMS: ['dmRooms'],
DM_CHATS: (currentChannelPath: IChannelPath) => ['chats', currentChannelPath],
ROOM_RECOMMENDATION: (value: string) => ['roomRecommendation', value],
};
11 changes: 7 additions & 4 deletions src/pages/ExplorePage.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import ExploreMenu from '@/components/explore/ExploreMenu';
import ExploreBody from '@/components/explore/exploreBody/ExploreBody';
import ExploreSearch from '@/components/explore/exploreHeader/ExploreSearch';
import ExploreHome from '@/components/explore/Home';
import Recommend from '@/components/explore/Recommend';
import { Box } from '@chakra-ui/react';
import { useEffect } from 'react';
import { useSearchParams } from 'react-router-dom';

const ExplorePage = ({
setMenu,
Expand All @@ -13,10 +14,12 @@ const ExplorePage = ({
setMenu(<ExploreMenu />);
}, []);

const [searchParams] = useSearchParams();
const keyword = searchParams.get('keyword');

return (
<Box flex={1} bg={'gray.600'}>
<ExploreSearch />
<ExploreBody />
{keyword ? <Recommend keyword={keyword} /> : <ExploreHome />}
</Box>
);
};
Expand Down
5 changes: 0 additions & 5 deletions src/types/explore.ts

This file was deleted.

0 comments on commit 774d089

Please sign in to comment.