Skip to content

Commit d42c82c

Browse files
authored
Merge pull request ricklamers#51 from Jerry-523/main
Added double confirmation when deleting conversation.
2 parents 93a2b9b + 1da4d8e commit d42c82c

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ working again ; )
22
I am very busy at the moment so I would be very thankful for contributions and PR's
33

44
## To do
5-
- [ ] Double confirm when deleting conversation
5+
- [x] Double confirm when deleting conversation
66
- [ ] loading / exporting a conversation
77
- [x] remember user preferences
88
- [ ] theme changer

client/js/chat.js

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,32 @@ const clear_conversation = async () => {
244244
}
245245
};
246246

247+
const show_option = async (conversation_id) => {
248+
const conv = document.getElementById(`conv-${conversation_id}`);
249+
const yes = document.getElementById(`yes-${conversation_id}`);
250+
const not = document.getElementById(`not-${conversation_id}`);
251+
252+
conv.style.display = "none";
253+
yes.style.display = "block";
254+
not.style.display = "block";
255+
}
256+
257+
const hide_option = async (conversation_id) => {
258+
const conv = document.getElementById(`conv-${conversation_id}`);
259+
const yes = document.getElementById(`yes-${conversation_id}`);
260+
const not = document.getElementById(`not-${conversation_id}`);
261+
262+
conv.style.display = "block";
263+
yes.style.display = "none";
264+
not.style.display = "none";
265+
}
266+
247267
const delete_conversation = async (conversation_id) => {
248268
localStorage.removeItem(`conversation:${conversation_id}`);
249269

270+
const conversation = document.getElementById(`convo-${conversation_id}`);
271+
conversation.remove();
272+
250273
if (window.conversation_id == conversation_id) {
251274
await new_conversation();
252275
}
@@ -363,14 +386,16 @@ const load_conversations = async (limit, offset, loader) => {
363386

364387
for (conversation of conversations) {
365388
box_conversations.innerHTML += `
366-
<div class="convo">
367-
<div class="left" onclick="set_conversation('${conversation.id}')">
368-
<i class="fa-regular fa-comments"></i>
369-
<span class="convo-title">${conversation.title}</span>
370-
</div>
371-
<i onclick="delete_conversation('${conversation.id}')" class="fa-regular fa-trash"></i>
372-
</div>
373-
`;
389+
<div class="convo" id="convo-${conversation.id}">
390+
<div class="left" onclick="set_conversation('${conversation.id}')">
391+
<i class="fa-regular fa-comments"></i>
392+
<span class="convo-title">${conversation.title}</span>
393+
</div>
394+
<i onclick="show_option('${conversation.id}')" class="fa-regular fa-trash" id="conv-${conversation.id}"></i>
395+
<i onclick="delete_conversation('${conversation.id}')" class="fa-regular fa-check" id="yes-${conversation.id}" style="display:none;"></i>
396+
<i onclick="hide_option('${conversation.id}')" class="fa-regular fa-x" id="not-${conversation.id}" style="display:none;"></i>
397+
</div>
398+
`;
374399
}
375400

376401
document.querySelectorAll(`code`).forEach((el) => {

0 commit comments

Comments
 (0)