Skip to content

Commit

Permalink
Add map and delete button
Browse files Browse the repository at this point in the history
  • Loading branch information
FireSpirit171 committed Dec 14, 2024
1 parent 559efd9 commit 1c6583b
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 27 deletions.
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ router.addRoute('/profile', async () => {
});

router.addRoute('/map', async () => {
await renderMapPage();
renderMapPage();
});

router.addRoute('/favorites', async () => {
renderFavoritesPage();
});

router.addRoute('/ads/', async (params: URLSearchParams) => {
Expand Down
12 changes: 6 additions & 6 deletions src/pages/FavouritePage/FavouritePage.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
<img src="{{images.[0].path}}" alt="{{address}}">
</div>
<div class="favourite-card__details">
<span class="favourite-card__title js-favourite-card-link">
{{cityName}}, {{address}}
</span>
<span class="favourite-card__title js-favourite-card-link">{{cityName}}, {{address}}</span>
<div class="favourite-card__info">
{{description}}
</div>
<div class="favourite-card__actions">
<button class="favourite-card__actions__chat js-favourite-card-chat">Напишите {{adAuthor.name}}</button>
<button class="favourite-card__actions__map js-favourite-card-map">
<img src="/earth.svg" height="20" width="20">
</button>
<a href="?={{id}}">
<button class="favourite-card__actions__map js-favourite-card-map">
<img src="/earth.svg" height="20" width="20">
</button>
</a>
<button class="favourite-card__actions__remove js-favourite-card-remove">
<img src="/delete-basket.svg" height="20" width="20">
</button>
Expand Down
21 changes: 18 additions & 3 deletions src/pages/FavouritePage/FavouritePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import { AdvertData } from "../../modules/Types";

Check failure on line 3 in src/pages/FavouritePage/FavouritePage.ts

View workflow job for this annotation

GitHub Actions / Run linters

Strings must use singlequote
import ApiClient from "../../modules/ApiClient";

Check failure on line 4 in src/pages/FavouritePage/FavouritePage.ts

View workflow job for this annotation

GitHub Actions / Run linters

Strings must use singlequote
import MapPage from "../MapPage/MapPage";

Check failure on line 5 in src/pages/FavouritePage/FavouritePage.ts

View workflow job for this annotation

GitHub Actions / Run linters

Strings must use singlequote

import router from "../../modules/Router";

Check failure on line 7 in src/pages/FavouritePage/FavouritePage.ts

View workflow job for this annotation

GitHub Actions / Run linters

Strings must use singlequote

class FavouritePage {
#favourites: AdvertData;
#parent?: HTMLDivElement;

constructor(){}

Expand All @@ -27,15 +29,28 @@ class FavouritePage {
link.onclick = () => {
router.navigateTo(`/ads/?id=${card.id}`);
}

Check failure on line 31 in src/pages/FavouritePage/FavouritePage.ts

View workflow job for this annotation

GitHub Actions / Run linters

Missing semicolon

const mapButton: HTMLButtonElement = card.querySelector('.js-favourite-card-map')!;
mapButton.onclick = () => {
const mapPage = new MapPage(link.innerHTML);
mapPage.render(this.#parent);
}

Check failure on line 37 in src/pages/FavouritePage/FavouritePage.ts

View workflow job for this annotation

GitHub Actions / Run linters

Missing semicolon

const deleteButton: HTMLButtonElement = card.querySelector('.js-favourite-card-remove')!;
deleteButton.onclick = async () => {
await ApiClient.removeFromFavourites(card.id);
this.render();
}

Check failure on line 43 in src/pages/FavouritePage/FavouritePage.ts

View workflow job for this annotation

GitHub Actions / Run linters

Missing semicolon
}
}

async render(parent: HTMLElement): Promise<void> {
async render(parent?: HTMLDivElement): Promise<void> {
await this.#getFavourites();
if (parent) this.#parent = parent;

const template = Handlebars.templates['FavouritePage.hbs'];
parent.replaceChildren();
parent.insertAdjacentHTML('afterbegin', template(this.#favourites));
this.#parent!.replaceChildren();
this.#parent!.insertAdjacentHTML('afterbegin', template(this.#favourites));

await this.#addEventListeners();
}
Expand Down
70 changes: 53 additions & 17 deletions src/pages/MapPage/MapPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@ interface Limit {

class MapPage {
#map;
// #placemarks;
#TOTAL_ZOOM: number;
#CITY_ZOOM: number;
#PLACE_ZOOM: number;

constructor() {
#currentAddress?: string;
#isCertainPoint: boolean;

constructor(address?: string) {
this.#TOTAL_ZOOM = 4;
this.#CITY_ZOOM = 11;
this.#PLACE_ZOOM = 13;

// this.#placemarks = new Map();
this.#currentAddress = address;
this.#isCertainPoint = (address) ? true : false;
}

#getLocation() {
Expand Down Expand Up @@ -127,22 +130,55 @@ class MapPage {
});
// carouselContainer.innerHTML = template({ id: d.id, images: mockImages });

const placemark = new ymaps.GeoObject(
{
geometry: {
type: 'Point',
coordinates: coordinates,
let placemark;
console.log(this.#isCertainPoint);
console.log(this.#currentAddress);
console.log(d.cityName + ', ' + d.address);
console.log(this.#currentAddress === d.cityName + ', ' + d.address);
if (this.#isCertainPoint && this.#currentAddress === d.cityName + ', ' + d.address) {
// Смотрим определенную точку, например, перешли по кнопке Показать на карте
placemark = new ymaps.GeoObject(
{
geometry: {
type: 'Point',
coordinates: coordinates,
},
properties: {
hintContent: d.address,
balloonContentHeader: d.address,
balloonContentBody: carouselContainer.innerHTML,
},
},
properties: {
hintContent: d.address,
balloonContentHeader: d.address,
balloonContentBody: carouselContainer.innerHTML,
{
balloonMinWidth: 250,
preset: "islands#redDotIcon",

Check failure on line 154 in src/pages/MapPage/MapPage.ts

View workflow job for this annotation

GitHub Actions / Run linters

Strings must use singlequote
}
);

this.#map.setCenter(
placemark.geometry._coordinates,
this.#PLACE_ZOOM
);

} else {
// Просто добавление точки в кластер
placemark = new ymaps.GeoObject(
{
geometry: {
type: 'Point',
coordinates: coordinates,
},
properties: {
hintContent: d.address,
balloonContentHeader: d.address,
balloonContentBody: carouselContainer.innerHTML,
},
},
},
{
balloonMinWidth: 250,
}
);
{
balloonMinWidth: 250,
}
);
}

placemark.events.add('click', () => {
this.#map.setCenter(
Expand Down

0 comments on commit 1c6583b

Please sign in to comment.