Spaces:
Runtime error
Runtime error
Update templates/index.html
Browse files- templates/index.html +186 -31
templates/index.html
CHANGED
@@ -1,43 +1,198 @@
|
|
1 |
-
|
2 |
-
<html>
|
3 |
<head>
|
4 |
-
<
|
|
|
|
|
5 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
.translation-container {
|
|
|
7 |
border: 1px solid #ddd;
|
8 |
-
padding:
|
9 |
-
margin:
|
|
|
10 |
display: flex;
|
11 |
justify-content: space-between;
|
12 |
-
align-items:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
}
|
14 |
</style>
|
15 |
</head>
|
16 |
<body>
|
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 |
</body>
|
43 |
</html>
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Traductions Yipunu</title>
|
7 |
<style>
|
8 |
+
body {
|
9 |
+
font-family: sans-serif;
|
10 |
+
margin: 20px;
|
11 |
+
background-color: #f4f4f4;
|
12 |
+
}
|
13 |
+
h1 {
|
14 |
+
text-align: center;
|
15 |
+
}
|
16 |
+
|
17 |
.translation-container {
|
18 |
+
background-color: #fff;
|
19 |
border: 1px solid #ddd;
|
20 |
+
padding: 15px;
|
21 |
+
margin: 15px 0;
|
22 |
+
border-radius: 8px;
|
23 |
display: flex;
|
24 |
justify-content: space-between;
|
25 |
+
align-items: flex-start; /* Alignez au début */
|
26 |
+
}
|
27 |
+
.translation-text{
|
28 |
+
flex: 2; /* Prend plus d'espace */
|
29 |
+
padding-right: 20px
|
30 |
+
}
|
31 |
+
.translation-actions {
|
32 |
+
display: flex;
|
33 |
+
flex-direction: column; /* Alignez verticalement */
|
34 |
+
}
|
35 |
+
.translation-actions a, .translation-actions button {
|
36 |
+
display: inline-block;
|
37 |
+
margin: 5px;
|
38 |
+
padding: 8px 12px;
|
39 |
+
background-color: #007bff;
|
40 |
+
color: #fff;
|
41 |
+
text-decoration: none;
|
42 |
+
border-radius: 5px;
|
43 |
+
border: none;
|
44 |
+
cursor: pointer;
|
45 |
+
text-align: center;
|
46 |
+
transition: background-color 0.3s ease;
|
47 |
+
}
|
48 |
+
.translation-actions button {
|
49 |
+
background-color: #28a745;
|
50 |
+
}
|
51 |
+
.translation-actions a:hover, .translation-actions button:hover {
|
52 |
+
background-color: #0056b3;
|
53 |
+
}
|
54 |
+
textarea{
|
55 |
+
margin-top: 10px;
|
56 |
+
border-radius:5px;
|
57 |
+
width: 250px;
|
58 |
+
padding: 8px 12px
|
59 |
+
}
|
60 |
+
.likes-dislikes {
|
61 |
+
font-size: .8em;
|
62 |
+
margin-top: 10px
|
63 |
+
}
|
64 |
+
.feedback-sent{
|
65 |
+
font-size: .8em;
|
66 |
+
margin-top: 10px
|
67 |
}
|
68 |
</style>
|
69 |
</head>
|
70 |
<body>
|
71 |
+
<h1>Traductions Yipunu</h1>
|
72 |
+
<div id="translations-container">
|
73 |
+
</div>
|
74 |
+
<script>
|
75 |
+
document.addEventListener('DOMContentLoaded', () => {
|
76 |
+
fetch('/data')
|
77 |
+
.then(response => response.json())
|
78 |
+
.then(data => {
|
79 |
+
const translations = data.translations;
|
80 |
+
const translationsContainer = document.getElementById('translations-container');
|
81 |
+
|
82 |
+
translations.forEach(translation => {
|
83 |
+
const container = document.createElement('div');
|
84 |
+
container.className = 'translation-container';
|
85 |
+
const textDiv = document.createElement('div');
|
86 |
+
textDiv.className = 'translation-text'
|
87 |
+
|
88 |
+
textDiv.innerHTML = `<p><strong>Français:</strong> ${translation.fr}</p>
|
89 |
+
<p><strong>Yipunu:</strong> ${translation.yi}</p>
|
90 |
+
<p class="likes-dislikes">Likes: <span id="likes-${translation.id}">${translation.likes}</span> | Dislikes: <span id="dislikes-${translation.id}">${translation.dislikes}</span></p>
|
91 |
+
`
|
92 |
+
|
93 |
+
const actionDiv = document.createElement('div');
|
94 |
+
actionDiv.className = "translation-actions"
|
95 |
+
const likeLink = document.createElement('a');
|
96 |
+
likeLink.href = `/vote/${translation.id}/like`;
|
97 |
+
likeLink.innerText = 'Like';
|
98 |
+
likeLink.onclick = async (e) => {
|
99 |
+
e.preventDefault();
|
100 |
+
await voteTranslation(translation.id, 'like');
|
101 |
+
};
|
102 |
+
|
103 |
+
|
104 |
+
const dislikeLink = document.createElement('a');
|
105 |
+
dislikeLink.href = `/vote/${translation.id}/dislike`;
|
106 |
+
dislikeLink.innerText = 'Dislike';
|
107 |
+
dislikeLink.onclick = async (e) => {
|
108 |
+
e.preventDefault();
|
109 |
+
await voteTranslation(translation.id, 'dislike');
|
110 |
+
};
|
111 |
+
const feedbackForm = document.createElement('form');
|
112 |
+
feedbackForm.action = `/submit_feedback/${translation.id}`;
|
113 |
+
feedbackForm.method = 'POST';
|
114 |
+
const feedbackTextarea = document.createElement('textarea');
|
115 |
+
feedbackTextarea.name = 'feedback';
|
116 |
+
feedbackTextarea.placeholder = 'Laisser votre avis';
|
117 |
+
const feedbackButton = document.createElement('button');
|
118 |
+
feedbackButton.type = 'submit';
|
119 |
+
feedbackButton.innerText = 'Envoyer avis';
|
120 |
+
|
121 |
+
feedbackForm.appendChild(feedbackTextarea);
|
122 |
+
feedbackForm.appendChild(feedbackButton);
|
123 |
+
feedbackForm.addEventListener('submit', async(e)=>{
|
124 |
+
e.preventDefault();
|
125 |
+
await submitFeedback(translation.id, feedbackTextarea.value, container);
|
126 |
+
});
|
127 |
+
actionDiv.appendChild(likeLink);
|
128 |
+
actionDiv.appendChild(dislikeLink);
|
129 |
+
actionDiv.appendChild(feedbackForm);
|
130 |
+
|
131 |
+
const feedbackStatus = document.createElement('p');
|
132 |
+
feedbackStatus.className = 'feedback-sent';
|
133 |
+
if(translation.feedback_sent){
|
134 |
+
feedbackStatus.textContent = "Feedback envoyé"
|
135 |
+
}
|
136 |
+
actionDiv.appendChild(feedbackStatus);
|
137 |
+
|
138 |
+
|
139 |
+
|
140 |
+
container.appendChild(textDiv);
|
141 |
+
container.appendChild(actionDiv);
|
142 |
+
translationsContainer.appendChild(container);
|
143 |
+
|
144 |
+
});
|
145 |
+
})
|
146 |
+
.catch(error => console.error('Error fetching data:', error));
|
147 |
+
});
|
148 |
+
|
149 |
+
async function voteTranslation(id, action) {
|
150 |
+
try {
|
151 |
+
await fetch(`/vote/${id}/${action}`);
|
152 |
+
const translation = translations.find(t => t.id === id);
|
153 |
+
if(action == "like") {
|
154 |
+
translation.likes += 1
|
155 |
+
document.getElementById(`likes-${id}`).innerText = translation.likes;
|
156 |
+
} else {
|
157 |
+
translation.dislikes += 1
|
158 |
+
document.getElementById(`dislikes-${id}`).innerText = translation.dislikes;
|
159 |
+
}
|
160 |
+
|
161 |
+
} catch (error) {
|
162 |
+
console.error('Error during vote:', error);
|
163 |
+
}
|
164 |
+
}
|
165 |
+
|
166 |
+
|
167 |
+
async function submitFeedback(id, feedback, container) {
|
168 |
+
try {
|
169 |
+
const formData = new FormData();
|
170 |
+
formData.append('feedback', feedback);
|
171 |
+
const response = await fetch(`/submit_feedback/${id}`, {
|
172 |
+
method: 'POST',
|
173 |
+
body: formData
|
174 |
+
});
|
175 |
+
if (response.ok) {
|
176 |
+
const feedbackSentElement = container.querySelector('.feedback-sent');
|
177 |
+
if (feedbackSentElement){
|
178 |
+
feedbackSentElement.textContent = 'Feedback envoyé';
|
179 |
+
} else {
|
180 |
+
const newFeedbackSentElement = document.createElement('p');
|
181 |
+
newFeedbackSentElement.className = "feedback-sent";
|
182 |
+
newFeedbackSentElement.textContent = 'Feedback envoyé';
|
183 |
+
container.querySelector('.translation-actions').appendChild(newFeedbackSentElement);
|
184 |
+
}
|
185 |
+
const translation = translations.find(t => t.id === id);
|
186 |
+
translation.feedback_sent = true
|
187 |
+
|
188 |
+
} else {
|
189 |
+
console.error('Error submitting feedback');
|
190 |
+
}
|
191 |
+
} catch (error) {
|
192 |
+
console.error('Error during submitting feedback:', error);
|
193 |
+
}
|
194 |
+
}
|
195 |
+
|
196 |
+
</script>
|
197 |
</body>
|
198 |
</html>
|