georgiev955

Locked Profile

Nov 2nd, 2023
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. async function lockedProfile() {
  2.     const response = await fetch('http://localhost:3030/jsonstore/advanced/profiles');
  3.     const users = await response.json();
  4.     document.querySelector('.profile').remove();
  5.    
  6.     for (const user in users) {
  7.         const id = users[user]._id;
  8.         const username = users[user].username;
  9.         const email = users[user].email;
  10.         const age = users[user].age;
  11.         console.log(age);
  12.  
  13.         const personProfile = document.createElement('div');
  14.         personProfile.classList.add('profile');
  15.         personProfile.innerHTML = `
  16.                 <img src="./iconProfile2.png" class="userIcon">
  17.                 <label>Lock</label>
  18.                 <input type="radio" name="${id}" value="lock" checked>
  19.                 <label>Unlock</label>
  20.                 <input type="radio" name="${id}" value="unlock"><br>
  21.                 <hr>
  22.                 <label>Username</label>
  23.                 <input type="text" name="user1Username" value="${username}" disabled="" readonly="">
  24.                 <div class="user1Username">
  25.                     <hr>
  26.                     <label>Email:</label>
  27.                     <input type="email" name="user1Email" value="${email}" disabled="" readonly="">
  28.                     <label>Age:</label>
  29.                     <input type="email" name="user1Age" value="${age}" disabled="" readonly="">
  30.                 </div>
  31.                 <button>Show more</button>
  32.         `
  33.         document.getElementById('main').appendChild(personProfile);
  34.     }
  35.     const extraInfo = Array.from(document.querySelectorAll('.user1Username'));
  36.     extraInfo.forEach(person => person.style.display = "none");
  37.    
  38.  
  39.     const showMoreBtns = document.querySelectorAll('button');
  40.     showMoreBtns.forEach(button => button.addEventListener('click', showInfo));
  41.  
  42.     function showInfo(e) {
  43.         const target = e.target.parentElement.children[9];
  44.         const lockRadio = e.target.parentElement.children[2];
  45.         const unlockRadio = e.target.parentElement.children[4];
  46.  
  47.         if (e.target.textContent === 'Hide it') {
  48.             if (lockRadio.checked === true) {
  49.                 return;
  50.             } else {
  51.                 target.style.display = 'none';
  52.                 e.target.textContent = 'Show more';
  53.                 return;
  54.             }
  55.         }
  56.  
  57.         if (lockRadio.checked === true) {
  58.             return;
  59.         } else {
  60.             target.style.display = '';
  61.             e.target.textContent = 'Hide it';
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment