loading of old data
This commit is contained in:
@@ -1 +1 @@
|
|||||||
{"2024-10-03T07:36:00.000Z":{"day":"2024-10-03T07:36:00.000Z","count":0,"difficulty":3,"sleep":7,"rest":3,"freeTime":2,"stress":3}}
|
{"2024-10-03":{"day":"2024-10-03","count":0,"difficulty":3,"sleep":7,"rest":3,"freeTime":2,"stress":3}}
|
||||||
@@ -81,28 +81,32 @@
|
|||||||
|
|
||||||
const setUpRestSlider = () => {
|
const setUpRestSlider = () => {
|
||||||
setTimeout( () => {
|
setTimeout( () => {
|
||||||
restSlider.value.setUp( 7, 3 );
|
restSlider.value.setUp( 7, rest.value );
|
||||||
}, 500 );
|
}, 500 );
|
||||||
}
|
}
|
||||||
|
|
||||||
const setUpDifficultySlider = () => {
|
const setUpDifficultySlider = () => {
|
||||||
setTimeout( () => {
|
setTimeout( () => {
|
||||||
difficultySlider.value.setUp( 7, 3 );
|
difficultySlider.value.setUp( 7, difficulty.value );
|
||||||
}, 1000 );
|
}, 1000 );
|
||||||
}
|
}
|
||||||
|
|
||||||
const setUpStressSlider = () => {
|
const setUpStressSlider = () => {
|
||||||
setTimeout( () => {
|
setTimeout( () => {
|
||||||
stressSlider.value.setUp( 7, 3 );
|
stressSlider.value.setUp( 7, stress.value );
|
||||||
}, 1500 );
|
}, 1500 );
|
||||||
}
|
}
|
||||||
|
|
||||||
const setUpFreeTimeSlider = () => {
|
const setUpFreeTimeSlider = () => {
|
||||||
setTimeout( () => {
|
setTimeout( () => {
|
||||||
freeTimeSlider.value.setUp( 5, 2 );
|
freeTimeSlider.value.setUp( 5, freeTime.value );
|
||||||
}, 2000 );
|
}, 2000 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getDate = ( date: Date ): string => {
|
||||||
|
return date.toISOString().slice( 0, date.toISOString().indexOf( 'T' ) );
|
||||||
|
}
|
||||||
|
|
||||||
const submitForm = () => {
|
const submitForm = () => {
|
||||||
if ( date.value && difficulty.value > -1 && stress.value > -1 && rest.value > -1 && cigaretCount.value >= 0 && sleepHours.value >= 0 ) {
|
if ( date.value && difficulty.value > -1 && stress.value > -1 && rest.value > -1 && cigaretCount.value >= 0 && sleepHours.value >= 0 ) {
|
||||||
if ( sleepHours.value < 2 ) {
|
if ( sleepHours.value < 2 ) {
|
||||||
@@ -117,11 +121,21 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface SaveData {
|
||||||
|
day: string;
|
||||||
|
count: number;
|
||||||
|
difficulty: number;
|
||||||
|
sleep: number;
|
||||||
|
rest: number;
|
||||||
|
freeTime: number;
|
||||||
|
stress: number;
|
||||||
|
}
|
||||||
|
|
||||||
const sendForm = () => {
|
const sendForm = () => {
|
||||||
fetch( localStorage.getItem( 'url' ) + '/update', {
|
fetch( localStorage.getItem( 'url' ) + '/update', {
|
||||||
method: 'post',
|
method: 'post',
|
||||||
body: JSON.stringify( {
|
body: JSON.stringify( {
|
||||||
day: date.value?.toISOString(),
|
day: getDate( date.value ?? new Date() ),
|
||||||
count: cigaretCount.value,
|
count: cigaretCount.value,
|
||||||
difficulty: difficulty.value,
|
difficulty: difficulty.value,
|
||||||
sleep: sleepHours.value,
|
sleep: sleepHours.value,
|
||||||
@@ -141,18 +155,28 @@
|
|||||||
alert( `Failed to save data (${ res.status })` );
|
alert( `Failed to save data (${ res.status })` );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const dateUpdatedHandler = () => {
|
const dateUpdatedHandler = () => {
|
||||||
console.log( date.value );
|
|
||||||
if ( date.value ) {
|
if ( date.value ) {
|
||||||
if ( date.value.getTime() <= new Date().getTime() + 10000 ) {
|
if ( date.value.getTime() <= new Date().getTime() + 10000 ) {
|
||||||
hasSelectedDate.value = true;
|
hasSelectedDate.value = true;
|
||||||
// TODO: Load old data, if present
|
// Load old data, if present
|
||||||
|
if ( oldData[ getDate( date.value ) ] ) {
|
||||||
if ( oldData[ date.value.toISOString() ] ) {
|
const data = oldData[ getDate( date.value ) ];
|
||||||
// TODO: Finish
|
cigaretCount.value = data.count ?? 0;
|
||||||
|
difficulty.value = data.difficulty ?? 3;
|
||||||
|
rest.value = data.rest ?? 3;
|
||||||
|
freeTime.value = data.freeTime ?? 2;
|
||||||
|
sleepHours.value = data.sleep ?? 0;
|
||||||
|
stress.value = data.stress ?? 3;
|
||||||
|
} else {
|
||||||
|
cigaretCount.value = 0;
|
||||||
|
difficulty.value = 3;
|
||||||
|
rest.value = 3;
|
||||||
|
freeTime.value = 2;
|
||||||
|
sleepHours.value = 0;
|
||||||
|
stress.value = 3;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const errors = [
|
const errors = [
|
||||||
@@ -175,7 +199,7 @@
|
|||||||
|
|
||||||
|
|
||||||
interface OldData {
|
interface OldData {
|
||||||
[key: string]: object;
|
[key: string]: SaveData;
|
||||||
}
|
}
|
||||||
|
|
||||||
let oldData: OldData = {};
|
let oldData: OldData = {};
|
||||||
|
|||||||
Reference in New Issue
Block a user