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

EmotionStressBefore 공통 컴포넌트화 #186

Merged
merged 1 commit into from
Nov 20, 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
38 changes: 33 additions & 5 deletions src/components/home/CoupleReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import React, { useState } from 'react';
import styled from '@emotion/styled';
import variables from '@styles/Variables';
import EChartsReact from 'echarts-for-react';
import EmotionStressBefore from '@pages/emotion/result/EmotionStressBefore';

type EmotionData = {
essential?: number;
refusing?: number;
relational?: number;
sexual?: number;
social?: number;
total?: number;
} | null;
interface CoupleResult {
my_emotion: EmotionData;
Expand Down Expand Up @@ -118,6 +120,8 @@ const CoupleReport = ({ coupleData }: CoupleReportProps) => {
],
};

console.log(coupleData?.result);

return (
<CoupleReportContainer>
<CoupleReportTitle>
Expand All @@ -138,7 +142,34 @@ const CoupleReport = ({ coupleData }: CoupleReportProps) => {
<EChartsReact option={option} />
{coupleData?.result && (
<div className="flex-box">
<EmotionGraphContainer></EmotionGraphContainer>
<EmotionGraphContainer>
{selected === 'self' && (
<>
{coupleData?.result?.my_inf_tests[0]?.total && (
<EmotionStressBefore
total={coupleData?.result?.my_inf_tests[0]?.total}
color={variables.colors.primary}
/>
)}
{coupleData?.result?.my_emotion?.total && (
<EmotionStressBefore total={coupleData?.result?.my_emotion?.total} text="예상 점수" />
)}
</>
)}
{selected === 'partner' && (
<>
{coupleData?.result?.spouse_inf_tests[0]?.total && (
<EmotionStressBefore
total={coupleData?.result?.spouse_inf_tests[0]?.total}
color={variables.colors.primary}
/>
)}
{coupleData?.result?.spouse_emotion?.total && (
<EmotionStressBefore total={coupleData?.result?.spouse_emotion?.total} text="예상 점수" />
)}
</>
)}
</EmotionGraphContainer>
</div>
)}
</ChartCover>
Expand All @@ -151,10 +182,7 @@ export default CoupleReport;

const EmotionGraphContainer = styled.div`
width: 100%;

.flex-box {
display: flex;
}
display: flex;
`;

const ToggleContainer = styled.div`
Expand Down
2 changes: 1 addition & 1 deletion src/pages/emotion/result/EmotionResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const EmotionResult = () => {

<EmotionGraphContainer>
<div className="flex-box">
<EmotionStressBefore record={prevRecord} />
<EmotionStressBefore total={prevRecord.total} />
<EmotionStress />
</div>
</EmotionGraphContainer>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/emotion/result/EmotionStress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const EmotionStress = () => {
},
axisLine: {
lineStyle: {
width: 20,
width: 12,
},
},
splitLine: {
Expand Down
38 changes: 17 additions & 21 deletions src/pages/emotion/result/EmotionStressBefore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,20 @@ import ECharts from 'echarts-for-react';
import useAnalysisStore from '@store/useAnalysisStore';
import styled from '@emotion/styled';

interface EmotionStressBeforeProps {
record: {
essential: number;
refusing: number;
relational: number;
sexual: number;
social: number;
total: number;
};
}

const EmotionStressBefore: React.FC<EmotionStressBeforeProps> = (record) => {
const EmotionStressBefore = ({
total,
color = `${variables.colors.secondaryStrong}`,
text = '기존 점수',
}: {
total: number;
color?: string;
text?: string;
}) => {
const analysisResult = useAnalysisStore((state) => state.analysis);
const value = record.record.total * 0.5;
const value = total * 0.5;

console.log(analysisResult);
console.log(record.record.total);
console.log(record);
console.log(total);

const [options] = useState({
tooltip: {
Expand All @@ -36,7 +32,7 @@ const EmotionStressBefore: React.FC<EmotionStressBeforeProps> = (record) => {
type: 'gauge',
startAngle: 90,
endAngle: -270,
color: `${variables.colors.secondaryStrong}`,
color: color,

pointer: {
show: false,
Expand All @@ -48,12 +44,12 @@ const EmotionStressBefore: React.FC<EmotionStressBeforeProps> = (record) => {
clip: false,
itemStyle: {
borderWidth: 1,
borderColor: `${variables.colors.secondaryStrong}`,
borderColor: color,
},
},
axisLine: {
lineStyle: {
width: 20,
width: 12,
},
},
splitLine: {
Expand All @@ -75,7 +71,7 @@ const EmotionStressBefore: React.FC<EmotionStressBeforeProps> = (record) => {
],
detail: {
fontSize: 22,
color: `${variables.colors.secondaryStrong}`,
color: color,
formatter: '{value}',
offsetCenter: ['0', '0%'],
},
Expand All @@ -86,11 +82,11 @@ const EmotionStressBefore: React.FC<EmotionStressBeforeProps> = (record) => {
});

return (
<StressText>
<StressText className="xxx">
<div className="stress-box">
<ECharts option={options} opts={{ width: 'auto', height: 'auto' }} />
</div>
<p className="stress-sub-text">기존 점수</p>
<p className="stress-sub-text">{text}</p>
</StressText>
);
};
Expand Down