forked from jplip/self-care-front
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZ_diary.html
217 lines (194 loc) · 6.32 KB
/
Z_diary.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
---
permalink: /diary
---
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-image: url("https://files.catbox.moe/1m85ow.png");
background-size: cover;
background-repeat: no-repeat;
background-position: top;
}
#diary-title-container {
background-color: rgb(132, 192, 134);
background-size: cover;
background-repeat: no-repeat;
background-position: top;
color: black; /* Black text */
padding: 50px 20px;
text-align: center;
}
#diary {
width: 70%; /* Adjust width as needed */
margin: 0 auto; /* Center the textarea */
padding: 10px;
border: 1px solid #ccc;
border-radius: 8px;
}
/* Center text inside diary-container */
.diary-container {
text-align: center;
}
/* Style the data container */
.data-container {
background-color: white;
border: 2px solid #ccc; /* Border style */
padding: 20px; /* Padding inside the container */
margin: 20px auto; /* Center the container */
max-width: 600px; /* Maximum width of the container */
}
.diary-buttons {
padding: 10px 20px; /* Padding around the button text */
background-color: #007bff; /* Button background color */
color: white; /* Button text color */
border: none; /* Remove button border */
border-radius: 5px; /* Rounded corners */
cursor: pointer; /* Show pointer cursor on hover */
transition: background-color 0.3s ease; /* Smooth transition for background color */
}
/* Hover effect for the button */
.diary-buttons:hover {
background-color: #0056b3; /* Darker background color on hover */
}
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-image: url('e285661a023fb83c8d7f975980422c22.gif');
background-size: cover;
}
.container {
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.form-control {
margin-bottom: 15px;
}
.form-control label {
font-weight: bold;
}
.form-control input {
width: 100%;
padding: 8px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
.form-control input[type="submit"] {
background-color: #4CAF50;
color: white;
cursor: pointer;
}
.form-control input[type="submit"]:hover {
background-color: #45a049;
}
.error-message {
color: red;
margin-top: 5px;
}
</style>
{% include sidebar.html %}
<body class='sandiego-background'>
<!-- Home button linking to index.html -->
<div>
<div id='diary-title-container'>
<h1 class='title'>Personal Diary</h1>
</div>
<br>
<br>
<div class="diary-container">
<h2 id="subtitle">Diary:</h2>
<form>
<textarea id="diary" class="input" placeholder="(Day), (Time): (Activity)"></textarea><br>
</form>
<button class="diary-buttons" onclick="diary()">New Entry</button>
<br>
<br>
<button class="diary-buttons" onclick="fetchDiary()">Load Personal Diary</button>
<p id="error"></p>
<div class="data-container">
<h2 id='subtitle'>Your Diary:</h2>
<div id="data"></div>
</div>
</div>
</div>
<script>
const userIDFromLocalStorage = localStorage.getItem('loggedInUserId');
console.log(userIDFromLocalStorage);
const userNameFromLocalStorage = localStorage.getItem('loggedInUserName');
function fetchDiary() {
fetch(`https://well.stu.nighthawkcodingsociety.com/api/users/${userIDFromLocalStorage}`)
// Local: http://127.0.0.1:8432
// Deployed:
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
let dataContainer = document.getElementById("data");
// Set innerHTML to data.diary directly
let diary = data.diary;
let itineraryItems = diary.split("||");
itineraryItems.forEach(item => {
let row = document.createElement("div");
row.textContent = item.trim(); // Trim to remove any extra whitespace
// Append row to the container
dataContainer.appendChild(row);
}); // <-- Added closing parenthesis and curly brace here
})
.catch(error => {
console.error('Error fetching diary:', error);
// Handle error
});
}
function diary() {
// Get the text content from the textarea
let text = document.getElementById("diary").value;
// Create an object with the text data and a unique UID (timestamp)
let data = {
"id": userIDFromLocalStorage,
"name": userNameFromLocalStorage,
"diary": text,
};
let options = {
method: 'PUT',
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
body: JSON.stringify(data),
};
fetch(`https://well.stu.nighthawkcodingsociety.com/api/users/${userIDFromLocalStorage}`, options)
.then(response => {
if (response.ok) {
// Handle successful submission
document.getElementById("error").innerHTML = "Diary updated!";
// Fetch updated images after submission
fetchDiary();
} else {
// Handle submission error
return response.json().then(errorData => {
if (errorData && errorData.message) {
document.getElementById("error").innerHTML = errorData.message;
} else {
document.getElementById("error").innerHTML = "Error submitting diary";
}
});
}
})
.catch(error => {
console.error("Error:", error);
document.getElementById("error").innerHTML = "Error submitting diary";
});
}
</script>