Skip to content

Commit

Permalink
Add jsdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
AshurovG committed Sep 26, 2024
1 parent 0494157 commit 7c5c655
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 0 deletions.
22 changes: 22 additions & 0 deletions public/components/AuthForm/AuthForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ export class AuthForm {
return this.#config;
}

/**
* Authorization fields validation
* @param {string} emailValue - email value entered by user
* @param {string} passwordValue - password value entered by user
* @returns {boolean} - true if the entered fields are valid
*/
validateFormFields(emailValue, passwordValue) {
const emailInput = document.getElementById('form-auth-email');
const passwordInput = document.getElementById('form-auth-password');
Expand All @@ -43,13 +49,24 @@ export class AuthForm {
}
}

/**
* Send authorization request
* @param {string} emailValue - email value entered by user
* @param {string} passwordValue - password value entered by user
* @returns {}
*/
async authRequest(emailValue, passwordValue) {
const response = await apiClient.post({
path: 'tasks',
body: { email: emailValue, password: passwordValue },
});
}

/**
* Processing of clicking on the authorization button
* @param {}
* @returns {}
*/
onAuthButtonClick() {
const authBtn = document.getElementById('form-auth-btn');
authBtn.addEventListener('click', async (e) => {
Expand All @@ -65,6 +82,11 @@ export class AuthForm {
});
}

/**
* Navigate to registration
* @param {}
* @returns {}
*/
handleRegLinkClick() {
const regLink = document.getElementById('form-auth-reg-link');
regLink.addEventListener('click', (e) => {
Expand Down
5 changes: 5 additions & 0 deletions public/components/ConfirmModal/ConfirmModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export class ConfirmModal {
});
}

/**
* Hide modal window
* @param {}
* @returns {}
*/
hideModal() {
const root = document.getElementById('root');
const modal = document.getElementById('modal');
Expand Down
5 changes: 5 additions & 0 deletions public/components/GridBlock/GridBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export class GridBlock {
return this.#movies.slice(0, 3);
}

/**
* Navigate to category page
* @param {}
* @returns {}
*/
onMoreClick() {
const more = document.getElementById('grid-block-header-more');
const main = document.querySelector('main');
Expand Down
5 changes: 5 additions & 0 deletions public/components/Loader/Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export class Loader {
this.#parent.innerHTML = template();
}

/**
* Delete loader from page and show loaded page
* @param {}
* @returns {}
*/
kill() {
this.#parent.innerHTML = this.#element;
}
Expand Down
26 changes: 26 additions & 0 deletions public/components/RegForm/RegForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ export class RegForm {
return this.#config;
}

/**
* Registration fields validation
* @param {string} loginValue - login value entered by user
* @param {string} emailValue - email value entered by user
* @param {string} passwordValue - password value entered by user
* @param {string} passwordConfirmInput - password confirmation value entered by user
* @returns {boolean} - true if the entered fields are valid
*/
validateFormFields(loginValue, emailValue, passwordValue, confirmValue) {
const emailInput = document.getElementById('form-reg-email');
const loginInput = document.getElementById('form-reg-login');
Expand Down Expand Up @@ -67,6 +75,14 @@ export class RegForm {
}
}

/**
* Send registration request
* @param {string} loginValue - login value entered by user
* @param {string} emailValue - email value entered by user
* @param {string} passwordValue - password value entered by user
* @param {string} passwordConfirmInput - password confirmation value entered by user
* @returns {}
*/
async regRequest(loginValue, emailValue, passwordValue, confirmValue) {
const response = await apiClient.post({
path: 'tasks',
Expand All @@ -79,6 +95,11 @@ export class RegForm {
});
}

/**
* Processing of clicking on the registration button
* @param {}
* @returns {}
*/
onRegButtonClick() {
const regBtn = document.getElementById('form-reg-btn');
regBtn.addEventListener('click', async (e) => {
Expand All @@ -105,6 +126,11 @@ export class RegForm {
});
}

/**
* Navigate to authorization
* @param {}
* @returns {}
*/
handleAuthLinkClick() {
const authLink = document.getElementById('form-reg-auth-link');
authLink.addEventListener('click', (e) => {
Expand Down
5 changes: 5 additions & 0 deletions public/components/Slider/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export class Slider {
this.renderTemplate();
}

/**
* checking the slider's boundary values
* @param {}
* @returns {}
*/
checkBtns() {
const btnNext = document.getElementById('slider-btn-next');
const btnPrev = document.getElementById('slider-btn-prev');
Expand Down
44 changes: 44 additions & 0 deletions public/modules/ApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ const HTTP_METHOD_PUT = 'PUT';
const HTTP_METHOD_DELETE = 'DELETE';

class ApiClient {
/**
* GET request
* @param {Object} params - request parameters
* @param {string} params.path - API endpoint path
* @param {number} params.id - item ID (optional)
* @returns {Promise<Object>} - response from the API
* @throws {Error} - if the request fails
*/
get({ path, id }) {
return this._apiClient({
method: HTTP_METHOD_GET,
Expand All @@ -14,6 +22,14 @@ class ApiClient {
});
}

/**
* POST request
* @param {Object} params - request parameters
* @param {string} params.path - API endpoint path
* @param {Object} params.body - request payload (data to be sent)
* @returns {Promise<Object>} - response from the API
* @throws {Error} - if the request fails
*/
post({ path, body }) {
return this._apiClient({
method: HTTP_METHOD_POST,
Expand All @@ -22,6 +38,15 @@ class ApiClient {
});
}

/**
* PUT request
* @param {Object} params - request parameters
* @param {string} params.path - API endpoint path
* @param {number|string} params.id - item ID to update
* @param {Object} params.body - request payload (data to be updated)
* @returns {Promise<Object>} - response from the API
* @throws {Error} - if the request fails
*/
put({ path, id, body }) {
return this._apiClient({
method: HTTP_METHOD_PUT,
Expand All @@ -31,6 +56,14 @@ class ApiClient {
});
}

/**
* DELETE request
* @param {Object} params - request parameters
* @param {string} params.path - API endpoint path
* @param {number|string} params.id - item ID to delete
* @returns {Promise<Object>} - response from the API
* @throws {Error} - if the request fails
*/
delete({ path, id }) {
return this._apiClient({
method: HTTP_METHOD_DELETE,
Expand All @@ -39,6 +72,17 @@ class ApiClient {
});
}

/**
* Send request to API
* @param {Object} params - request parameters
* @param {string} params.method - HTTP method (GET, POST, PUT, DELETE)
* @param {string} params.path - API endpoint path
* @param {number|string} [params.id=null] - item ID (optional)
* @param {Object} [params.body=null] - request payload (optional)
* @returns {Promise<Object>} - response from the API
* @throws {Error} - if the request fails
* @private
*/
async _apiClient({ method, path, id = null, body = null }) {
const url = API_URL + path + (id ? `/${id}` : '');
const response = await fetch(url, {
Expand Down
15 changes: 15 additions & 0 deletions public/modules/Validators.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* Email validation
* @param {string} emailAddress - email value
* @returns {boolean} - true if email value is valid
*/
export function validateEmailAddress(emailAddress) {
let atSymbol = emailAddress.indexOf('@');
let dotSymbol = emailAddress.lastIndexOf('.');
Expand All @@ -20,6 +25,11 @@ export function validateEmailAddress(emailAddress) {
}
}

/**
* Password validation
* @param {string} password - password value
* @returns {boolean} - true if password value is valid
*/
export function validatePassword(password) {
if (password.length < 8) {
return false;
Expand All @@ -37,6 +47,11 @@ export function validatePassword(password) {
}

// TODO: уточнить (сейчас проверяем на длину, только англ символы и разрешение .)
/**
* Login validation
* @param {string} username - username value
* @returns {boolean} - true if username value is valid
*/
export function validateLogin(username) {
if (username.length <= 5) {
return false;
Expand Down
10 changes: 10 additions & 0 deletions public/pages/CategoryPage/CategoryPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export class CategoryPage {
return this.#movies.slice(0, 3);
}

/**
* Send get movies from category request
* @param {}
* @returns {}
*/
async getCategoryMovies() {
const response = await apiClient.get({
path: 'movies',
Expand All @@ -32,6 +37,11 @@ export class CategoryPage {
moviesList.render();
}

/**
* Navigate to previous page
* @param {}
* @returns {}
*/
goBack() {
const backButton = document.getElementById('category-page-button-back');
const main = document.querySelector('main');
Expand Down
5 changes: 5 additions & 0 deletions public/pages/MainPage/MainPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ export class MainPage {
this.#newMovies = response;
}

/**
* Render movies blocks
* @param {}
* @returns {}
*/
async renderBlocks() {
await Promise.all([
this.getTrendMovies(),
Expand Down

0 comments on commit 7c5c655

Please sign in to comment.