Skip to content

Commit

Permalink
fix: 健康飲酒率を2以下に修正
Browse files Browse the repository at this point in the history
  • Loading branch information
nomanoma121 committed Dec 1, 2024
1 parent 88abc56 commit 7a9199e
Show file tree
Hide file tree
Showing 8 changed files with 311 additions and 139 deletions.
4 changes: 4 additions & 0 deletions client/src/Dashboard.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.left-top-container {
display: flex;
}

29 changes: 16 additions & 13 deletions client/src/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import DrinkingAmountGraph from "./components/DrinkingAmountGraph/DrinkingAmount
import ConditionAvg from "./components/ConditionAvg/ConditionAvg";
import ConditionDist from "./components/ConditionDist/ConditionDist";
import DrinkingState from "./components/DrinkingState/DrinkingState";
import LimitDrinkingAmountJudge from "./components/LimitDrinkingAmountJudge/LimitDrinkingAmountJudge";
import LimitDrinkingAmountCalc from "./components/LimitDrinkingAmountCalc/LimitDrinkingAmountCalc";
import "./Dashboard.css";

function Dashboard() {
const now = new Date();
Expand Down Expand Up @@ -68,21 +69,23 @@ function Dashboard() {
{Number(displayMonth) + 2 === 13 ? 1 : Number(displayMonth) + 2}
</div>
{Array.isArray(fetchedData) ? (
<div>
<div>
<div className="container">
<div className="drinking-data-container">
<div className="left-container">
<div className="left-top-container">
<ConditionAvg fetchedData={fetchedData} />
<DrinkingState fetchedData={fetchedData} />
</div>
<DrinkingAmountGraph
fetchedData={fetchedData}
daysInMonth={daysInMonth}
/>
</div>
<div>
<ConditionAvg fetchedData={fetchedData} />
<DrinkingState fetchedData={fetchedData} />
<ConditionDist fetchedData={fetchedData} />
</div>
<DrinkingAmountGraph
fetchedData={fetchedData}
daysInMonth={daysInMonth}
/>
</div>
<div>
<ConditionDist fetchedData={fetchedData} />
</div>
<LimitDrinkingAmountJudge />
<LimitDrinkingAmountCalc />
</div>
) : (
<p>データ取得に失敗しました。</p>
Expand Down
24 changes: 19 additions & 5 deletions client/src/components/DrinkingState/DrinkingState.css
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
l.drinking-state-container {
.drinking-state-container {
background-color: white;
border-radius: 20px;
display: flex;
justify-content: center;
align-items: center;
width: 300px;
height: 100px;
padding: 0;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
}

.drinking-count-container {
margin: 0;
background-color: green;
padding: 0;
width: 50%;
}

.healthy-drinking-rate-container {
margin: 0;
background-color: blue;
padding: 0;
width: 50%;
border-left: 2px solid gray;
}

.drinking-count-container h1 {
font-size: 15px;
font-weight: normal;
}

.drinking-count-container span {
font-size: 30px;
}

.healthy-drinking-rate-container h1 {
font-size: 15px;
font-weight: normal;
}

.healthy-drinking-rate-container span {
font-size: 30px;
}

6 changes: 3 additions & 3 deletions client/src/components/DrinkingState/DrinkingState.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function DrinkingCount({ fetchedData }) {

useEffect(() => {
const healthyDrinkingNum = fetchedData.filter(
(data) => data.condition <= 3,
(data) => data.condition <= 2,
).length;
setHealthyDrinkingRate(
((healthyDrinkingNum / fetchedData.length) * 100 || 0).toFixed(0),
Expand All @@ -27,11 +27,11 @@ function DrinkingCount({ fetchedData }) {
<div className="drinking-state-container">
<div className="drinking-count-container">
<h1>飲酒回数</h1>
<p>{drinkingCount}</p>
<p><span>{drinkingCount}</span></p>
</div>
<div className="healthy-drinking-rate-container">
<h1>健康飲酒率</h1>
<p>{healthyDrinkingRate}%</p>
<p><span>{healthyDrinkingRate}</span>%</p>
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,269 @@
import "./LimitDrinkingAmountCalc.css";
import { useState } from "react";

function LimitDrinkingAmountCalc() {
// 状態管理
const [selectedCondition, setSelectedCondition] = useState(null);
const [selectedDate, setSelectedDate] = useState("");

Check failure on line 7 in client/src/components/LimitDrinkingAmountCalc/LimitDrinkingAmountCalc.jsx

View workflow job for this annotation

GitHub Actions / lint

'selectedDate' is assigned a value but never used

Check failure on line 7 in client/src/components/LimitDrinkingAmountCalc/LimitDrinkingAmountCalc.jsx

View workflow job for this annotation

GitHub Actions / lint

'setSelectedDate' is assigned a value but never used
const [isDateValid, setIsDateValid] = useState(false);

Check failure on line 8 in client/src/components/LimitDrinkingAmountCalc/LimitDrinkingAmountCalc.jsx

View workflow job for this annotation

GitHub Actions / lint

'setIsDateValid' is assigned a value but never used
const [conditionError, setConditionError] = useState(false);

Check failure on line 9 in client/src/components/LimitDrinkingAmountCalc/LimitDrinkingAmountCalc.jsx

View workflow job for this annotation

GitHub Actions / lint

'conditionError' is assigned a value but never used

// エラーメッセージの状態を追加
const [errorMessage, setErrorMessage] = useState("");

Check failure on line 12 in client/src/components/LimitDrinkingAmountCalc/LimitDrinkingAmountCalc.jsx

View workflow job for this annotation

GitHub Actions / lint

'errorMessage' is assigned a value but never used

Check failure on line 12 in client/src/components/LimitDrinkingAmountCalc/LimitDrinkingAmountCalc.jsx

View workflow job for this annotation

GitHub Actions / lint

'setErrorMessage' is assigned a value but never used

// アルコール数量の状態を管理するstate
const [alcoholQuantities, setAlcoholQuantities] = useState({
beer350: 0,
beer500: 0,
highball350: 0,
highball500: 0,
wine: 0,
sake: 0,
shochu: 0,
whiskey: 0,
});

// 体調ボタンがクリックされたときの処理
const handleConditionClick = (value) => {

Check failure on line 27 in client/src/components/LimitDrinkingAmountCalc/LimitDrinkingAmountCalc.jsx

View workflow job for this annotation

GitHub Actions / lint

'handleConditionClick' is assigned a value but never used
setSelectedCondition(value);
setConditionError(false);
};

// アルコール量を計算する関数
const computeTotalAlcohol = () => {

Check failure on line 33 in client/src/components/LimitDrinkingAmountCalc/LimitDrinkingAmountCalc.jsx

View workflow job for this annotation

GitHub Actions / lint

'computeTotalAlcohol' is assigned a value but never used
const alcoholData = [
{ quantity: alcoholQuantities.beer350, volume: 350, percentage: 0.05 },
{ quantity: alcoholQuantities.beer500, volume: 500, percentage: 0.05 },
{
quantity: alcoholQuantities.highball350,
volume: 350,
percentage: 0.07,
},
{
quantity: alcoholQuantities.highball500,
volume: 500,
percentage: 0.07,
},
{ quantity: alcoholQuantities.wine, volume: 120, percentage: 0.12 },
{ quantity: alcoholQuantities.sake, volume: 180, percentage: 0.15 },
{ quantity: alcoholQuantities.shochu, volume: 100, percentage: 0.25 },
{ quantity: alcoholQuantities.whiskey, volume: 30, percentage: 0.4 },
];
const total = alcoholData.reduce(
(acc, { quantity, volume, percentage }) => {
return acc + quantity * volume * percentage;
},
0,
);
return total;
};

// ボタンの無効化
const isButtonDisabled = !isDateValid || selectedCondition === null;

Check failure on line 62 in client/src/components/LimitDrinkingAmountCalc/LimitDrinkingAmountCalc.jsx

View workflow job for this annotation

GitHub Actions / lint

'isButtonDisabled' is assigned a value but never used

return (
<div className="register-container">
{/* 酒の数量登録 */}
<div className="alcohol-register">
<h2>アルコール数量登録</h2>
<table className="alcohol-table">
<thead>
<tr>
<th>お酒</th>
<th>アルコール度数</th>
<th>数量</th>
</tr>
</thead>
<tbody>
<tr>
<td>
ビール・発泡酒・チューハイなど
<br />
<small>※1缶=350mlとして</small>
</td>
<td>5%</td>
<td>
<input
type="number"
min="0"
placeholder="0"
value={alcoholQuantities.beer350}
onChange={(e) =>
setAlcoholQuantities({
...alcoholQuantities,
beer350: Number(e.target.value),
})
}
/>{" "}
</td>
</tr>
<tr>
<td>
ビール・発泡酒・チューハイなど
<br />
<small>※1缶=500mlとして</small>
</td>
<td>5%</td>
<td>
<input
type="number"
min="0"
placeholder="0"
value={alcoholQuantities.beer500}
onChange={(e) =>
setAlcoholQuantities({
...alcoholQuantities,
beer500: Number(e.target.value),
})
}
/>{" "}
</td>
</tr>
<tr>
<td>
ハイボールなど
<br />
<small>※1缶=350mlとして</small>
</td>
<td>7%</td>
<td>
<input
type="number"
min="0"
placeholder="0"
value={alcoholQuantities.highball350}
onChange={(e) =>
setAlcoholQuantities({
...alcoholQuantities,
highball350: Number(e.target.value),
})
}
/>{" "}
</td>
</tr>
<tr>
<td>
ハイボールなど
<br />
<small>※1缶=500mlとして</small>
</td>
<td>7%</td>
<td>
<input
type="number"
min="0"
placeholder="0"
value={alcoholQuantities.highball500}
onChange={(e) =>
setAlcoholQuantities({
...alcoholQuantities,
highball500: Number(e.target.value),
})
}
/>{" "}
</td>
</tr>
<tr>
<td>
ワインなど
<br />
<small>※1杯=120mlとして</small>
</td>
<td>12%</td>
<td>
<input
type="number"
min="0"
placeholder="0"
value={alcoholQuantities.wine}
onChange={(e) =>
setAlcoholQuantities({
...alcoholQuantities,
wine: Number(e.target.value),
})
}
/>{" "}
</td>
</tr>
<tr>
<td>
清酒など
<br />
<small>※1合=180mlとして</small>
</td>
<td>15%</td>
<td>
<input
type="number"
min="0"
placeholder="0"
value={alcoholQuantities.sake}
onChange={(e) =>
setAlcoholQuantities({
...alcoholQuantities,
sake: Number(e.target.value),
})
}
/>{" "}
</td>
</tr>
<tr>
<td>
焼酎など
<br />
<small>※コップ1杯=100mlとして</small>
</td>
<td>25%</td>
<td>
<input
type="number"
min="0"
placeholder="0"
value={alcoholQuantities.shochu}
onChange={(e) =>
setAlcoholQuantities({
...alcoholQuantities,
shochu: Number(e.target.value),
})
}
/>{" "}
</td>
</tr>
<tr>
<td>
ウイスキー、ブランデーなど
<br />
<small>※シングル1杯=30mlとして</small>
</td>
<td>40%</td>
<td>
<input
type="number"
min="0"
placeholder="0"
value={alcoholQuantities.whiskey}
onChange={(e) =>
setAlcoholQuantities({
...alcoholQuantities,
whiskey: Number(e.target.value),
})
}
/>{" "}
</td>
</tr>
</tbody>
</table>
</div>
</div>
);
}

export default LimitDrinkingAmountCalc;
Loading

0 comments on commit 7a9199e

Please sign in to comment.