Skip to content

WM5 | AISHA_ATHMAN_LALI | MODULE_REACT | HIGH_SCORES_TABLE | LEVEL 1 & 2 #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

aishaathmanlali
Copy link

@aishaathmanlali aishaathmanlali commented Mar 6, 2024

Self checklist

  • I have committed my files one by one, on purpose, and for a reason
  • I have titled my PR with COHORT_NAME | FIRST_NAME LAST_NAME | REPO_NAME | WEEK
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

This is a PR for the High-Scores Table challenge. I have completed level one where I have displayed the given data in tables as requested in the instructions

Questions

I am still struggling with the table. Is there a better way to go about it?

@aishaathmanlali aishaathmanlali changed the title WM5 | AISHA_ATHMAN_LALI | MODULE_REACT | HIGH_SCORES_TABLE | WEEK_1 WM5 | AISHA_ATHMAN_LALI | MODULE_REACT | HIGH_SCORES_TABLE | WEEK 1 & 2 Mar 9, 2024
@aishaathmanlali aishaathmanlali changed the title WM5 | AISHA_ATHMAN_LALI | MODULE_REACT | HIGH_SCORES_TABLE | WEEK 1 & 2 WM5 | AISHA_ATHMAN_LALI | MODULE_REACT | HIGH_SCORES_TABLE | LEVEL 1 & 2 Mar 9, 2024
Comment on lines +14 to +48
.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}

@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
}

.card {
padding: 2em;
}

.read-the-docs {
color: #888;
}

Choose a reason for hiding this comment

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

This may have been left in by accident, because I can't see where it is being used.

},
];

export default allCountryScores;

Choose a reason for hiding this comment

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

I would consider removing the default attribute from your export as it is considered a bad practice by most developers. There are multiple reasons for this by a common one is the variable/function name could differ between files and cause confusion if changes are made.

Instead of an import such as

import allCountryScores from "../scores.js"

It would look like

import { allCountryScores } from "../scores.js"

Any variables/functions etc that are referenced inside braces {}, need to match the declaration in the file you are importing from, improving the consistency of your naming.

If you tried to do

import { nothing } from "../scores.js"

It would fail as there are no variables/functions named nothing in scores.js.

Choose a reason for hiding this comment

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

Also, your export can be moved onto the same line as your declaration of your variable, so line 65 is not necessary, the same can be achieved by moving 'export' or 'export default' to line 1.

This would look like

export let allCountryScores = []

Or since const would be more appropriate here export const allCountryScores = []

Comment on lines +11 to +57
function App() {
allCountryScores.sort(byName);
return (
<>
<h1>HIGH SCORES PER COUNTRY</h1>
{allCountryScores.map((country, index) => (
<table
style={{
border: "1px solid black",
borderSpacing: "10px",
width: "100%",
}}
>
<thead>
<tr>
<th scope="col" style={{ border: "2px solid red" }} key={index}>
{country.name}
</th>
</tr>
</thead>
<tbody>
<tr>
<ul style={{ borderBottom: "2px solid blue" }} scope="col">
<td style={{ padding: "1px" }}>player</td>
<td style={{ paddingLeft: "40px" }}>score</td>
</ul>
</tr>
</tbody>
<tbody>
<tr>
{country.scores.map((score, index) => (
<ul
style={{ borderBottom: "1px solid red" }}
scope="col"
key={index}
>
<td style={{ marginRight: "1px" }}>{score.n}</td>
<td style={{ marginLeft: "90px" }}>{score.s}</td>
</ul>
))}
</tr>
</tbody>
</table>
))}
</>
);
}

Choose a reason for hiding this comment

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

Great Job!

If you wanted another challenge I would encourage you to look into importing individual components, this will be crucial when you start working with larger files.

Here is an article from the React team on this area https://react.dev/learn/importing-and-exporting-components

This can help in a few areas:

  1. Allow you to create reusable components without duplicating code.
  2. Cleanup larger files and make your code easier to read.

To use your work as an example, your App function could be refactored to look like:

function App() {
  allCountryScores.sort(byName);

  return (
    <>
      <h1> HIGH SCORES PER COUNTRY </h1>

      {allCountryScores.map( ( country, index ) => (
        <ScoreTable country={country} index={index} />
      ) )}
    </>
  );
}

import "./App.scss";
import "../scores.js";

Choose a reason for hiding this comment

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

Unused import

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants