-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
165 lines (144 loc) · 6.31 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title> Correio EmoElegante </title>
<link rel="stylesheet" href="style/style.css">
</head>
<body>
<div id="root">
<div class="index__header">
<h1 class="index__header-title">FUZUEMO</h1>
<img id="ademo-toggler" class="index__header-icon ademo-icon" src="static/ademo.png" alt="ademo">
<img id="zululu-toggler" class="index__header-icon zululu-icon" src="static/zululu.png" alt="zululu">
</div>
<form id="messageForm" class="index__form">
<div class="index__form-container">
<textarea id="message" class="index__form-input" form="messageForm" name="message" placeholder="Participe do projeto meu emo minha vida anonimamente!" rows="4" maxlength="280" type="text"></textarea>
<svg id="sendMessageButton" class="index__form-button" xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 512 512">
<path d="M498.1 5.6c10.1 7 15.4 19.1 13.5 31.2l-64 416c-1.5 9.7-7.4 18.2-16 23s-18.9 5.4-28 1.6L284 427.7l-68.5 74.1c-8.9 9.7-22.9 12.9-35.2 8.1S160 493.2 160 480V396.4c0-4 1.5-7.8 4.2-10.7L331.8 202.8c5.8-6.3 5.6-16-.4-22s-15.7-6.4-22-.7L106 360.8 17.7 316.6C7.1 311.3 .3 300.7 0 288.9s5.9-22.8 16.1-28.7l448-256c10.7-6.1 23.9-5.5 34 1.4z"/>
</svg>
</div>
</form>
<div class="index__header">
<h2 class="index__message-title">MENSAGENS</h2>
</div>
<ul id="messages" class="index__message-list">
<!-- -->
</ul>
</div>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
const url = "https://correioemoelegante.herokuapp.com/messages"
function sendMessage(message){
$.post({
url,
data: {
message
},
success: function(){
location.reload()
}
})
}
function updateLike(id){
$.ajax({
url,
type: 'PUT',
data: {
id
},
success: function(){
location.reload()
}
})
}
$(document).ready(function(){
$.ajax({ url,
context: document.body,
success: function(data){
const ids = JSON.parse(window.localStorage.getItem('ids')) || []
data.messages?.sort(function (a, b) {
return new Date(b.createdAt) - new Date(a.createdAt);
})
data.messages?.map((d) => {
var date = new Date(d.createdAt);
return $("#messages").append(`
<ol class="index__message-item">
<p class="index__message-item-content">${d.message}</p>
<div class="index__message-item-footer">
<svg id="${d.id}" class="index__message-item-footer-button xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 512 512">
${ids.find((res)=> res == d.id)
? `<path id="like-button" d="M47.6 300.4L228.3 469.1c7.5 7 17.4 10.9 27.7 10.9s20.2-3.9 27.7-10.9L464.4 300.4c30.4-28.3 47.6-68 47.6-109.5v-5.8c0-69.9-50.5-129.5-119.4-141C347 36.5 300.6 51.4 268 84L256 96 244 84c-32.6-32.6-79-47.5-124.6-39.9C50.5 55.6 0 115.2 0 185.1v5.8c0 41.5 17.2 81.2 47.6 109.5z"/>`
: `<path d="M225.8 468.2l-2.5-2.3L48.1 303.2C17.4 274.7 0 234.7 0 192.8v-3.3c0-70.4 50-130.8 119.2-144C158.6 37.9 198.9 47 231 69.6c9 6.4 17.4 13.8 25 22.3c4.2-4.8 8.7-9.2 13.5-13.3c3.7-3.2 7.5-6.2 11.5-9c0 0 0 0 0 0C313.1 47 353.4 37.9 392.8 45.4C462 58.6 512 119.1 512 189.5v3.3c0 41.9-17.4 81.9-48.1 110.4L288.7 465.9l-2.5 2.3c-8.2 7.6-19 11.9-30.2 11.9s-22-4.2-30.2-11.9zM239.1 145c-.4-.3-.7-.7-1-1.1l-17.8-20c0 0-.1-.1-.1-.1c0 0 0 0 0 0c-23.1-25.9-58-37.7-92-31.2C81.6 101.5 48 142.1 48 189.5v3.3c0 28.5 11.9 55.8 32.8 75.2L256 430.7 431.2 268c20.9-19.4 32.8-46.7 32.8-75.2v-3.3c0-47.3-33.6-88-80.1-96.9c-34-6.5-69 5.4-92 31.2c0 0 0 0-.1 .1s0 0-.1 .1l-17.8 20c-.3 .4-.7 .7-1 1.1c-4.5 4.5-10.6 7-16.9 7s-12.4-2.5-16.9-7z"/>`
}
</svg>
<span id="likeCount" class="index__message-item-footer-counter">${d.like}</span>
<span class="index__message-item-footer-date">${date.toLocaleString()}</span>
</div>
</ol>
`)
})
$(".index__message-item-footer-button").on('click', function (e) {
const id = this.id
const ids = JSON.parse(window.localStorage.getItem('ids')) || []
if (!ids.find((res)=> res == id)) {
ids.push(id)
localStorage.setItem('ids', JSON.stringify(ids));
updateLike(this.id)
}
})
}
});
$("#message").keydown(function (e) {
const message = $('#message').val()
if (e.keyCode==13){
if(message != ""){
sendMessage(message)
$('#message').val("")
}
e.preventDefault()
}
})
$("#sendMessageButton").click(function () {
const message = $('#message').val()
if(message != ""){
sendMessage(message)
$('#message').val("")
}
});
$("#refreshButton").click(function () {
location.reload()
});
})
</script>
<script type="text/javascript">
// functions
const enableAdemode = () => {
document.body.classList.add('ademo');
localStorage.setItem('ademo', 'enabled');
};
const disableAdemode = () => {
document.body.classList.remove('ademo');
localStorage.setItem('ademo', 'disabled');
};
// get localstorage
let ademode = localStorage.getItem("ademo");
if(ademode === "enabled"){
enableAdemode();
};
// add button toggler
const ademoToggler = document.querySelector("#ademo-toggler");
const zululuToggler = document.querySelector("#zululu-toggler");
ademoToggler.addEventListener("click", () => {
ademode = localStorage.getItem("ademo");
ademode === 'enabled' ? disableAdemode() : enableAdemode();
});
zululuToggler.addEventListener("click", () => {
ademode = localStorage.getItem("ademo");
ademode === 'enabled' ? disableAdemode() : enableAdemode();
});
</script>
</html>