feat: add calories goal
This commit is contained in:
@@ -100,6 +100,7 @@
|
|||||||
<div class="calories-banner">
|
<div class="calories-banner">
|
||||||
<div class="calories-number" id="caloriesCounter">0</div>
|
<div class="calories-number" id="caloriesCounter">0</div>
|
||||||
<div class="calories-text">Calories Today</div>
|
<div class="calories-text">Calories Today</div>
|
||||||
|
<div class="calories-text-goal" id="caloriesGoalText">of 0</div>
|
||||||
<div class="calories-text-alkaline" id="alkaline-level">80% Alkaline</div>
|
<div class="calories-text-alkaline" id="alkaline-level">80% Alkaline</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -229,6 +230,10 @@
|
|||||||
<div class="date-display">Define your macros goal</div>
|
<div class="date-display">Define your macros goal</div>
|
||||||
|
|
||||||
<form id="settingsForm" class="settings-form">
|
<form id="settingsForm" class="settings-form">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="caloriesGoal">Calories goal</label>
|
||||||
|
<input type="number" id="caloriesGoal" placeholder="Calories" required>
|
||||||
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="proteinGoal">Protein goal</label>
|
<label for="proteinGoal">Protein goal</label>
|
||||||
<input type="number" id="proteinGoal" placeholder="Proteins in grams" required>
|
<input type="number" id="proteinGoal" placeholder="Proteins in grams" required>
|
||||||
|
|||||||
@@ -156,6 +156,7 @@ async function handleSaveSettings(e: SubmitEvent) {
|
|||||||
showLoading();
|
showLoading();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const caloriesGoal = getInputById('caloriesGoal').value;
|
||||||
const proteinGoal = getInputById('proteinGoal').value;
|
const proteinGoal = getInputById('proteinGoal').value;
|
||||||
const fatGoal = getInputById('fatGoal').value;
|
const fatGoal = getInputById('fatGoal').value;
|
||||||
const carboGoal = getInputById('carboGoal').value;
|
const carboGoal = getInputById('carboGoal').value;
|
||||||
@@ -174,6 +175,7 @@ async function handleSaveSettings(e: SubmitEvent) {
|
|||||||
|
|
||||||
// Save to Appwrite
|
// Save to Appwrite
|
||||||
await AppwriteDB.saveUserSettings({
|
await AppwriteDB.saveUserSettings({
|
||||||
|
caloriesGoal: parseInt(caloriesGoal),
|
||||||
proteinGoal: parseInt(proteinGoal),
|
proteinGoal: parseInt(proteinGoal),
|
||||||
fatGoal: parseInt(fatGoal),
|
fatGoal: parseInt(fatGoal),
|
||||||
carboGoal: parseInt(carboGoal),
|
carboGoal: parseInt(carboGoal),
|
||||||
@@ -218,11 +220,13 @@ async function handleSettings() {
|
|||||||
const hasGoals = Array.isArray(settings) && settings.length > 0;
|
const hasGoals = Array.isArray(settings) && settings.length > 0;
|
||||||
if (hasGoals) {
|
if (hasGoals) {
|
||||||
const index = settings.length - 1;
|
const index = settings.length - 1;
|
||||||
|
getInputById('caloriesGoal').value = settings[index].caloriesGoal;
|
||||||
getInputById('proteinGoal').value = settings[index].proteinGoal;
|
getInputById('proteinGoal').value = settings[index].proteinGoal;
|
||||||
getInputById('fatGoal').value = settings[index].fatGoal;
|
getInputById('fatGoal').value = settings[index].fatGoal;
|
||||||
getInputById('carboGoal').value = settings[index].carboGoal;
|
getInputById('carboGoal').value = settings[index].carboGoal;
|
||||||
getInputById('fiberGoal').value = settings[index].fiberGoal;
|
getInputById('fiberGoal').value = settings[index].fiberGoal;
|
||||||
} else {
|
} else {
|
||||||
|
getInputById('caloriesGoal').value = '';
|
||||||
getInputById('proteinGoal').value = '';
|
getInputById('proteinGoal').value = '';
|
||||||
getInputById('fatGoal').value = '';
|
getInputById('fatGoal').value = '';
|
||||||
getInputById('carboGoal').value = '';
|
getInputById('carboGoal').value = '';
|
||||||
@@ -703,6 +707,12 @@ async function loadFoodEntries(date: Date) {
|
|||||||
const hasGoals = Array.isArray(settings) && settings.length > 0;
|
const hasGoals = Array.isArray(settings) && settings.length > 0;
|
||||||
if (hasGoals) {
|
if (hasGoals) {
|
||||||
const index = settings.length - 1;
|
const index = settings.length - 1;
|
||||||
|
getDivById('caloriesGoalText').classList.add('hidden');
|
||||||
|
if (parseInt(settings[index].caloriesGoal) > 0) {
|
||||||
|
getDivById('caloriesGoalText').textContent = `of ${settings[index].caloriesGoal}`;
|
||||||
|
getDivById('caloriesGoalText').classList.remove('hidden');
|
||||||
|
}
|
||||||
|
|
||||||
getDivById('proteinGoalText').classList.add('hidden');
|
getDivById('proteinGoalText').classList.add('hidden');
|
||||||
if (parseInt(settings[index].proteinGoal) > 0) {
|
if (parseInt(settings[index].proteinGoal) > 0) {
|
||||||
getDivById('proteinGoalText').textContent = `of ${settings[index].proteinGoal}`;
|
getDivById('proteinGoalText').textContent = `of ${settings[index].proteinGoal}`;
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ export type FoodStorage = {
|
|||||||
|
|
||||||
export type UserSettings = {
|
export type UserSettings = {
|
||||||
id?: string;
|
id?: string;
|
||||||
|
caloriesGoal?: number;
|
||||||
proteinGoal: number;
|
proteinGoal: number;
|
||||||
fatGoal: number;
|
fatGoal: number;
|
||||||
carboGoal: number;
|
carboGoal: number;
|
||||||
|
|||||||
Reference in New Issue
Block a user