File size: 3,806 Bytes
ec4fcc3
 
 
 
 
 
48f798b
ec4fcc3
 
 
4589b25
48f798b
 
ec4fcc3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4589b25
 
ec4fcc3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
class CustomCommentsSection extends HTMLElement {
  connectedCallback() {
    this.attachShadow({ mode: 'open' });
    this.shadowRoot.innerHTML = `
      <style>
        .comments-section {
          background: linear-gradient(135deg, #3b5998 0%, #2c3e50 100%);
          padding: 20px;
          border-radius: 10px;
          margin-top: 20px;
          color: #00ff00;
        }
.comments-header {
          font-size: 1.2rem;
          margin-bottom: 15px;
          padding-bottom: 5px;
          border-bottom: 1px solid #3b5998;
        }
        .comment-form textarea {
          width: 100%;
          padding: 10px;
          margin-bottom: 10px;
          border-radius: 5px;
          border: 1px solid #ccc;
          background: rgba(255,255,255,0.9);
        }
        .comment-form button {
          background: #3b5998;
          color: white;
          border: none;
          padding: 8px 15px;
          border-radius: 5px;
          cursor: pointer;
        }
        .comments-list {
          margin-top: 20px;
        }
        .comment {
          display: flex;
          margin-bottom: 15px;
          padding-bottom: 15px;
          border-bottom: 1px solid rgba(255,255,255,0.1);
        }
        .comment-avatar {
          width: 40px;
          height: 40px;
          border-radius: 50%;
          margin-right: 10px;
        }
        .comment-content {
          flex: 1;
        }
        .comment-author {
          font-weight: bold;
          margin-bottom: 5px;
        }
        .comment-date {
          font-size: 0.8rem;
          color: #00ff00;
margin-bottom: 5px;
        }
        .comment-text {
          line-height: 1.4;
        }
      </style>
      <div class="comments-section">
        <div class="comments-header">Comments</div>
        
        <div class="comment-form">
          <textarea placeholder="Write a comment..." rows="3"></textarea>
          <button>Post Comment</button>
        </div>
        
        <div class="comments-list">
          <div class="comment">
            <img src="http://static.photos/people/200x200/2" class="comment-avatar">
            <div class="comment-content">
              <div class="comment-author">Tom Anderson</div>
              <div class="comment-date">2 days ago</div>
              <div class="comment-text">Welcome to MySpace! This is going to be awesome!</div>
            </div>
          </div>
          <div class="comment">
            <img src="http://static.photos/people/200x200/3" class="comment-avatar">
            <div class="comment-content">
              <div class="comment-author">Chris DeWolfe</div>
              <div class="comment-date">1 day ago</div>
              <div class="comment-text">Great profile! Check out the new features we added!</div>
            </div>
          </div>
        </div>
      </div>
    `;

    // Comment form submission
    this.shadowRoot.querySelector('.comment-form button').addEventListener('click', () => {
      const text = this.shadowRoot.querySelector('.comment-form textarea').value;
      if (text.trim()) {
        const comment = document.createElement('div');
        comment.className = 'comment';
        comment.innerHTML = `
          <img src="http://static.photos/people/200x200/${Math.floor(Math.random()*10)+1}" class="comment-avatar">
          <div class="comment-content">
            <div class="comment-author">New User</div>
            <div class="comment-date">Just now</div>
            <div class="comment-text">${text}</div>
          </div>
        `;
        this.shadowRoot.querySelector('.comments-list').prepend(comment);
        this.shadowRoot.querySelector('.comment-form textarea').value = '';
      }
    });
  }
}
customElements.define('custom-comments-section', CustomCommentsSection);