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: 유저가 설정한 목표에 맞는 시각화 #246

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 4 additions & 5 deletions components/molecules/record-mark/record-mark.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@ interface RecordMarkProps {
totalDistance?: number;
strokes?: Array<StrokeInfo>;
renderType?: 'calendar' | 'detail';
goal: number | undefined;
}

// TODO: 로그인 이후 저장된 유저의 목표 거리로 수정 필요
const goal = 1000;

export const RecordMark = ({
type,
isAchieved,
totalDistance,
strokes,
renderType = 'calendar',
goal,
}: RecordMarkProps) => {
const ref = useRef<HTMLDivElement | null>(null);
const [contentSize, setContentSize] = useState<{
Expand All @@ -36,7 +35,7 @@ export const RecordMark = ({
});

const waves: Array<{ color: string; waveHeight: number }> = [];
if (strokes) {
if (strokes && goal) {
strokes.forEach(({ name, meter }) => {
const color = getSwimColor(name);
waves.push({ color, waveHeight: meter / goal });
Expand Down Expand Up @@ -68,7 +67,7 @@ export const RecordMark = ({
/>
) : (
<div className={layoutStyles({ renderType })}>
{totalDistance && (
{totalDistance && goal && (
<Waves
width={contentSize.width}
height={contentSize.height}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useAtomValue } from 'jotai';

import { Image } from '@/components/atoms';
import { RecordMark } from '@/components/molecules/record-mark';
import { StrokeInfo } from '@/features/main';
import { StrokeInfo, useGoal } from '@/features/main';
import { calendarViewImageAtom } from '@/store';
import { css, cx } from '@/styled-system/css';
import { flex } from '@/styled-system/patterns';
Expand All @@ -25,6 +25,7 @@ export const ItemContent = ({
imageUrl,
}: ItemContentProps) => {
const isViewImage = useAtomValue(calendarViewImageAtom);
const goal = useGoal();

if (isViewImage && imageUrl)
return (
Expand All @@ -48,6 +49,7 @@ export const ItemContent = ({
totalDistance={totalDistance}
isAchieved={isAchieved}
strokes={strokes}
goal={goal}
/>
);
};
Expand Down
1 change: 1 addition & 0 deletions features/main/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './use-calendar-data';
export * from './use-calendar-rendering-data';
export * from './use-goal';
export * from './use-timeline';
11 changes: 11 additions & 0 deletions features/main/hooks/use-goal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useQueryClient } from '@tanstack/react-query';

import { MemberResponse } from '@/app/api/member/route';

export const useGoal = () => {
const queryClient = useQueryClient();
const data = queryClient.getQueryData<MemberResponse>(['currentMember']);
const goal = data?.data.goal;

return goal;
};
3 changes: 2 additions & 1 deletion features/record-detail/sections/detail-preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const DetailPreviewSection = ({ data }: { data: RecordDetailType }) => {

{/* 파도 svg */}
<div className={wavesStyle}>
{strokes?.length ? (
{strokes?.length && member?.goal ? (
<RecordMark
isAchieved={Boolean(
member?.goal && totalMeter && totalMeter > member?.goal,
Expand All @@ -71,6 +71,7 @@ export const DetailPreviewSection = ({ data }: { data: RecordDetailType }) => {
totalDistance={totalMeter}
type={type}
renderType="detail"
goal={member.goal}
/>
) : (
<Image
Expand Down
Loading