Skip to content

Commit

Permalink
Merge pull request kookmin-sw#93 from capstone-maru/dev
Browse files Browse the repository at this point in the history
feat: 테스트
  • Loading branch information
he2e2 authored May 21, 2024
2 parents a97c8f3 + 85b873b commit 019acaf
Show file tree
Hide file tree
Showing 19 changed files with 240 additions and 115 deletions.
14 changes: 14 additions & 0 deletions public/House with garden.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 26 additions & 5 deletions src/app/pages/mobile/mobile-profile-page.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
'use client';

import axios from 'axios';
import Link from 'next/link';
import React, { useState, useEffect } from 'react';
import styled from 'styled-components';

import { Bookmark } from '@/components';
import { useAuthValue, useUserData } from '@/features/auth';
import {
type GetFollowingListDTO,
useCertification,
useFollowUser,
useFollowingListData,
useGetCode,
useUnfollowUser,
useUserProfile,
Expand Down Expand Up @@ -312,10 +313,30 @@ function UserInfo({
}: UserProfileInfoProps) {
const [isChecked, setIsChecked] = useState(false);

const followList = useFollowingListData();
const [isMarked, setIsMarked] = useState(
followList.data?.data.followingList[memberId] != null,
);
const [followList, setFollowList] = useState<Record<string, string[]>>();
const [isMarked, setIsMarked] = useState(false);

useEffect(() => {
if (followList?.[memberId] != null) {
setIsMarked(true);
} else setIsMarked(false);
}, [followList]);

useEffect(() => {
(async () => {
try {
const res = await axios.get<GetFollowingListDTO>(
'/maru-api/profile/follow',
);
const followListData = res.data.data.followingList;
setFollowList(followListData);
return true;
} catch (error) {
console.error(error);
return false;
}
})();
}, [setIsMarked]);

const toggleSwitch = () => {
setIsChecked(!isChecked);
Expand Down
29 changes: 8 additions & 21 deletions src/app/pages/mobile/mobile-shared-post-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import styled from 'styled-components';

import { Bookmark, CircularProfileImage } from '@/components';
import { ImageGrid } from '@/components/shared-post-page';
import { useAuthValue, useUserData } from '@/features/auth';
import { useAuthValue } from '@/features/auth';
import { useCreateChatRoom } from '@/features/chat';
import { fromAddrToCoord } from '@/features/geocoding';
import { useFollowUser, useUnfollowUser } from '@/features/profile';
Expand Down Expand Up @@ -445,15 +445,6 @@ export function MobileSharedPostPage({
enabled: type === 'dormitory' && auth?.accessToken != null,
});

const { data: userData } = useUserData(auth?.accessToken != null);
const [userId, setUserId] = useState<string>('');

useEffect(() => {
if (userData != null) {
setUserId(userData.memberId);
}
}, [userData]);

useEffect(() => {
if (sharedPost?.data.address.roadAddress != null) {
fromAddrToCoord({ query: sharedPost?.data.address.roadAddress }).then(
Expand All @@ -474,16 +465,7 @@ export function MobileSharedPostPage({
}
}, [sharedPost]);

const [roomName, setRoomName] = useState<string>('');

useEffect(() => {
if (sharedPost !== undefined) {
setRoomName(sharedPost.data.publisherAccount.nickname);
}
}, [sharedPost]);

const members = [userId];
const { mutate: chattingMutate } = useCreateChatRoom(roomName, members);
const { mutate: chattingMutate } = useCreateChatRoom();

const isLoading = useMemo(
() =>
Expand Down Expand Up @@ -574,7 +556,12 @@ export function MobileSharedPostPage({
</div>
<styles.chattingButton
onClick={() => {
chattingMutate();
if (selected == null) return;

chattingMutate({
roomName: selected.nickname,
members: [selected.memberId],
});
}}
>
채팅
Expand Down
31 changes: 26 additions & 5 deletions src/app/pages/profile-page.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
'use client';

import axios from 'axios';
import Link from 'next/link';
import React, { useState, useEffect } from 'react';
import styled from 'styled-components';

import { Bookmark } from '@/components';
import { useAuthValue, useUserData } from '@/features/auth';
import {
type GetFollowingListDTO,
useCertification,
useFollowUser,
useFollowingListData,
useGetCode,
useUnfollowUser,
useUserProfile,
Expand Down Expand Up @@ -443,10 +444,30 @@ function UserInfo({
}: UserProfileInfoProps) {
const [isChecked, setIsChecked] = useState(false);

const followList = useFollowingListData();
const [isMarked, setIsMarked] = useState(
followList.data?.data.followingList[memberId] != null,
);
const [followList, setFollowList] = useState<Record<string, string[]>>();
const [isMarked, setIsMarked] = useState(false);

useEffect(() => {
if (followList?.[memberId] != null) {
setIsMarked(true);
} else setIsMarked(false);
}, [followList]);

useEffect(() => {
(async () => {
try {
const res = await axios.get<GetFollowingListDTO>(
'/maru-api/profile/follow',
);
const followListData = res.data.data.followingList;
setFollowList(followListData);
return true;
} catch (error) {
console.error(error);
return false;
}
})();
}, [setIsMarked]);

const toggleSwitch = () => {
setIsChecked(!isChecked);
Expand Down
35 changes: 15 additions & 20 deletions src/app/pages/shared-post-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import { useRouter } from 'next/navigation';
import { useEffect, useMemo, useRef, useState } from 'react';
import { useRecoilState } from 'recoil';
import styled from 'styled-components';

import { Bookmark, CircularProfileImage } from '@/components';
import { CardToggleButton, ImageGrid } from '@/components/shared-post-page';
import { useAuthValue, useUserData } from '@/features/auth';
import { useCreateChatRoom } from '@/features/chat';
import { useAuthValue } from '@/features/auth';
import { chatOpenState, useCreateChatRoom } from '@/features/chat';
import { fromAddrToCoord } from '@/features/geocoding';
import { useFollowUser, useUnfollowUser } from '@/features/profile';
import {
Expand Down Expand Up @@ -496,15 +497,6 @@ export function SharedPostPage({
enabled: type === 'dormitory' && auth?.accessToken != null,
});

const { data: userData } = useUserData(auth?.accessToken != null);
const [userId, setUserId] = useState<string>('');

useEffect(() => {
if (userData != null) {
setUserId(userData.memberId);
}
}, [userData]);

useEffect(() => {
if (sharedPost?.data.address.roadAddress != null) {
fromAddrToCoord({ query: sharedPost?.data.address.roadAddress }).then(
Expand All @@ -525,15 +517,9 @@ export function SharedPostPage({
}
}, [sharedPost]);

const [roomName, setRoomName] = useState<string>('');
const [, setIsChatOpen] = useRecoilState(chatOpenState);

useEffect(() => {
if (sharedPost !== undefined) {
setRoomName(sharedPost.data.publisherAccount.nickname);
}
}, [sharedPost]);

const { mutate: chattingMutate } = useCreateChatRoom(roomName, [userId]);
const { mutate: chattingMutate } = useCreateChatRoom();

const isLoading = useMemo(
() =>
Expand Down Expand Up @@ -754,7 +740,16 @@ export function SharedPostPage({
<styles.buttons>
<styles.chattingButton
onClick={() => {
chattingMutate();
if (selected == null) return;

chattingMutate({
roomName: selected.nickname,
members: [selected.memberId],
});

setTimeout(() => {
setIsChatOpen(true);
}, 200);
}}
>
채팅하기
Expand Down
27 changes: 16 additions & 11 deletions src/components/FloatingChatting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { Client } from '@stomp/stompjs';
import axios from 'axios';
import { useRouter } from 'next/navigation';
import React, { useEffect, useState } from 'react';
import { useRecoilState } from 'recoil';
import styled from 'styled-components';

import { ChattingList } from './chat/ChattingList';
import { ChattingRoom } from './chat/ChattingRoom';

import { useAuthValue, useUserData } from '@/features/auth';
import { type GetChatRoomDTO } from '@/features/chat';
import { chatOpenState, type GetChatRoomDTO } from '@/features/chat';
import { useIsMobile } from '@/shared/mobile';

const styles = {
Expand Down Expand Up @@ -246,7 +247,7 @@ function FloatingChattingBox() {
}, [message, isChatRoomOpen]);

// const roomName = 'test2';
// const members = ['naver_htT4VdDRPKqGqKpnncpa71HCA4CVg5LdRC1cWZhCnF8'];
// const members = ['naver_hW_CDCYdU3NNTQWq_TV_MkpldnMZI6fOD1mnPo-V1NE'];
// const { mutate: chattingCreate } = useCreateChatRoom(roomName, members);

return (
Expand All @@ -269,12 +270,12 @@ function FloatingChattingBox() {

<styles.chattingSection>
{/* <button
onClick={() => {
chattingCreate();
}}
>
생성
</button> */}
onClick={() => {
chattingCreate();
}}
>
생성
</button> */}
{chatRooms.map((room, index) => (
<ChattingList
key={index}
Expand Down Expand Up @@ -306,7 +307,7 @@ function FloatingChattingBox() {
}

export function FloatingChatting() {
const [isChatOpen, setIsChatOpen] = useState<boolean>(false);
const [isChatOpen, setIsChatOpen] = useRecoilState(chatOpenState);
const router = useRouter();

const toggleChat = () => {
Expand All @@ -315,7 +316,6 @@ export function FloatingChatting() {

const isMobile = useIsMobile();
useEffect(() => {
if (!isMobile) router.replace('/');
if (isChatOpen && isMobile) {
router.replace('/chat');
}
Expand All @@ -324,9 +324,14 @@ export function FloatingChatting() {
}
}, [isChatOpen, isMobile]);

useEffect(() => {
if (!isMobile && window.location.pathname === '/chat') {
router.replace('/');
}
}, [isMobile]);

const auth = useAuthValue();
if (auth == null) return <></>;

return (
<>
<styles.chattingButton onClick={toggleChat}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/card/VitalSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ export function VitalSection({

setFeatures(data);
}
}, []);
}, [vitalFeatures]);

const handleEssentialFeatureChange = useCallback(
(key: 'smoking' | 'roomSharingOption' | 'mateAge', value: string) => {
Expand Down
Loading

0 comments on commit 019acaf

Please sign in to comment.