forked from jplip/self-care-front
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Z_edit.html
194 lines (185 loc) · 7.09 KB
/
Z_edit.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
---
permalink: /edit
---
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Edit Profile</title>
<style>
body {
font-family: 'Poppins', sans-serif;
background-color: #f2f2f2;
margin: 0;
padding: 20px; /* Adjusted padding */
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-image: url('e285661a023fb83c8d7f975980422c22.gif');
background-size: cover;
}
.profile-container {
max-width: 600px;
margin: 0 auto;
background: #fff;
border-radius: 15px;
text-align: center;
color: #333;
padding: 20px; /* Adjusted padding */
}
.profile-container h2 {
font-weight: 500;
color: #000;
margin-bottom: 20px; /* Decreased margin */
}
.profile-container textarea.bio-input {
width: 100%;
resize: none;
border-radius: 5px;
border: 1px solid #ccc;
padding: 10px;
margin-bottom: 10px; /* Decreased margin */
}
.profile-container img.profile-image {
width: 100px;
height: 100px;
border-radius: 50%;
margin-top: 20px; /* Decreased margin */
margin-bottom: 20px; /* Decreased margin */
}
.filter-buttons {
display: flex; /* Added display property */
justify-content: center; /* Added justify-content property */
}
.filter-buttons button {
padding: 10px 15px; /* Adjusted padding */
font-size: 16px;
background-color: #1c7a09;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
margin: 0 5px; /* Adjusted margin */
}
.filter-buttons button:hover {
background-color: #124d06;
}
.submit-button {
padding: 10px 15px;
font-size: 16px;
background-color: #08d101;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}
.submit-button:hover {
background-color: #08af02;
}
#update-image {
display: block;
width: 200px;
background: #1e4f2b;
color: #fff;
padding: 12px;
margin: 10px auto;
border-radius: 5px;
cursor: pointer;
}
input[type="file"] {
display: none;
}
</style>
<!-- Include the sidebar HTML -->
{% include sidebar.html %}
</head>
<body>
<div class="profile-container">
<h2>Edit Profile</h2>
<form id="profile-form" action="#" method="post">
<label for="age">Age:</label><br>
<input type="number" id="age" name="age"><br><br>
<label for="gender">Gender:</label><br>
<select id="gender" name="gender" required>
<option value="male">Male</option>
<option value="female">Female</option>
</select><br><br>
<label for="bio">Bio:</label><br>
<textarea id="bio" name="bio" class="bio-input" rows="4" cols="50"></textarea><br><br>
<label for="exerciseGoals">Exercise Goals:</label><br>
<input type="text" id="exerciseGoals" name="exerciseGoals"><br><br>
<label for="sleepGoals">Sleep Goals:</label><br>
<input type="text" id="sleepGoals" name="sleepGoals"><br><br>
<label for="image">Profile Image:</label><br>
<img src="images/profile.webp" id="pfp" class="profile-image">
<label id='update-image' for="input-image">Upload Image</label>
<input id='input-image' type="file" accept="image/jpeg, image/jpg, image/png">
<canvas id="canvas" class="profile-image"></canvas>
<div class="filter-buttons">
<button type="button" onclick="applyFilter('grayscale')">Grayscale</button>
<button type="button" onclick="applyFilter('invert')">Invert</button>
<button type="button" onclick="applyFilter('sepia')">Sepia</button>
<button type="button" onclick="resetImage()">Reset</button>
</div><br><br>
<button type="submit" class="submit-button">Save Changes</button>
</form>
</div>
</body>
</html>
<script type="module">
import { uri, options } from '{{site.baseurl}}/assets/js/api/config.js';
const userNameFromLocalStorage = localStorage.getItem('loggedInUserName');
const userIDFromLocalStorage = localStorage.getItem('loggedInUserId');
const userNameElement = document.getElementById('user-name');
if (userNameFromLocalStorage) {
userNameElement.textContent = userNameFromLocalStorage;
}
let pfp = document.getElementById('pfp');
let inputImg = document.getElementById('input-image');
inputImg.onchange = function() {
pfp.src = URL.createObjectURL(inputImg.files[0]);
}
async function handleSubmit(event) {
event.preventDefault();
const formData = {
id: userIDFromLocalStorage,
age: document.getElementById('age').value,
gender: document.getElementById('gender').value,
bio: document.getElementById('bio').value,
exerciseGoals: document.getElementById('exerciseGoals').value,
sleepGoals: document.getElementById('sleepGoals').value,
};
canvas.toBlob(async (blob) => {
try {
const base64String = await blobToBase64(blob);
formData.image_path = base64String;
const response = await fetch(`https://well.stu.nighthawkcodingsociety.com/api/users/${userIDFromLocalStorage}`, {
...options,
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(formData)
});
if (!response.ok) {
const errorText = await response.text();
throw new Error(`Server error: ${errorText}`);
}
const contentType = response.headers.get('content-type');
if (contentType && contentType.includes('application/json')) {
const result = await response.json();
console.log(result);
} else {
const resultText = await response.text();
throw new Error(`Unexpected response type: ${resultText}`);
}
} catch (error) {
console.error('Error during form submission:', error);
}
}, 'image/png');
}
</script>
<script src="{{site.baseurl}}/assets/script.js"></script>