Skip to content

Commit

Permalink
Merge pull request #176 from boostcampwm-2022/develop
Browse files Browse the repository at this point in the history
v0.2
  • Loading branch information
claycat authored Dec 2, 2022
2 parents e378af2 + 163ab09 commit dabc2e3
Show file tree
Hide file tree
Showing 17 changed files with 93 additions and 23 deletions.
5 changes: 4 additions & 1 deletion client/src/components/Card/Card.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export const Summary = styled.div`
`;

export const CardTitle = styled.p`
${fontMedium(COLOR.BLACK, 700)}
${fontMedium(COLOR.BLACK, 700)};
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
`;

export const SummaryBody = styled.div`
Expand Down
9 changes: 6 additions & 3 deletions client/src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import useCardMap from "#hooks/useCardMap";
import { LatLng } from "#types/LatLng";
import { ReactNode } from "react";
import { useNavigate } from "react-router-dom";
import { CardWrapper, Summary } from "./Card.styles";

interface CardProps {
img: string;
to: string;
children: ReactNode;
path: LatLng[];
}

const Card = ({ img, to, children }: CardProps) => {
const Card = ({ to, children, path }: CardProps) => {
const navigate = useNavigate();
const { renderMap } = useCardMap({ runningPath: path });
return (
<CardWrapper onClick={() => navigate(to)}>
<img src={img} />
{renderMap()}
<Summary>{children}</Summary>
</CardWrapper>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ _CourseCard.args = {
data: {
id: 1,
title: "Dirty Ho (Lan tou He)",
img: "https://kr.object.ncloudstorage.com/j199/img/%EC%8A%A4%ED%81%AC%EB%A6%B0%EC%83%B7%202022-11-20%20%EC%98%A4%ED%9B%84%204.01.56.png",
path: [
{ lat: 126.57091836134346, lng: 33.45090000378721 },
{ lat: 126.57004847387998, lng: 33.450635526049844 },
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Card/CourseCard/CourseCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface CourseCardProps {

const CourseCard = ({ data }: CourseCardProps) => {
return (
<Card img={data.img} to={`/course/${data.id}`}>
<Card to={`/course/${data.id}`} path={data.path}>
<CardTitle>{data.title}</CardTitle>
<SummaryBody>
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ _RecruitCard.args = {
course: {
id: 1,
title: "Dirty Ho (Lan tou He)",
img: "https://kr.object.ncloudstorage.com/j199/img/%EC%8A%A4%ED%81%AC%EB%A6%B0%EC%83%B7%202022-11-20%20%EC%98%A4%ED%9B%84%204.01.56.png",
path: [
{ lat: 126.57091836134346, lng: 33.45090000378721 },
{ lat: 126.57004847387998, lng: 33.450635526049844 },
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Card/RecruitCard/RecruitCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface RecruitCardProps {

const RecruitCard = ({ data }: RecruitCardProps) => {
return (
<Card img={data.course.img} to={`/recruit/${data.id}`}>
<Card to={`/recruit/${data.id}`} path={data.course.path}>
<SummaryHead>
<CardTitle>{data.title}</CardTitle>
<PeopleWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ const Card = styled.div`
div:not(:last-child) {
margin-bottom: 30px;
}
h2 {
display: block;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
max-width: 100%;
margin-bottom: 12px;
}
`;

interface RecruitTextCardProps {
Expand All @@ -21,6 +29,7 @@ const RecruitTextCard = ({ data }: RecruitTextCardProps) => {
const navigate = useNavigate();
return (
<Card onClick={() => navigate(`/recruit/${data.id}`)}>
<h2>{data.title}</h2>
<DetailLabel title="์ถœ๋ฐœ์ " value={data.course.hDong.name || ""} />
<DetailLabel title="์ด๊ฑฐ๋ฆฌ" value={`${(data.course.pathLength / 1000).toFixed(1)}km`} />
<DetailLabel title="ํŽ˜์ด์Šค" value={getDisplayPaceString(data.pace)} />
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/DetailLabel/DetailLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const TextWrapper = styled.div`
${fontSmall(COLOR.LIGHT_GRAY, 400)};
}
p:nth-child(2) {
${fontSmall(COLOR.BLACK, 500)}
${fontSmall(COLOR.BLACK, 500)};
}
`;

Expand Down
59 changes: 59 additions & 0 deletions client/src/hooks/useCardMap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { LatLng } from "#types/LatLng";
import { MapProps } from "#types/MapProps";
import { getBounds, getMiddlePoint } from "#utils/pathUtils";
import { useCallback, useEffect, useRef, useState } from "react";

const useCardMap = ({ runningPath }: Pick<MapProps, "runningPath">) => {
const container = useRef<HTMLDivElement>(null);
const map = useRef<kakao.maps.Map>();
const polyLineRef = useRef<kakao.maps.Polyline>();
const [path] = useState<kakao.maps.LatLng[]>([]);

useEffect(() => {
if (!container.current || !runningPath) return;
const { lat, lng } = getMiddlePoint(runningPath);
map.current = new kakao.maps.Map(container.current, {
center: new kakao.maps.LatLng(lat, lng),
});

polyLineRef.current = new kakao.maps.Polyline({
map: map.current,
path,
});
map.current.setZoomable(false);
map.current.setDraggable(false);
drawPath(runningPath);
const pathBounds = getBounds(runningPath || []);
const sw = new kakao.maps.LatLng(pathBounds.minLat, pathBounds.minLng);
const ne = new kakao.maps.LatLng(pathBounds.maxLat, pathBounds.maxLng);
const mapBounds = new kakao.maps.LatLngBounds(sw, ne);
map.current.setBounds(mapBounds);
}, [runningPath, map]);

const getLaMaByLatLng = (point: LatLng): kakao.maps.LatLng => {
return new kakao.maps.LatLng(point.lat, point.lng);
};

const drawPath = useCallback(
async (path: LatLng[] | undefined) => {
if (!path) {
return;
}
if (!polyLineRef.current) return;
polyLineRef.current.setPath(path.map((point) => getLaMaByLatLng(point)));
},
[polyLineRef],
);

return {
map: map.current,
path,
renderMap: () => (
<div style={{ position: "relative" }}>
<div ref={container} style={{ width: "100%", aspectRatio: `16 / 9` }} />
</div>
),
};
};

export default useCardMap;
4 changes: 2 additions & 2 deletions client/src/pages/Courses/Courses.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ const Courses = () => {

const courseQueryParams = () => {
const param: any = {};
if (titleFilter) param.title = "true";
if (authorFilter) param.author = "true";
param.title = titleFilter ? "true" : "false";
param.author = authorFilter ? "true" : "false";
if (searchContent !== "") param.query = searchContent;
param.maxLen = (currentDistanceFilter.max * 1000).toString();
param.minLen = (currentDistanceFilter.min * 1000).toString();
Expand Down
4 changes: 1 addition & 3 deletions client/src/pages/MockRecruits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,11 @@ const MockRecruits = () => {
pace: randomPace,
userId: userInfo.userIdx,
};
console.log(randomRecruit);
return randomRecruit;
};

const sendAxiosRequest = async (recruit: any) => {
const response = await post("/recruit", await recruit);
console.log(response);
await post("/recruit", await recruit);
};
const handleSubmit = async () => {
for (let i = 0; i < reps; i++) {
Expand Down
1 change: 0 additions & 1 deletion client/src/pages/NewCourse/NewCourse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const NewCourse = () => {
const checkFormValidation = () => {
if (title && path.length) {
handleToggleConfirmModal();
console.log(title);
}
};

Expand Down
6 changes: 3 additions & 3 deletions client/src/pages/Recruits/Recruits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ const Recruits = () => {

const recruitQueryParams = () => {
const param: any = {};
if (titleFilter) param.title = "true";
if (authorFilter) param.author = "true";
if (availFilter) param.avail = "true";
param.title = titleFilter ? "true" : "false";
param.author = authorFilter ? "true" : "false";
param.avail = availFilter ? "true" : "false";
if (searchContent !== "") param.query = searchContent;
param.maxLen = (currentDistanceFilter.max * 1000).toString();
param.minLen = (currentDistanceFilter.min * 1000).toString();
Expand Down
1 change: 0 additions & 1 deletion client/src/types/Course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { LatLng } from "./LatLng";
export interface Course {
id: number;
title: string;
img: string;
path: LatLng[];
pathLength: number;
hDong: hDong;
Expand Down
6 changes: 4 additions & 2 deletions client/src/utils/pathUtils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
export const getMiddlePoint = (path: { lat: number; lng: number }[]) => {
import { LatLng } from "#types/LatLng";

export const getMiddlePoint = (path: LatLng[]) => {
const bounds = getBounds(path);
return { lat: (bounds.minLat + bounds.maxLat) / 2, lng: (bounds.minLng + bounds.maxLng) / 2 };
};

export const getBounds = (path: { lat: number; lng: number }[]) => {
export const getBounds = (path: LatLng[]) => {
let minLat = 90;
let maxLat = -90;
let minLng = 180;
Expand Down
2 changes: 1 addition & 1 deletion server/src/course/course.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class CourseService {
return [];
}

if (!queryParams.getTitle() && !queryParams.getAuthor()) {
if (!queryParams.getTitle() && !queryParams.getAuthor() && queryParams.getQuery()) {
return [];
}

Expand Down
2 changes: 1 addition & 1 deletion server/src/recruit/recruit.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class RecruitService {
return [];
}

if (!queryParams.getTitle() && !queryParams.getAuthor()) {
if (!queryParams.getTitle() && !queryParams.getAuthor() && queryParams.getQuery()) {
return [];
}

Expand Down

0 comments on commit dabc2e3

Please sign in to comment.