Skip to content

Commit

Permalink
Исправления для GitHub Pages
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyAkkuratov committed May 30, 2024
1 parent 2c84af3 commit 7977635
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
40 changes: 23 additions & 17 deletions src/weatherApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,38 @@ export default async function weatherApp(rootElement) {

async function updateHistoryBlock(cityName) {
const historyElement = rootElement.querySelector("#history");

if (historyList.includes(cityName)) {
historyList.splice(historyList.indexOf(cityName), 1);
historyList.unshift(cityName);
}

const p = historyElement.querySelector(`[id='${cityName}']`);
historyList.unshift(cityName);
let p = historyElement.querySelector(`[id='${cityName}']`);

if (p) {
historyElement.removeChild(p);
historyElement.querySelector("span").insertAdjacentElement("afterend", p);
} else {
historyList.unshift(cityName);
const p = createHistoryParagraph(cityName);

p = createHistoryParagraph(cityName);
historyElement.querySelector("span").insertAdjacentElement("afterend", p);
}

if (historyList.length > maxHistorylines) {
historyList.pop();
historyElement.removeChild(historyElement.lastElementChild);
}
if (historyList.length > maxHistorylines) {
historyList.pop();
historyElement.removeChild(historyElement.lastElementChild);
}
setHistorySet(historyList);
}

function loadHistory() {
const localHistoryList = getHistoryList();
if (localHistoryList.length > 0) {
localHistoryList
.reverse()
.forEach((cityName) => updateHistoryBlock(cityName));
}
}

const ipInfo = await getInfoByIP();

rootElement.innerHTML = mainTemplate;
Expand All @@ -97,7 +107,8 @@ export default async function weatherApp(rootElement) {
rootElement.addEventListener("click", (event) => {
if (event.target instanceof HTMLAnchorElement) {
event.preventDefault();
router.navigate(event.target.href);
// eslint-disable-next-line no-undef
router.navigate(PREFIX + event.target.href);
}
});

Expand All @@ -119,15 +130,10 @@ export default async function weatherApp(rootElement) {
path: "/",
onEnter: () => {
rootElement.innerHTML = mainTemplate;
loadHistory();
},
});

const localHistoryList = getHistoryList();
if (localHistoryList.length > 0) {
localHistoryList
.reverse()
.forEach((cityName) => updateHistoryBlock(cityName));
}

loadHistory();
if (ipInfo.city) router.navigate(`/weather/${ipInfo.city}`);
}
7 changes: 7 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { DefinePlugin } = require("webpack");

const PREFIX =
process.env.NODE_ENV === "production" ? "/OTUS_homework_lesson07" : "";

module.exports = {
entry: "./src/index.js",
Expand All @@ -20,6 +24,9 @@ module.exports = {
favicon: "./src/assets/favicon.png",
filename: "404.html",
}),
new DefinePlugin({
PREFIX: JSON.stringify(PREFIX),
}),
],
module: {
rules: [
Expand Down

0 comments on commit 7977635

Please sign in to comment.