Skip to content

Commit

Permalink
im getting tired
Browse files Browse the repository at this point in the history
  • Loading branch information
rasulov1337 committed Dec 20, 2024
1 parent 9496f66 commit 365e236
Showing 1 changed file with 17 additions and 29 deletions.
46 changes: 17 additions & 29 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

import Header from './components/Header/Header';
import AuthPopup from './components/AuthPopup/AuthPopup';

import MainPage from './pages/MainPage/MainPage';
import ProfilePage from './pages/ProfilePage/ProfilePage';
Expand Down Expand Up @@ -50,14 +49,16 @@ const renderFavoritesPage = () => {
favouritePage.render(pageContainer);
};

const renderNotificationsPage = () => {};

const renderAdvertPage = async (id: string) => {
const info = await ApiClient.getAd(id);
const authorInfo = await ApiClient.getUser(info.authorUUID);
try {
const info = await ApiClient.getAd(id);
const authorInfo = await ApiClient.getUser(info.authorUUID);

const page = new AdPage(pageContainer, info, authorInfo);
page.render();
const page = new AdPage(pageContainer, info, authorInfo);
page.render();
} catch {
router.navigateTo('/404');
}
};

const renderEditAdvertPage = async (uuid: string) => {
Expand All @@ -72,27 +73,21 @@ const renderCreateAdvertPage = async () => {
pageContainer.appendChild(page.getElement());
};

const renderSignInPage = () => {
const auth = new AuthPopup();
auth.render(root);
};

const renderProfilePage = async () => {
clearPage('main-photo', 'main-content');
const profilePage = new ProfilePage();
await profilePage.render(pageContainer);
};

const renderAdListPage = async (action: 'edit' | undefined, adId: string) => {
const sessionData = await APIService.getSessionData();
const userId = sessionData['id'];
const isHost = (await ApiClient.getUser(userId))['isHost'];
if (!userId) {
console.error('There is no userId in local storage!');
return;
if (!globalStore.auth.isAuthorized) {
router.navigateTo('/403');
}

let data = await ApiClient.getAdsOfUser(userId);
const isHost = (await ApiClient.getUser(globalStore.auth.userId!))[
'isHost'
];
let data = await ApiClient.getAdsOfUser(globalStore.auth.userId!);
if (!('places' in data)) {
data = [];
} else {
Expand Down Expand Up @@ -122,13 +117,6 @@ const renderAdListPage = async (action: 'edit' | undefined, adId: string) => {
}
};

/** Объект с коллбеками для header`а */
const headerCallbacks = {
favoritesPage: renderFavoritesPage,
notificationsPage: renderNotificationsPage,
signInPage: renderSignInPage,
};

const renderHeader = async () => {
document.getElementById('header')?.remove();

Expand All @@ -142,8 +130,8 @@ const renderHeader = async () => {
globalStore.auth.isAuthorized = false;
}

const header = new Header(headerCallbacks, sessionData ? true : false);
root.prepend(header.getElement());
const header = new Header(root, sessionData);
header.render('afterbegin');
};

router.addRoute('/', async () => {
Expand Down Expand Up @@ -205,7 +193,7 @@ router.addRoute('/payment', async (params: URLSearchParams) => {
const adId = params.get('adId');

if (!adId) {
router.navigateTo('/'); // TODO: Maybe 404 / 403 / 400?
router.navigateTo('/404');
return;
}

Expand Down

0 comments on commit 365e236

Please sign in to comment.