Skip to content

Instantly share code, notes, and snippets.

View hieptl's full-sized avatar
🎯
Focusing

Hiep Le hieptl

🎯
Focusing
View GitHub Profile
@hieptl
hieptl / requests.js
Last active October 13, 2021 06:52
requests.js - API - Creating a New Matching Request - Tinder Clone
app.post("/requests/create", (req, res) => {
const { matchRequestFrom, matchRequestTo, matchRequestSender, matchRequestReceiver } = req.body;
if (matchRequestFrom && matchRequestTo && matchRequestSender && matchRequestReceiver) {
// check the request existed in the database or not.
const sql = "SELECT * FROM match_request WHERE match_request_from = ? AND match_request_to = ?";
dbConn.query(sql, [matchRequestFrom, matchRequestTo], function (err, result) {
if (err) {
res.status(200).jsonp({ message: "The system error. Please try again" });
} else if (result && result.length !== 0) {
res.status(200).jsonp({ message: "The match request existed in the system." });
@hieptl
hieptl / requests.js
Created September 28, 2021 06:42
requests.js - API - Get the List of Matching Requests - Tinder Clone
app.post("/requests/get", (req, res) => {
const { ccUid } = req.body;
const sql = "SELECT * FROM match_request WHERE match_request_from = ? || match_request_to = ?";
dbConn.query(sql, [ccUid, ccUid], function (err, result) {
if (err) {
res.status(200).jsonp({ message: 'Cannot get the list of match requests' });
} else {
res.status(200).jsonp(result);
}
});
@hieptl
hieptl / requests.js
Created September 28, 2021 08:07
requests.js - API - Update Matching Request - Tinder Clone
const getUpdateRequest = (id, status) => {
if (status && status === constants.matchRequestStatus.accepted) {
return {
payload: [status, new Date(), id],
sql: "UPDATE match_request SET match_request_status = ?, accepted_date = ? WHERE id = ?"
};
}
return {
payload: [status, id],
sql: "UPDATE match_request SET match_request_status = ? WHERE id = ?"
@hieptl
hieptl / login.html
Created September 28, 2021 09:04
login.html - Tinder Clone
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Login</title>
<link rel="stylesheet" href="/css/styles.css" />
<script
defer
@hieptl
hieptl / auth.js
Created September 28, 2021 09:13
auth.js - Client Side - Tinder Clone
window.addEventListener("DOMContentLoaded", function () {
function shouldRedirectToHomePage(user, isLoginPage) {
return user && isLoginPage;
}
function shouldRedirectToLoginPage(user, isLoginPage) {
return !user && !isLoginPage;
}
const authenticatedUser = JSON.parse(localStorage.getItem("auth"));
@hieptl
hieptl / util.js
Created September 28, 2021 09:18
util.js - Client Side - Tinder Clone
const loading = document.getElementById('loading');
function hideLoading() {
loading.classList.add('loading--hide');
}
function showLoading() {
loading.classList.remove('loading--hide');
loading.classList.add('loading--active');
}
@hieptl
hieptl / login.js
Created September 28, 2021 11:49
login.js - Register New Account - Tinder Clone
const registerNewAccount = ({ avatar, email, password, fullname, age, gender }) => {
showLoading();
const userUuid = uuid.v4();
const form = new FormData();
form.append("avatar", avatar);
form.append("email", email);
form.append("password", password);
form.append("age", age);
form.append("gender", gender);
form.append("ccUid", userUuid);
@hieptl
hieptl / login.js
Created September 28, 2021 11:51
login.js - Login Client Side - Tinder Clone
loginBtn.addEventListener("click", function () {
// show loading indicator.
showLoading();
// get input user's credentials.
const email = emailLoginInputElement ? emailLoginInputElement.value : null;
const password = passwordLoginInputElement ? passwordLoginInputElement.value : null;
if (isUserCredentialsValid({ email, password })) {
axios
.post("/login", { email, password })
.then((res) => {
@hieptl
hieptl / index.html
Last active October 8, 2021 04:45
index.html - Client Side - Tinder Clone
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tinder Clone - CometChat JS SDK</title>
<link rel="stylesheet" href="/css/styles.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css">
</head>
@hieptl
hieptl / index.js
Created September 28, 2021 12:53
index.js - Client Side - Header - Tinder Clone
window.addEventListener("DOMContentLoaded", function () {
...
// set header information
const authenticatedUser = JSON.parse(localStorage.getItem("auth"));
if (authenticatedUser) {
...
// show authenticated user on the header.
const headerRight = document.getElementById("header__right");
const userImage = document.getElementById("user__image");
const userName = document.getElementById("user__name");