4.27.3: Фикс undefined в статистике Fitbit
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m7s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m7s
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "play-life-web",
|
"name": "play-life-web",
|
||||||
"version": "4.27.2",
|
"version": "4.27.3",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
@@ -100,18 +100,34 @@ function FitbitIntegration({ onNavigate }) {
|
|||||||
throw new Error('Ошибка при загрузке статистики')
|
throw new Error('Ошибка при загрузке статистики')
|
||||||
}
|
}
|
||||||
const data = await response.json()
|
const data = await response.json()
|
||||||
setStats(data)
|
// Нормализуем данные, чтобы избежать undefined
|
||||||
|
const defaultGoal = { min: 0, max: 0 }
|
||||||
|
const normalizedStats = {
|
||||||
|
steps: {
|
||||||
|
value: data.steps?.value ?? 0,
|
||||||
|
goal: data.steps?.goal ?? defaultGoal
|
||||||
|
},
|
||||||
|
floors: {
|
||||||
|
value: data.floors?.value ?? 0,
|
||||||
|
goal: data.floors?.goal ?? defaultGoal
|
||||||
|
},
|
||||||
|
azm: {
|
||||||
|
value: data.azm?.value ?? 0,
|
||||||
|
goal: data.azm?.goal ?? defaultGoal
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setStats(normalizedStats)
|
||||||
// Обновляем цели из ответа
|
// Обновляем цели из ответа
|
||||||
if (data.steps?.goal) {
|
if (data.steps?.goal) {
|
||||||
setGoals({
|
setGoals({
|
||||||
steps: data.steps.goal,
|
steps: data.steps.goal,
|
||||||
floors: data.floors.goal,
|
floors: data.floors?.goal ?? defaultGoal,
|
||||||
azm: data.azm.goal
|
azm: data.azm?.goal ?? defaultGoal
|
||||||
})
|
})
|
||||||
setEditedGoals({
|
setEditedGoals({
|
||||||
steps: data.steps.goal,
|
steps: data.steps.goal,
|
||||||
floors: data.floors.goal,
|
floors: data.floors?.goal ?? defaultGoal,
|
||||||
azm: data.azm.goal
|
azm: data.azm?.goal ?? defaultGoal
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -293,14 +309,14 @@ function FitbitIntegration({ onNavigate }) {
|
|||||||
<div className="mb-6">
|
<div className="mb-6">
|
||||||
<div className="flex justify-between items-center mb-2">
|
<div className="flex justify-between items-center mb-2">
|
||||||
<span className="text-gray-700 font-medium">Шаги</span>
|
<span className="text-gray-700 font-medium">Шаги</span>
|
||||||
<span className={`font-bold ${getProgressColor(stats.steps.value, stats.steps.goal.min, stats.steps.goal.max)}`}>
|
<span className={`font-bold ${getProgressColor(stats.steps?.value ?? 0, stats.steps?.goal?.min ?? 0, stats.steps?.goal?.max ?? 0)}`}>
|
||||||
{stats.steps.value.toLocaleString()} / {stats.steps.goal.min}-{stats.steps.goal.max}
|
{(stats.steps?.value ?? 0).toLocaleString()} / {stats.steps?.goal?.min ?? 0}-{stats.steps?.goal?.max ?? 0}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-full bg-gray-200 rounded-full h-3">
|
<div className="w-full bg-gray-200 rounded-full h-3">
|
||||||
<div
|
<div
|
||||||
className="bg-indigo-600 h-3 rounded-full transition-all"
|
className="bg-indigo-600 h-3 rounded-full transition-all"
|
||||||
style={{ width: `${Math.min(100, getProgressPercent(stats.steps.value, stats.steps.goal.min, stats.steps.goal.max))}%` }}
|
style={{ width: `${Math.min(100, getProgressPercent(stats.steps?.value ?? 0, stats.steps?.goal?.min ?? 0, stats.steps?.goal?.max ?? 0))}%` }}
|
||||||
></div>
|
></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -309,14 +325,14 @@ function FitbitIntegration({ onNavigate }) {
|
|||||||
<div className="mb-6">
|
<div className="mb-6">
|
||||||
<div className="flex justify-between items-center mb-2">
|
<div className="flex justify-between items-center mb-2">
|
||||||
<span className="text-gray-700 font-medium">Этажи</span>
|
<span className="text-gray-700 font-medium">Этажи</span>
|
||||||
<span className={`font-bold ${getProgressColor(stats.floors.value, stats.floors.goal.min, stats.floors.goal.max)}`}>
|
<span className={`font-bold ${getProgressColor(stats.floors?.value ?? 0, stats.floors?.goal?.min ?? 0, stats.floors?.goal?.max ?? 0)}`}>
|
||||||
{stats.floors.value} / {stats.floors.goal.min}-{stats.floors.goal.max}
|
{stats.floors?.value ?? 0} / {stats.floors?.goal?.min ?? 0}-{stats.floors?.goal?.max ?? 0}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-full bg-gray-200 rounded-full h-3">
|
<div className="w-full bg-gray-200 rounded-full h-3">
|
||||||
<div
|
<div
|
||||||
className="bg-indigo-600 h-3 rounded-full transition-all"
|
className="bg-indigo-600 h-3 rounded-full transition-all"
|
||||||
style={{ width: `${Math.min(100, getProgressPercent(stats.floors.value, stats.floors.goal.min, stats.floors.goal.max))}%` }}
|
style={{ width: `${Math.min(100, getProgressPercent(stats.floors?.value ?? 0, stats.floors?.goal?.min ?? 0, stats.floors?.goal?.max ?? 0))}%` }}
|
||||||
></div>
|
></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -325,14 +341,14 @@ function FitbitIntegration({ onNavigate }) {
|
|||||||
<div className="mb-6">
|
<div className="mb-6">
|
||||||
<div className="flex justify-between items-center mb-2">
|
<div className="flex justify-between items-center mb-2">
|
||||||
<span className="text-gray-700 font-medium">Баллы кардио</span>
|
<span className="text-gray-700 font-medium">Баллы кардио</span>
|
||||||
<span className={`font-bold ${getProgressColor(stats.azm.value, stats.azm.goal.min, stats.azm.goal.max)}`}>
|
<span className={`font-bold ${getProgressColor(stats.azm?.value ?? 0, stats.azm?.goal?.min ?? 0, stats.azm?.goal?.max ?? 0)}`}>
|
||||||
{stats.azm.value} / {stats.azm.goal.min}-{stats.azm.goal.max}
|
{stats.azm?.value ?? 0} / {stats.azm?.goal?.min ?? 0}-{stats.azm?.goal?.max ?? 0}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-full bg-gray-200 rounded-full h-3">
|
<div className="w-full bg-gray-200 rounded-full h-3">
|
||||||
<div
|
<div
|
||||||
className="bg-indigo-600 h-3 rounded-full transition-all"
|
className="bg-indigo-600 h-3 rounded-full transition-all"
|
||||||
style={{ width: `${Math.min(100, getProgressPercent(stats.azm.value, stats.azm.goal.min, stats.azm.goal.max))}%` }}
|
style={{ width: `${Math.min(100, getProgressPercent(stats.azm?.value ?? 0, stats.azm?.goal?.min ?? 0, stats.azm?.goal?.max ?? 0))}%` }}
|
||||||
></div>
|
></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user