Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions submissions/Serge044/FriendsApp/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Friends App</title>
<meta
name="viewport"
content="width=device-width, initial-scale=1.0"/>
<link rel="shortcut icon" href="images/favicon.png">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="wrapper">
<div class="page">
<div class="page__container">
<div class="page__header">
<h1 class="page__title">Friends App</h1>
<div class="page__action">
<button id="btn" type="button" class="page__theme"></button>
<button id="btn2" type="button" class="page__reset"></button>
</div>
</div>
<div class="page__content">
<div id="result"></div>
<div class="menu-sort">

<div class="bullet-sort">
<p class="icons"> sort-by-age </p>
<button class="btn_sort">0 - 99</button>
<button class="btn_sort">99 - 0</button>
</div>


<div class="bullet-sort">
<p class="icons"> sort-by-name </p>
<button class="btn_sort">A - Z</button>
<button class="btn_sort">Z - A</button>
</div>

<div class="bullet-sort">
<p class="icons"> sort-by-sex </p>
<button class="btn_sort">M</button>
<button class="btn_sort">W</button>
<button class="btn_sort">all</button>
</div>

<div class="bullet-sort">
<button class="btn_sort-reset">Reset</button>
</div>

</div>
</div>
</div>
</div>
</div>

<script type="module" src="script.js"></script>
</body>
</html>
115 changes: 115 additions & 0 deletions submissions/Serge044/FriendsApp/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
window.addEventListener("load", windowLoad);

function windowLoad() {
//HTML
const htmlBlock = document.documentElement;

// get saved theme
const saveUserTheme = localStorage.getItem("user-theme");

// work with system configurations
let userTheme;
if (window.matchMedia) {
userTheme = window.matchMedia("(prefers-color-scheme: dark)").matches
? "dark"
: "light";
}
window
.matchMedia("(prefers-color-scheme: dark)")
.addEventListener("change", (e) => {
!saveUserTheme ? changeTheme() : null;
});

// change theme by click
const themeButton = document.querySelector(".page__theme");
const resetButton = document.querySelector(".page__reset");
if (themeButton) {
themeButton.addEventListener("click", function (e) {
resetButton.classList.add("active");
changeTheme(true);
});
}
if (resetButton) {
resetButton.addEventListener("click", function (e) {
resetButton.classList.remove("active");
localStorage.setItem("user-theme", "");
});
}

// function add theme class
function setThemeClass() {
if (saveUserTheme) {
htmlBlock.classList.add(saveUserTheme);
resetButton.classList.add("active");
} else {
htmlBlock.classList.add(userTheme);
}
}
// add theme class
setThemeClass();

// function change theme
function changeTheme(saveTheme = false) {
let currentTheme = htmlBlock.classList.contains("light") ? "light" : "dark";
let newTheme;

if (currentTheme === "light") {
newTheme = "dark";
} else if (currentTheme === "dark") {
newTheme = "light";
}
htmlBlock.classList.remove(currentTheme);
htmlBlock.classList.add(newTheme);
saveTheme ? localStorage.setItem("user-theme", newTheme) : null;
}
}

// get 10 cards
fetch("https://randomuser.me/api/?results=10")
.then((res) => res.json())
.then((data) => {
let cards = data.results;

let result = "";

cards.forEach(function (lists) {
result += `
<div>
<div class="friend-card">
<div class="card-top">
<div><img src="${lists.picture.large}"></div>
<div class="bullet">
<div id="name"> ${lists.name.first} ${lists.name.last}</div>
<div>${lists.gender}</div>
</div>
</div>

<div class="card-bottom">

<div class="bullet">
<p class="icons"> age-image: </p>
<div id="age">${lists.dob.age}</div>
</div>

<div class="bullet">
<p class="icons"> location-image: </p>
<div id="location">${lists.location.city}, ${lists.location.country}</div>
</div>

<div class="bullet">
<p class="icons"> phone-image: </p>
<div id="phone">${lists.cell}</div>
</div>

<div class="bullet">
<p class="icons"> email-image: </p>
<div>${lists.email}</div>
</div>

</div>
</div>
</div> `;
});

document.getElementById("result").innerHTML = result;
});
Loading