-
Notifications
You must be signed in to change notification settings - Fork 2
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
โฆottom-float-button [FE][Feat] #264 : ์๋ฒ์์ ๋ฐ์์จ ๋ฐ์ดํฐ๋ฅผ ์ง๋ ๋ฐ ์บ๋ฒ์ค์ ์ฐ๋
- Loading branch information
Showing
6 changed files
with
140 additions
and
66 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,48 +1,101 @@ | ||
// import { HeaderContext } from '@/component/layout/header/LayoutHeaderProvider'; | ||
// import { useContext, useEffect, useState } from 'react'; | ||
// import { IUserChannelInfo } from '@/types/channel.types.ts'; | ||
// import { getChannelInfo } from '@/api/channel.api.ts'; | ||
// import { useLocation } from 'react-router-dom'; | ||
// import { CanvasWithMap } from '@/component/canvas/CanvasWithMap.tsx'; | ||
|
||
// export const HostView = () => { | ||
// const [userChannels, setUserChannels] = useState<IUserChannelInfo>(); | ||
// const [userNames, setUserNames] = useState<string[]>(['์ฌ์ฉ์ 1']); | ||
|
||
// const headerContext = useContext(HeaderContext); | ||
|
||
// const location = useLocation(); | ||
|
||
// const fetchChannelInfo = (id: string) => { | ||
// getChannelInfo(id) | ||
// .then(res => { | ||
// if (res.data) setUserChannels(res.data); | ||
// }) | ||
// .catch((error: any) => { | ||
// console.error(error); | ||
// }); | ||
// }; | ||
|
||
// useEffect(() => { | ||
// headerContext.setRightButton('dropdown'); | ||
// headerContext.setLeftButton('back'); | ||
// headerContext.setItems(['1']); | ||
|
||
// fetchChannelInfo(location.pathname.split('/')[2]); | ||
// }, []); | ||
|
||
// useEffect(() => { | ||
// if (userChannels?.guests) { | ||
// const names = userChannels.guests.filter(Boolean).map(guest => guest.name!); | ||
// setUserNames(names); | ||
// } | ||
// }, [userChannels]); | ||
|
||
// useEffect(() => { | ||
// headerContext.setItems(userNames); | ||
// }, [userNames]); | ||
|
||
// // TODO: geoCoding API๋ฅผ ์ด์ฉํด์ ํ์ฌ ์์น๋ ์์์์น๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์๋ ์ขํ ์ค์ ๊ตฌํ (ํ์ฌ: ํ๋์ฝ๋ฉ) | ||
// return <CanvasWithMap lat={37.3595704} lng={127.105399} zoom={21} mapType="naver" allowCanvas />; | ||
// }; | ||
export const HostView = () => <>Hello</>; | ||
import { HeaderContext } from '@/component/layout/header/LayoutHeaderProvider'; | ||
import { ReactNode, useContext, useEffect, useState } from 'react'; | ||
import { IGuest, IChannelInfo } from '@/types/channel.types.ts'; | ||
import { getChannelInfo } from '@/api/channel.api.ts'; | ||
import { useLocation } from 'react-router-dom'; | ||
import { MapCanvasForView } from '@/component/canvasWithMap/canvasWithMapForView/MapCanvasForView.tsx'; | ||
import { IGuestDataInMapProps, IPoint } from '@/lib/types/canvasInterface.ts'; | ||
import { getChannelResEntity, guestEntity } from '@/api/dto/channel.dto.ts'; | ||
|
||
export const HostView = () => { | ||
const [channelInfo, setChannelInfo] = useState<IChannelInfo>(); | ||
const [userNames, setUserNames] = useState<string[]>(['์ฌ์ฉ์ 1']); | ||
const [mapProps, setMapProps] = useState<IGuestDataInMapProps[]>([]); | ||
const [component, setComponent] = useState<ReactNode>(); | ||
|
||
const headerContext = useContext(HeaderContext); | ||
|
||
const location = useLocation(); | ||
|
||
const transformTypeGuestEntityToIGuest = (props: guestEntity): IGuest => { | ||
return { | ||
id: props.id ?? '', | ||
name: props.name ?? '', | ||
startPoint: { | ||
lat: props.start_location?.lat ?? 0, | ||
lng: props.start_location?.lng ?? 0, | ||
}, | ||
endPoint: { | ||
lat: props.end_location?.lat ?? 0, | ||
lng: props.end_location?.lng ?? 0, | ||
}, | ||
paths: (props.path as IPoint[]) ?? [], | ||
markerStyle: { | ||
color: props.marker_style?.color ?? '', | ||
}, | ||
}; | ||
}; | ||
|
||
const transformTypeFromResToInfo = (props: getChannelResEntity): IChannelInfo => { | ||
const guests = props.guests?.map(guest => transformTypeGuestEntityToIGuest(guest)) ?? []; | ||
|
||
return { | ||
name: props.name ?? '', | ||
hostId: props.host_id ?? '', | ||
channelId: props.id ?? '', | ||
guests, | ||
}; | ||
}; | ||
|
||
const fetchChannelInfo = (userId: string) => { | ||
getChannelInfo(userId) | ||
.then(res => { | ||
if (!res.data) throw new Error('๐ Fetch Error: responsed undefined'); | ||
const transfromedData = transformTypeFromResToInfo(res.data); | ||
setChannelInfo(transfromedData); | ||
}) | ||
.catch((error: any) => { | ||
console.error(error); | ||
}); | ||
}; | ||
|
||
useEffect(() => { | ||
headerContext.setRightButton('dropdown'); | ||
headerContext.setLeftButton('back'); | ||
headerContext.setItems(['1']); | ||
|
||
fetchChannelInfo(location.pathname.split('/')[2]); | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (channelInfo?.guests) { | ||
const names = channelInfo.guests.filter(Boolean).map(guest => guest.name!); | ||
setUserNames(names); | ||
channelInfo.guests?.map(guest => | ||
setMapProps(prev => [...prev, guest as IGuestDataInMapProps]), | ||
); | ||
} | ||
}, [channelInfo]); | ||
|
||
useEffect(() => { | ||
headerContext.setItems(userNames); | ||
}, [userNames]); | ||
|
||
useEffect(() => { | ||
if (mapProps.length > 1) { | ||
setComponent( | ||
<MapCanvasForView | ||
lat={37.3595704} | ||
lng={127.105399} | ||
width="100%" | ||
height="100%" | ||
guests={mapProps} | ||
/>, | ||
); | ||
} | ||
}, [mapProps]); | ||
|
||
return ( | ||
<article className="absolute h-full w-screen flex-grow overflow-hidden">{component}</article> | ||
); | ||
}; |
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 |
---|---|---|
@@ -1,22 +1,24 @@ | ||
export interface ILocation { | ||
lat: number | undefined; | ||
lng: number | undefined; | ||
export interface IPoint { | ||
lat: number; | ||
lng: number; | ||
} | ||
|
||
export interface IGuestMarkerStyle { | ||
color: string | undefined; | ||
color: string; | ||
} | ||
|
||
export interface IGuest { | ||
name: string | undefined; | ||
start_location: ILocation | undefined; | ||
end_location: ILocation | undefined; | ||
path: ILocation[] | undefined; | ||
marker_style: IGuestMarkerStyle | undefined; | ||
id: string; | ||
name: string; | ||
startPoint: IPoint; | ||
endPoint: IPoint; | ||
paths: IPoint[]; | ||
markerStyle: IGuestMarkerStyle; | ||
} | ||
|
||
export interface IUserChannelInfo { | ||
host_id: string | undefined; | ||
name: string | undefined; | ||
guests: IGuest[] | undefined; | ||
export interface IChannelInfo { | ||
channelId: string; | ||
hostId: string; | ||
name: string; | ||
guests: IGuest[]; | ||
} |