Skip to content

Commit

Permalink
- Add country selection option
Browse files Browse the repository at this point in the history
- Redesign UI + responsiveness
- Minor refactorings
- Add favicon
- Repo cleanup
  • Loading branch information
wazeerc committed May 29, 2024
1 parent 831e342 commit 022e05f
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 53 deletions.
Binary file added public/globe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 4 additions & 28 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,18 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<link rel="icon" href="%PUBLIC_URL%/globe.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
content="Flags Guessr | A Flag Guessing Game"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/globe.png" />
<title>Flags Guessr | A Flag Guessing Game</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
11 changes: 5 additions & 6 deletions src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import App from './App';
import { render } from "@testing-library/react";

test('renders learn react link', () => {
import App from "./App";

test("renders learn react link", () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
expect(true).toBe(true);
});
8 changes: 5 additions & 3 deletions src/components/CountriesGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { allCoutries } from "../data/allCountries";
import { countryFlag } from "../utils/dataFetching";
import { getFlag } from "../utils/fetchData";

const CountriesGrid = () => {
const sessionCountry = "mu"; // TODO: Get from store
const sessionCountryFlag = getFlag(sessionCountry);

const country = allCoutries[0];
const imgSrc = countryFlag(country);
return (
<>
<h1>What flag is this?</h1>
<section id="countries-grid">
<img className="mu" alt={country} src={imgSrc}></img>
<img className="flag" alt={country} src={sessionCountryFlag}></img>
</section>
</>
);
Expand Down
9 changes: 7 additions & 2 deletions src/components/FlagsGuessr.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { useEffect } from "react";
import CountriesGrid from "./CountriesGrid";
import Options from "./Options";
import OptionsGrid from "./OptionsGrid";

import "./styles/FlagsGuessr.css";

const FlagsGuessr = () => {
useEffect(() => {
//TODO: dispatch country to store
}, []);

return (
<>
<main className="flags-guessr-main">
<CountriesGrid />
<Options />
<OptionsGrid />
</main>
</>
);
Expand Down
9 changes: 0 additions & 9 deletions src/components/Options.tsx

This file was deleted.

61 changes: 61 additions & 0 deletions src/components/OptionsGrid.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import React, { useEffect, useState } from "react";

interface ICountries {
countryName: string;
onClick: (event: React.MouseEvent<HTMLButtonElement>) => void;
}

const CountriesOptions = (props: ICountries) => {
const { countryName, onClick } = props;

return (
<>
<button onClick={onClick}>{countryName}</button>
</>
);
};

const OptionsGrid = () => {
const [selection, setSelection] = useState<string | null>(null);
const [isSelectionCorrect, setIsSelectionCorrect] = useState<boolean>(false);
const [emoji, setEmoji] = useState<string>("🌐");

const tempOptions = ["Mauritius", "Australia", "France", "England"];

useEffect(() => {
if (selection === "Mauritius") {
setIsSelectionCorrect(true);
setEmoji("🤗");
}
}, [selection]);

const handleCountrySelection = (selectedCountry: string) => {
if (!isSelectionCorrect) {
setSelection(selectedCountry);
}
};

return (
<>
<h2>{emoji}</h2>
{!isSelectionCorrect ? (
<div className="options-grid">
{tempOptions.map((country) => (
<CountriesOptions
key={country}
countryName={country}
onClick={() => {
handleCountrySelection(country);
if (selection !== "Mauritius") setEmoji("😱");
}}
/>
))}
</div>
) : (
<h3>Indeed, this is the Mauritian flag!</h3>
)}
</>
);
};

export default OptionsGrid;
35 changes: 31 additions & 4 deletions src/components/styles/FlagsGuessr.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
.flags-guessr-main{
.flags-guessr-main {
color: aliceblue;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
gap: 1rem;
gap: .4rem;
height: 100vh;
text-align: center;

.mu{
height: 25rem;
.flag {
height: 20rem;
}

.options-grid {
display: grid;
grid-template-columns: repeat(2, auto);
grid-gap: 2rem;

button {
width: 14rem;
}
}
}

@media screen and (max-width: 768px) {
.flags-guessr-main {
.flag {
height: 13.4rem;
}

.options-grid {
button {
width: 9rem;
font-size: 1rem;
}
}
}
}
2 changes: 2 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
body {
margin: 0;
padding: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
background-color: #1f1f1f;
}

code {
Expand Down
1 change: 1 addition & 0 deletions src/store/FlagsGuessrSlice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { }
2 changes: 1 addition & 1 deletion src/utils/dataFetching.ts → src/utils/fetchData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ const getFlag = (country: string) => {
return `https://flagcdn.com/${country}.svg`
}

export { getFlag as countryFlag };
export { getFlag };

0 comments on commit 022e05f

Please sign in to comment.