-
Notifications
You must be signed in to change notification settings - Fork 1
/
render-function.js
80 lines (53 loc) · 2.09 KB
/
render-function.js
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
export function renderAllUsers(user) {
const a = document.createElement('a');
a.href = `../pawfile-users/detail-page/?user_id=${user.user_id}`;
const userEl = document.createElement('div');
userEl.classList.add('user-div');
const nameEl = document.createElement('p');
nameEl.classList.add('name-tag');
nameEl.textContent = user.name;
const imgEl = document.createElement('img');
imgEl.classList.add('img-tag');
imgEl.src = user.image_url;
userEl.append(nameEl, imgEl);
a.append(userEl);
return a;
}
export function renderMessage(comment, user, currentUser) {
const dogChat = document.createElement('div');
dogChat.classList.add('div-container');
const userContainer = document.createElement('div');
userContainer.classList.add('user-container');
if (user.user_id === currentUser.id) {
dogChat.classList.add('your-message');
}
const avatarEl = document.createElement('img');
avatarEl.classList.add('avatar-class');
avatarEl.src = user.image_url;
const dogNameEl = document.createElement('p');
dogNameEl.classList.add('username');
dogNameEl.textContent = `${user.name}`;
const commentP = document.createElement('p');
commentP.classList.add('commentP');
if (comment) {
commentP.innerHTML = comment.replace(/(http|https|ftp):\/\/(\S*)/g, match => `<a target = "_blank" href = "${match}">${match}</a> `);
}
userContainer.append(avatarEl, dogNameEl);
dogChat.append(userContainer, commentP);
return dogChat;
}
export function renderSingleUser(user) {
const userEl = document.createElement('div');
userEl.classList.add('user-div');
const nameEl = document.createElement('p');
nameEl.classList.add('name-tag');
nameEl.textContent = user.name;
const imgEl = document.createElement('img');
imgEl.classList.add('img-tag');
imgEl.src = user.image_url;
const bioEl = document.createElement('p');
bioEl.classList.add('bio-tag');
bioEl.textContent = user.bio;
userEl.append(nameEl, imgEl, bioEl);
return userEl;
}