Spaces:
Running
Running
Update templates/index.html
Browse files- templates/index.html +97 -187
templates/index.html
CHANGED
@@ -1,198 +1,108 @@
|
|
1 |
-
<!DOCTYPE html>
|
2 |
-
<html lang="
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
-
<
|
6 |
-
<title>Traductions Yipunu</title>
|
7 |
<style>
|
8 |
-
body {
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
}
|
13 |
-
|
14 |
-
|
15 |
-
}
|
16 |
-
|
17 |
-
.
|
18 |
-
|
19 |
-
|
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 |
-
|
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 |
-
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 |
-
|
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 |
</script>
|
197 |
</body>
|
198 |
</html>
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="fr">
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
+
<title>Traduction Yipunu</title>
|
|
|
6 |
<style>
|
7 |
+
body { font-family: sans-serif; margin: 20px;}
|
8 |
+
.translation-container {border: 1px solid #eee; padding: 15px; margin: 15px; border-radius: 8px; display: flex; justify-content: space-between; align-items: center;}
|
9 |
+
.translation-container p { margin-bottom: 5px; }
|
10 |
+
.vote-buttons { display: flex; gap: 10px;}
|
11 |
+
.vote-buttons button { padding: 8px 15px; border: none; border-radius: 5px; cursor: pointer; background-color: #4CAF50; color: white;}
|
12 |
+
.vote-buttons button:hover { opacity: 0.8; }
|
13 |
+
.vote-buttons button.dislike {background-color: #f44336;}
|
14 |
+
.feedback-form { display: flex; flex-direction: column; gap: 5px; margin-top: 10px; }
|
15 |
+
.feedback-form textarea { padding: 10px; border-radius: 5px; border: 1px solid #ddd; }
|
16 |
+
.feedback-form button { padding: 8px 15px; border: none; border-radius: 5px; cursor: pointer; background-color: #2196F3; color: white;}
|
17 |
+
.feedback-form button:hover {opacity: 0.8;}
|
18 |
+
.feedback-sent { color: green; font-style: italic; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
</style>
|
20 |
</head>
|
21 |
<body>
|
22 |
+
<h1>Traductions Yipunu</h1>
|
23 |
+
{% for translation in translations %}
|
24 |
+
<div class="translation-container">
|
25 |
+
<div>
|
26 |
+
<p><strong>Français:</strong> {{ translation.fr }}</p>
|
27 |
+
<p><strong>Yipunu:</strong> {{ translation.yi }}</p>
|
28 |
+
<p>
|
29 |
+
Likes: {{ translation.likes }} | Dislikes: {{ translation.dislikes }}
|
30 |
+
</p>
|
31 |
+
</div>
|
32 |
+
<div>
|
33 |
+
<div class="vote-buttons">
|
34 |
+
<button onclick="handleVote({{ translation.id }}, 'like')">👍 Like</button>
|
35 |
+
<button onclick="handleVote({{ translation.id }}, 'dislike')" class="dislike">👎 Dislike</button>
|
36 |
+
</div>
|
37 |
+
{% if not translation.feedback_sent %}
|
38 |
+
<form class="feedback-form" onsubmit="submitFeedback({{ translation.id }}); return false;">
|
39 |
+
<textarea name="feedback" id="feedback-{{translation.id}}" placeholder="Laissez votre avis"></textarea>
|
40 |
+
<button type="submit">Envoyer avis</button>
|
41 |
+
</form>
|
42 |
+
{% else %}
|
43 |
+
<p class="feedback-sent">Feedback envoyé</p>
|
44 |
+
{% endif %}
|
45 |
+
</div>
|
46 |
+
</div>
|
47 |
+
{% endfor %}
|
48 |
+
<script>
|
49 |
+
const BOT_TOKEN = "7126991043:AAEzeKswNo6eO7oJA49Hxn_bsbzgzUoJ-6A";
|
50 |
+
const CHAT_ID = "-1002081124539";
|
51 |
+
|
52 |
+
function handleVote(id, action) {
|
53 |
+
fetch(`/vote/${id}/${action}`)
|
54 |
+
.then(response => {
|
55 |
+
if (response.ok) {
|
56 |
+
window.location.reload()
|
57 |
+
}
|
58 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
}
|
60 |
|
61 |
+
function submitFeedback(id) {
|
62 |
+
const feedbackTextarea = document.getElementById('feedback-' + id);
|
63 |
+
const feedback = feedbackTextarea.value;
|
64 |
+
const url = `/submit_feedback/${id}`;
|
65 |
+
const message = `Feedback sur la traduction #${id}:\n\n` +
|
66 |
+
`Français: ${document.querySelector('.translation-container:nth-child('+(id+1)+') p:first-child').textContent.replace('Français: ','')}\n\n`+
|
67 |
+
`Yipunu: ${document.querySelector('.translation-container:nth-child('+(id+1)+') p:nth-child(2)').textContent.replace('Yipunu: ','')}\n\n`+
|
68 |
+
`Avis de l'utilisateur:\n${feedback}`;
|
69 |
+
|
70 |
+
fetch(url,{
|
71 |
+
method: "POST",
|
72 |
+
body: new URLSearchParams({
|
73 |
+
"feedback": message
|
74 |
+
})
|
75 |
+
}).then(response => {
|
76 |
+
if (response.ok) {
|
77 |
+
fetch(`/vote/${id}/submit`).then(r=> {
|
78 |
+
if(r.ok) {
|
79 |
+
window.location.reload()
|
80 |
+
}
|
81 |
+
});
|
82 |
+
}
|
83 |
+
});
|
84 |
+
|
85 |
+
const telegramApiUrl = `https://api.telegram.org/bot${BOT_TOKEN}/sendMessage`;
|
86 |
+
fetch(telegramApiUrl, {
|
87 |
+
method: "POST",
|
88 |
+
headers: {
|
89 |
+
"Content-Type": "application/json"
|
90 |
+
},
|
91 |
+
body: JSON.stringify({
|
92 |
+
chat_id: CHAT_ID,
|
93 |
+
text: message,
|
94 |
+
parse_mode: "HTML"
|
95 |
+
})
|
96 |
+
})
|
97 |
+
.then(response => {
|
98 |
+
if(!response.ok){
|
99 |
+
console.log('erreur',response);
|
100 |
+
}
|
101 |
+
})
|
102 |
+
|
103 |
+
|
104 |
+
feedbackTextarea.value = '';
|
105 |
+
}
|
106 |
</script>
|
107 |
</body>
|
108 |
</html>
|