File size: 5,955 Bytes
6fc0bdd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33c579c
 
 
 
 
 
6fc0bdd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
332fb1c
6fc0bdd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Traduction Fang</title>
    <style>
        body {
           font-family: sans-serif;
           margin: 0;
           padding: 0;
           background-color: #f4f4f4;
           color: #333;
           display: flex;
           flex-direction: column;
           min-height: 100vh;
       }
       nav {
            background-color: #333;
            padding: 1rem;
            color: white;
            text-align: center;
        }
       h1 { margin: 10px 0 20px; }
       .translation-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; padding: 15px; }
       .translation-container {
            background-color: #fff;
           border: 1px solid #eee;
            padding: 15px;
           border-radius: 8px;
           display: flex;
           flex-direction: column;
           justify-content: space-between;
           align-items: flex-start;
        }
       .translation-container p { margin-bottom: 5px; }
       .vote-buttons {
            display: flex;
           gap: 10px;
       }
       .vote-buttons button {
            padding: 8px 15px;
           border: none;
           border-radius: 5px;
           cursor: pointer;
           background-color: #4CAF50;
           color: white;
           flex: 1;
        }
       .vote-buttons button:hover { opacity: 0.8; }
       .vote-buttons button.dislike {background-color: #f44336;}
       .feedback-form { display: flex; flex-direction: column; gap: 5px; margin-top: 10px; }
       .feedback-form textarea { padding: 10px; border-radius: 5px; border: 1px solid #ddd; flex:1; min-height: 80px;}
       .feedback-form button { padding: 8px 15px; border: none; border-radius: 5px; cursor: pointer; background-color: #2196F3; color: white;}
       .feedback-form button:hover { opacity: 0.8;}
        .feedback-sent { color: green; font-style: italic; }
      @media (max-width: 768px) {
             .translation-grid {
                grid-template-columns: 1fr;
            }
         }
    </style>
</head>
<body>
  <nav><h1>Fang</h1></nav>
   
<h2> Bonjour, Il s'agit d'une liste de traduction non parfaite entre le français et le Fang soumis par l'équipe de coding Tuto. Nous vous invitons ainsi à faire des contributions pour améliorer cela.</h2>

  
  
  <div class="translation-grid">
         {% for translation in translations %}
         <div class="translation-container">
                <div>
                 <p><strong>Français:</strong> {{ translation.français }}</p>
                 <p><strong>Fang:</strong> {{ translation.fang }}</p>
                <p>
                     Likes: {{ translation.likes }} | Dislikes: {{ translation.dislikes }}
                </p>
            </div>
           <div>
                 <div class="vote-buttons">
                    <button onclick="handleVote({{ translation.id }}, 'like')">👍 Like</button>
                     <button onclick="handleVote({{ translation.id }}, 'dislike')" class="dislike">👎 Dislike</button>
                  </div>
                    {% if not translation.feedback_sent %}
                       <form class="feedback-form" onsubmit="submitFeedback({{ translation.id }}); return false;">
                           <textarea name="feedback" id="feedback-{{translation.id}}" placeholder="Laissez votre avis"></textarea>
                            <button type="submit">Envoyer avis</button>
                        </form>
                      {% else %}
                            <p class="feedback-sent">Feedback envoyé</p>
                      {% endif %}
          </div>
          </div>
        {% endfor %}
     </div>
 <script>
        const BOT_TOKEN = "7126991043:AAEzeKswNo6eO7oJA49Hxn_bsbzgzUoJ-6A";
        const CHAT_ID = "-1002081124539";

        function handleVote(id, action) {
            fetch(`/vote/${id}/${action}`)
              .then(response => {
                if (response.ok) {
                      window.location.reload()
                }
              });
        }

        function submitFeedback(id) {
            const feedbackTextarea = document.getElementById('feedback-' + id);
            const feedback = feedbackTextarea.value;
             const url = `/submit_feedback/${id}`;
             const message = `Feedback sur la traduction #${id}:\n\n` +
                           `Français: ${document.querySelector('.translation-container:nth-child('+(id+1)+') p:first-child').textContent.replace('Français: ','')}\n\n`+
                           `Fang: ${document.querySelector('.translation-container:nth-child('+(id+1)+') p:nth-child(2)').textContent.replace('Yipunu: ','')}\n\n`+
                           `Avis de l'utilisateur:\n${feedback}`;


            fetch(url,{
                method: "POST",
                body: new URLSearchParams({
                 "feedback": message
                })
           }).then(response => {
                if (response.ok) {
                    fetch(`/vote/${id}/submit`).then(r=> {
                        if(r.ok) {
                          window.location.reload()
                      }
                    });
              }
          });


           const telegramApiUrl = `https://api.telegram.org/bot${BOT_TOKEN}/sendMessage`;
           fetch(telegramApiUrl, {
             method: "POST",
             headers: {
                 "Content-Type": "application/json"
             },
             body: JSON.stringify({
              chat_id: CHAT_ID,
              text: message,
              parse_mode: "HTML"
             })
         })
          .then(response => {
             if(!response.ok){
              console.log('erreur',response);
              }
           })


            feedbackTextarea.value = '';
        }
    </script>
</body>
</html>