Spaces:
Sleeping
Sleeping
File size: 7,573 Bytes
03c61e3 24f661d 03c61e3 24f661d 03c61e3 24f661d 03c61e3 24f661d 03c61e3 24f661d 03c61e3 24f661d 03c61e3 24f661d |
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 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Traductions Yipunu</title>
<style>
body {
font-family: sans-serif;
margin: 20px;
background-color: #f4f4f4;
}
h1 {
text-align: center;
}
.translation-container {
background-color: #fff;
border: 1px solid #ddd;
padding: 15px;
margin: 15px 0;
border-radius: 8px;
display: flex;
justify-content: space-between;
align-items: flex-start; /* Alignez au début */
}
.translation-text{
flex: 2; /* Prend plus d'espace */
padding-right: 20px
}
.translation-actions {
display: flex;
flex-direction: column; /* Alignez verticalement */
}
.translation-actions a, .translation-actions button {
display: inline-block;
margin: 5px;
padding: 8px 12px;
background-color: #007bff;
color: #fff;
text-decoration: none;
border-radius: 5px;
border: none;
cursor: pointer;
text-align: center;
transition: background-color 0.3s ease;
}
.translation-actions button {
background-color: #28a745;
}
.translation-actions a:hover, .translation-actions button:hover {
background-color: #0056b3;
}
textarea{
margin-top: 10px;
border-radius:5px;
width: 250px;
padding: 8px 12px
}
.likes-dislikes {
font-size: .8em;
margin-top: 10px
}
.feedback-sent{
font-size: .8em;
margin-top: 10px
}
</style>
</head>
<body>
<h1>Traductions Yipunu</h1>
<div id="translations-container">
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
fetch('/data')
.then(response => response.json())
.then(data => {
const translations = data.translations;
const translationsContainer = document.getElementById('translations-container');
translations.forEach(translation => {
const container = document.createElement('div');
container.className = 'translation-container';
const textDiv = document.createElement('div');
textDiv.className = 'translation-text'
textDiv.innerHTML = `<p><strong>Français:</strong> ${translation.fr}</p>
<p><strong>Yipunu:</strong> ${translation.yi}</p>
<p class="likes-dislikes">Likes: <span id="likes-${translation.id}">${translation.likes}</span> | Dislikes: <span id="dislikes-${translation.id}">${translation.dislikes}</span></p>
`
const actionDiv = document.createElement('div');
actionDiv.className = "translation-actions"
const likeLink = document.createElement('a');
likeLink.href = `/vote/${translation.id}/like`;
likeLink.innerText = 'Like';
likeLink.onclick = async (e) => {
e.preventDefault();
await voteTranslation(translation.id, 'like');
};
const dislikeLink = document.createElement('a');
dislikeLink.href = `/vote/${translation.id}/dislike`;
dislikeLink.innerText = 'Dislike';
dislikeLink.onclick = async (e) => {
e.preventDefault();
await voteTranslation(translation.id, 'dislike');
};
const feedbackForm = document.createElement('form');
feedbackForm.action = `/submit_feedback/${translation.id}`;
feedbackForm.method = 'POST';
const feedbackTextarea = document.createElement('textarea');
feedbackTextarea.name = 'feedback';
feedbackTextarea.placeholder = 'Laisser votre avis';
const feedbackButton = document.createElement('button');
feedbackButton.type = 'submit';
feedbackButton.innerText = 'Envoyer avis';
feedbackForm.appendChild(feedbackTextarea);
feedbackForm.appendChild(feedbackButton);
feedbackForm.addEventListener('submit', async(e)=>{
e.preventDefault();
await submitFeedback(translation.id, feedbackTextarea.value, container);
});
actionDiv.appendChild(likeLink);
actionDiv.appendChild(dislikeLink);
actionDiv.appendChild(feedbackForm);
const feedbackStatus = document.createElement('p');
feedbackStatus.className = 'feedback-sent';
if(translation.feedback_sent){
feedbackStatus.textContent = "Feedback envoyé"
}
actionDiv.appendChild(feedbackStatus);
container.appendChild(textDiv);
container.appendChild(actionDiv);
translationsContainer.appendChild(container);
});
})
.catch(error => console.error('Error fetching data:', error));
});
async function voteTranslation(id, action) {
try {
await fetch(`/vote/${id}/${action}`);
const translation = translations.find(t => t.id === id);
if(action == "like") {
translation.likes += 1
document.getElementById(`likes-${id}`).innerText = translation.likes;
} else {
translation.dislikes += 1
document.getElementById(`dislikes-${id}`).innerText = translation.dislikes;
}
} catch (error) {
console.error('Error during vote:', error);
}
}
async function submitFeedback(id, feedback, container) {
try {
const formData = new FormData();
formData.append('feedback', feedback);
const response = await fetch(`/submit_feedback/${id}`, {
method: 'POST',
body: formData
});
if (response.ok) {
const feedbackSentElement = container.querySelector('.feedback-sent');
if (feedbackSentElement){
feedbackSentElement.textContent = 'Feedback envoyé';
} else {
const newFeedbackSentElement = document.createElement('p');
newFeedbackSentElement.className = "feedback-sent";
newFeedbackSentElement.textContent = 'Feedback envoyé';
container.querySelector('.translation-actions').appendChild(newFeedbackSentElement);
}
const translation = translations.find(t => t.id === id);
translation.feedback_sent = true
} else {
console.error('Error submitting feedback');
}
} catch (error) {
console.error('Error during submitting feedback:', error);
}
}
</script>
</body>
</html> |