Skip to content

Commit

Permalink
HAR-69: Сделал страницу 404 и добавил недостающие файлы к прошлому ко…
Browse files Browse the repository at this point in the history
…ммиту
  • Loading branch information
glebkos committed Apr 14, 2024
1 parent be3ce7b commit 48d3eb6
Show file tree
Hide file tree
Showing 19 changed files with 117 additions and 29 deletions.
2 changes: 1 addition & 1 deletion source/app/App.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {API} from '../shared/api/API.js';
import {Error} from '../components/pages/error/error.js';
import {Error} from '../pages/error/error.js';
import './styles/App.css';
import {Router} from './Router.js';
import {Profile} from '../pages/profile/ui/profile.js';
Expand Down
6 changes: 5 additions & 1 deletion source/app/Router.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {Error} from '../pages/error/error.js';

export class Router {
constructor() {
this.routes = [];
Expand Down Expand Up @@ -68,7 +70,9 @@ export class Router {
this.currentPage = reqRoute.view;
await reqRoute.view.render(...args);
} else {
//
const errorView = new Error();
this.currentPage = errorView;
errorView.render();
}
}

Expand Down
2 changes: 1 addition & 1 deletion source/app/styles/App.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import "../../components/pages/error/error.css";
@import "../../pages/error/error.css";

@import "button/button.css";
@import "input/input.css";
Expand Down
8 changes: 0 additions & 8 deletions source/components/pages/error/error.handlebars

This file was deleted.

12 changes: 0 additions & 12 deletions source/components/pages/error/error.js

This file was deleted.

4 changes: 4 additions & 0 deletions source/entity/boardPin/ui/boardPin.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<img src="{{ pin.content_url }}" alt="" class="pin" id="pin-{{ pin.pin_id }}">
{{#if owner}}
<button class="btn button-active board-pin__button" id="pin-del-{{pin.pin_id}}">Удалить</button>
{{/if}}
34 changes: 34 additions & 0 deletions source/entity/boardPin/ui/boardPin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {View} from '../../../app/View.js';
import BoardPinFeedTemplate from './boardPin.handlebars';
import './boardPin.scss';
import {API} from '../../../shared/api/API.js';

export class BoardPinFeedView extends View{
constructor(root, ...args) {
super(...args);
this.root = root;
}

onClick(pinID) {
window.location.pathname = '/pin/' + pinID;
}

render(pin, board) {
console.log(pin, board);
this.root.innerHTML = BoardPinFeedTemplate({pin, owner: board.is_owner});

const eventRoot = document.querySelector('#pin-' + pin.pin_id);
eventRoot.addEventListener('click', (event) => {
event.preventDefault();
this.onClick(pin.pin_id);
});

const delBtn = document.querySelector('#pin-del-' + pin.pin_id);
delBtn.addEventListener('click', async (event) => {
event.preventDefault();
const api = new API('/boards/' + board.board_id + '/pins/' + pin.pin_id);
await api.DELETE();
window.location.pathname = '/board/' + board.board_id;
})
}
}
6 changes: 6 additions & 0 deletions source/entity/boardPin/ui/boardPin.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.pin__hover-elem{
position: absolute;
background-color: var(--search-color);
width: 100%;
height: 100%;
}
3 changes: 3 additions & 0 deletions source/features/boardList/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {BoardListView} from './ui/boardList.js';

export {BoardListView};
6 changes: 6 additions & 0 deletions source/pages/board/ui/boardView.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {BoardAPI} from '../api/api.js';
import {Profile} from '../../profile/ui/profile.js';
import {BoardEdit} from '../../boardEdit/ui/boardEdit.js';
import {BoardFeedView} from '../../../widgets/boardFeed/ui/boardFeed.js';
import {Error} from '../../error/error.js';

/**
* Handle board page
Expand All @@ -28,6 +29,11 @@ export class BoardView extends View {
async render(boardID) {
const boardAPI = new BoardAPI(boardID);
const response = await boardAPI.api();
if (response.code !== 0){
const errorView = new Error();
errorView.render();
return;
}
const board = response.body.board;
this.root.innerHTML = boardViewTemplate({board});

Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions source/pages/error/error.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="error">
<div class="error_status">
404
</div>
<div class="error_description">
Страница не найдена
</div>
</div>
19 changes: 19 additions & 0 deletions source/pages/error/error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/** @module source/components/pages/error */

import templateError from './error.handlebars';
import {View} from '../../app/View.js';

/**
* Provides error view on site by rendering 'Handlebars.templates.error'.
* @function Error
*/
export class Error extends View{

constructor(...args) {
super(...args);
this.root = document.getElementById('root');
}
render() {
this.root.innerHTML = templateError({});
}
};
2 changes: 1 addition & 1 deletion source/pages/login/ui/loginView.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import loginTemplate from './loginView.handlebars'
import './loginView.scss';
import {View} from '../../../app/View.js';
import {emailValidation, passwordValidation} from '../../../shared/utils/validation.js';
import {Error} from '../../../components/pages/error/error.js';
import {Error} from '../../error/error.js';
import {ERROR_COLOR, errors} from '../../../shared/config.js';
import {LoginAPI} from '../api/api.js';
import {NavbarView} from '../../../widgets/navbar/ui/navbar.js';
Expand Down
6 changes: 6 additions & 0 deletions source/pages/pin/ui/pinView.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {PinAPI} from '../api/api.js';
import {Profile} from '../../profile/ui/profile.js';
import {ErrorWindowView} from '../../../entity/errorWindow/ui/errorWindow.js';
import {errors} from '../../../shared/config.js';
import {Error} from '../../error/error.js';

/**
* Handle pin page
Expand All @@ -31,6 +32,11 @@ export class PinView extends View {
async render(pinID) {
const pinAPI = new PinAPI(pinID);
const response = await pinAPI.api()
if (response.code !== 0){
const errorView = new Error();
errorView.render();
return;
}
const pin = response.body;

this.root.innerHTML = pinViewTemplate({pin});
Expand Down
6 changes: 6 additions & 0 deletions source/pages/profile/ui/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {ProfileAPI} from '../api/api.js';
import {ProfileEdit} from '../../profileEdit/ui/profileEdit.js';
import {PinView} from '../../pin/ui/pinView.js';
import {BoardEdit} from '../../boardEdit/ui/boardEdit.js';
import {Error} from '../../error/error.js';

/**
* Handle profile page
Expand All @@ -29,6 +30,11 @@ export class Profile extends View {
async render(nickname) {
const profileAPI = new ProfileAPI(nickname);
const response = await profileAPI.api();
if (response.code !== 0){
const errorView = new Error();
errorView.render();
return;
}
const user = response.body;
this.root.innerHTML = templateProfile();
this.profileUserInfo = new ProfileUserInfo();
Expand Down
12 changes: 12 additions & 0 deletions source/pages/signup/api/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {API} from '../../../shared/api/API.js';

export class SignupAPI extends API{
constructor(...args) {
const url = '/users';
super(url, ...args);
}

async registerRequest(post){
return await super.POST(JSON.stringify(post));
}
}
2 changes: 1 addition & 1 deletion source/pages/signup/ui/signupView.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import signupTemplate from './signupView.handlebars';
import './signupView.scss';
import {debounce} from '../../../shared/utils/debounce.js';
import {debounceTimeout, ERROR_COLOR, errors} from '../../../shared/config.js';
import {Error} from '../../../components/pages/error/error.js';
import {Error} from '../../error/error.js';
import {NavbarView} from '../../../widgets/navbar/ui/navbar.js';
import {SignupAPI} from '../api/api.js';

Expand Down
8 changes: 4 additions & 4 deletions source/widgets/navbar/ui/navbar.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
</div>
<div class="navbar_right-block" id="navbar_login_menu">
{{#if user}}
<div class="primary-btn btn" id="navbar-user-name">{{ user.nickname }}</div>
<button class="secondary-btn btn" id="navbar_logout_button">Выход</button>
<button class="button-active btn" id="navbar-user-name">{{ user.nickname }}</button>
<button class="button-passive btn" id="navbar_logout_button">Выход</button>
{{else}}
<button class="primary-btn btn" id="navbar_login_button">Войти</button>
<button class="secondary-btn btn" id="navbar_signup_button">Регистрация</button>
<button class="button-active btn" id="navbar_login_button">Войти</button>
<button class="button-passive btn" id="navbar_signup_button">Регистрация</button>
{{/if}}
</div>
</div>
Expand Down

0 comments on commit 48d3eb6

Please sign in to comment.