Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/src/components/LoginButton/LoginButton.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from "react";

export const LoginButton: React.FC = () => {
const login = () => {
const login = React.useCallback(() => {
window.location.href = "http://localhost:4000/auth/login";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This hardcoded URL makes it difficult to deploy the application across different environments (development, staging, production). It's recommended to externalize this configuration using environment variables. For instance, you could define REACT_APP_API_URL in a .env file and construct the URL from it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Hardcoding URLs makes the application difficult to configure for different environments (e.g., development, staging, production) and is a maintainability concern. It's best practice to externalize configuration values like this.

Consider moving this URL to an environment variable. For example, in a Create React App project, you could use process.env.REACT_APP_LOGIN_URL and define it in a .env file.

};
}, []);
Comment on lines +4 to +6

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The use of React.useCallback here does not provide a performance benefit because the LoginButton component itself is not memoized (e.g., with React.memo). The component will still re-render if its parent re-renders, and the onClick handler will be recreated.

If performance optimization is the goal, you should also wrap the component in React.memo. If not, useCallback adds unnecessary complexity and can be removed for simplicity.


return (
<button type="button" onClick={login}>Login with Google</button>
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/Profile/Profile.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from "react";

type Props = {
name: string;
name?: string;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

By making name optional, it can be undefined. This will cause an empty <h3> tag to be rendered in the component. To prevent this, you should handle the undefined case where the prop is used, for example by providing a fallback value: <h3>{name || 'Anonymous User'}</h3>.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Making the name prop optional is a valid change to the component's API, but the implementation doesn't handle the case where name is not provided. This will result in an empty <h3> tag being rendered.

To improve this, you should consider either conditionally rendering the element or providing a fallback value.

Example (conditional rendering):

{name && <h3>{name}</h3>}

Example (fallback value):

<h3>{name || 'Anonymous'}</h3>

picture: string;
};
export const Profile: React.FC<Props> = ({ name, picture }) => {
return (
<div>
<div style={{display: "flex", flexDirection: "column"}}>

Check failure on line 9 in client/src/components/Profile/Profile.tsx

View workflow job for this annotation

GitHub Actions / build_and_test

A space is required before '}'

Check failure on line 9 in client/src/components/Profile/Profile.tsx

View workflow job for this annotation

GitHub Actions / build_and_test

A space is required after '{'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Inline styles are best avoided for maintainability. They mix styling with logic, are hard to override, and don't support features like pseudo-selectors or media queries. Please extract these styles into a CSS file and use a className instead. This will keep the component clean and the styles reusable.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using inline styles is generally discouraged because it mixes styling concerns with component logic, making styles harder to reuse, override, and maintain. It's better to use CSS classes with a separate stylesheet for better separation of concerns and maintainability.

For example:

In Profile.tsx:

<div className="profile-container">

In a corresponding CSS file:

.profile-container {
  display: flex;
  flex-direction: column;
}

<h3>{name}</h3>
<img src={picture} alt="Profile picture" />
</div>
Expand Down
14 changes: 7 additions & 7 deletions docs/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ const test = () => {
// console.log(c)
// b = "nova hodnota"

// const o = {
// data: () => {
// console.log("data");
// },
// };
// o["data"]?.();
// o["data2"]?.();
const o = {
data: () => {
console.log("data");
},
};
o["data"]?.();
o["data2"]?.();
test();
5 changes: 5 additions & 0 deletions docs/js/index2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
console.clear();

const obj = {
a: 1,
self: () => obj,
Expand All @@ -19,6 +20,8 @@ const obj = {

console.log("test2:");
console.log(obj.test2());


console.log("test:");
console.log(obj.test());

Expand All @@ -30,5 +33,7 @@ console.log(obj.test2.apply({}));
console.log("self");
console.log(obj.self());


console.log("----- TIMEOUT ------")
setTimeout(obj.testConsole, 3000);
setTimeout(obj.testConsole2, 3000);
2 changes: 1 addition & 1 deletion docs/js3/hell_await.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const demo = () => {

const run = async () => {
try {
console.log("HODNOTA "+ hodnota);
// console.log("HODNOTA "+ hodnota);
await deleteCopyFile();
const items = await getItems();
await writeItems(items);
Expand Down
2 changes: 1 addition & 1 deletion docs/js3/hell_promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ deleteCopyFile()
.then(getItems)
.then(writeItems)
.then(() => {
console.log("DONE");
console.log("All done");
})
.catch((err) => {
console.error("oops");
Expand Down
61 changes: 38 additions & 23 deletions docs/js3/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,46 @@
<head>
<meta charset="utf-8" />
<title>Demo</title>
<style>
#main {
display: flex;
background: #8ca7bf;
padding: 1em;
gap: 1em
}

</style>
</head>
<body>
<div id="main">
<h1 id="title">Demo</h1>

<form id="myForm">
<label for="jmeno">Jmeno (alespon 1 znak):</label>
<div>
<input type="text" value="" placeholder="Zadej hodnotu" id='jmeno' name="jmeno" />
</div>

<label for="prijmeni">Prijmeni (alespon 1 znak):</label>
<div>
<input type="text" value="riha" placeholder="Zadej hodnotu" id='prijmeni'
name="prijmeni" />
</div>

<button class='button' id="submit" type='button'>Odeslat</button>
</form>
<textarea id="output" rows="10" cols="50"></textarea>


<div>
<h1 id="title">Demo</h1>

<form id="myForm">
<label for="jmeno">Jmeno (alespon 1 znak):</label>
<div>
<input type="text" value="" placeholder="Zadej hodnotu" id='jmeno' name="jmeno" />
</div>

<label for="prijmeni">Prijmeni (alespon 1 znak):</label>
<div>
<input type="text" value="riha" placeholder="Zadej hodnotu" id='prijmeni'
name="prijmeni" />
</div>

<button class='button' id="submit" type='button'>Odeslat</button>
</form>
</div>

<div>
<textarea id="output" rows="10" cols="50"></textarea>
<button id="clear">Smazat</button>
</div>
<script>



const print = (message) => {
document.getElementById("output").value += `${typeof message === "string" ? message : JSON.stringify(message, null, 2)}
`;
document.getElementById("output").value += `${typeof message === "string" ? message : JSON.stringify(message, null, 2)}\n`;
};
const showError = (inputId) => {
const errorMessage = document.createElement("span");
Expand Down Expand Up @@ -60,7 +71,7 @@ <h1 id="title">Demo</h1>
// current target = element with listener
// target = who actually triggered it
// print(`#main klik, target: ${evt.target.getAttribute("id") ? `#${evt.target.getAttribute("id")}` : evt.target.tagName}`);
print(`#main klik, target: ${evt.target.getAttribute("id") ? `#${evt.target.getAttribute("id")}` : evt.target.tagName}`);
print(`#main klik, target: ${evt.target.getAttribute("id") ? `#${evt.target.getAttribute("id")}` : `<${evt.target.tagName}>`}`);
});


Expand All @@ -70,6 +81,10 @@ <h1 id="title">Demo</h1>
evt.stopPropagation();
});

document.querySelector("#clear").addEventListener("click", (evt) => {
document.getElementById("output").value = "";
evt.stopPropagation();
})

</script>

Expand Down
3 changes: 1 addition & 2 deletions docs/js3/pocasi.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
</head>
<body>
<div id="main">
<button class='button' id="pocasi" type='button'>Pocasi?</button>
<textarea id="output" rows="10" cols="50"></textarea>
<button class='button' id="poca" type='button'>Pocasi?</button>
<button class='button' id="pocasi" type='button'>Pocasi</button>
<script src="./pocasi.js"></script>

</div>
Expand Down
18 changes: 7 additions & 11 deletions docs/js3/pocasi.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ const getCityCoords = async (cityName) => {
try {

const response = await fetch(`https://geocoding-api.open-meteo.com/v1/search?name=${cityName}&language=en&format=json`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ key: "value" }),
method: "GET",
});


Expand All @@ -25,6 +21,7 @@ const getCityCoords = async (cityName) => {
return { latitude, longitude };
} catch (e) {
window.alert(e.message);
return undefined;
}
};
const getForecast = async ({ latitude, longitude }) => {
Expand All @@ -38,18 +35,17 @@ const getForecast = async ({ latitude, longitude }) => {
const max = jsonResponse.daily.temperature_2m_max[0];
const min = jsonResponse.daily.temperature_2m_min[0];
const average = (max + min) / 2;
print({ average: average + jsonResponse.daily_units.temperature_2m_max });
return average + jsonResponse.daily_units.temperature_2m_max;
} catch (e) {
window.alert(e.message);
}
};


window.document.getElementById("pocasi").addEventListener("click", async () => {
const mesto = "Praha";
const cities = document.querySelector("textarea").value.split(/[:;]/);

const cityCoords = await getCityCoords(mesto);
print(cityCoords);

const forecast = await getForecast(cityCoords);
const cityCoords = await getCityCoords(cities[0]);
print(`\n Coordinates: ${JSON.stringify(cityCoords, null, 4)}\n`);
print(` ${await getForecast(cityCoords)}`);
});
Loading