Skip to content
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

Made a navbar #37

Closed
Closed
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
37 changes: 19 additions & 18 deletions backend/uno-game-engine/deck.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
const colors: Array<CardColor> = ['red', 'yellow', 'green', 'blue'];
const values = [
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'skip',
'reverse',
'draw2',
];
const specialCards = ['wild', 'draw4'];
const deck = [];
// const colors = ['red', 'yellow', 'green', 'blue'];
// const values = [
// '0',
// '1',
// '2',
// '3',
// '4',
// '5',
// '6',
// '7',
// '8',
// '9',
// 'skip',
// 'reverse',
// 'draw2',
// ];
// const specialCards = ['wild', 'draw4'];
// const deck = [];
const sameCardCount = []; // to keep track of same cards in assigning unique id to each card

/**
Expand Down Expand Up @@ -74,6 +74,7 @@ export function makeCard(
* This function shuffles the elements of the given array *in place* . The function behaves in a type-agnostic way.
* Time complexity: O(n)
*/
// elint-disable-next-line
export function shuffle(deck: Array<UNOCard>) {
// Fisher-Yates shuffle algorithm to shuffle card deck
for (let i = deck.length - 1; i > 0; i--) {
Expand Down
319 changes: 121 additions & 198 deletions frontend/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"postcss": "^8.4.38",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^5.2.1",
"react-router-dom": "^6.23.1",
"tailwindcss": "^3.4.3"
},
Expand Down
65 changes: 65 additions & 0 deletions frontend/src/Navbar.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
body {
transition: margin-right 0.3s;
margin-right: 0;
}

body.menu-open {
margin-right: 250px;
}

.sidebar {
position: fixed;
top: 0;
right: -250px;
width: 250px;
height: 100%;
background-color: #111;
overflow-x: hidden;
transition: right 0.3s;
z-index: 1000;
}

.sidebar.open {
right: 0;
}

.ul {
list-style-type: none;
padding: 0;
}

.li {
padding: 8px 16px;
text-align: left;
color: #818181;
}

.li:hover {
background-color: #575757;
color: #ffffff;
}

.a {
text-decoration: none;
color: inherit;
display: block;
}

.a.active {
color: yellow;
}

.menuButton {
position: absolute;
top: 10px;
right: 10px;
z-index: 1100;
}

.hidden {
display: none;
}

.mainContent {
transition: margin-right 0.3s;
}
99 changes: 96 additions & 3 deletions frontend/src/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,100 @@
import './index.css';
import { useState, useEffect } from 'react';
import { Link, NavLink } from 'react-router-dom';
import { FaBars, FaTimes } from 'react-icons/fa';
import styles from './Navbar.module.css';

function Navbar() {
return <div className="flex flex-row">Navbar</div>;
interface NavbarProps {
logoSrc?: string;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good job on the props!

bgColorFrom?: string;
bgColorTo?: string;
navLinks?: Array<{ title: string; link: string }>;
}

function Navbar(props: NavbarProps) {
const {
logoSrc = './assets/uno_csoc.png', // Default logo
navLinks = [
{ title: 'Home', link: '/' },
{ title: 'Play', link: '/play' },
{ title: 'Game', link: '/game' },
{ title: 'About', link: '/about' },
], // Default navigation
bgColorFrom = '#999999',
bgColorTo = '#333333',
// Default background colors
} = props;

const [open, setOpen] = useState(false);

useEffect(() => {
document.body.classList.toggle('menu-open', open);
}, [open]);

const handleMenu = () => {
setOpen((prev) => !prev);
};
const background = `linear-gradient(to right, ${bgColorFrom}, ${bgColorTo})`;

return (
<header className="sticky top-0 z-50 flex flex-row">
<nav
className="bg-opacity-90 border-gray-200 px-4 lg:px-6 py-2.5 w-full"
style={{ background }}
>
<div className="flex flex-wrap items-center justify-between max-w-screen-xl mx-auto">
<Link to="/" className="flex items-center">
<img src={logoSrc} className="h-12 mr-3" alt="Logo" />
</Link>
<div className="items-center justify-between hidden w-full md:flex md:w-auto md:order-1">
<ul className="flex flex-col mt-4 font-medium md:flex-row md:space-x-8 md:mt-0">
{navLinks.map((link, index) => (
<li key={index}>
<NavLink
to={link.link}
className={({ isActive }) =>
`block py-2 pr-4 pl-3 duration-200 border-b border-gray-100 hover:bg-gray-50 lg:hover:bg-transparent lg:border-0 hover:text-yellow-400 lg:p-0 ${isActive ? 'text-yellow-400' : 'text-gray-300'}`
}
>
{link.title}
</NavLink>
</li>
))}
</ul>
</div>
<div className={`flex md:hidden ${styles.menuButton}`}>
<button
type="button"
onClick={handleMenu}
className={`inline-flex items-center justify-center p-2 text-gray-400 rounded-md hover:text-white hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-800 focus:ring-white`}
>
<span className="sr-only">Toggle main menu</span>
{open ? <FaTimes /> : <FaBars />}
</button>
</div>
</div>
</nav>
<div
id="sidebar"
className={`${styles.sidebar} ${open ? styles.open : ''}`}
>
<ul className={styles.ul}>
{navLinks.map((link, index) => (
<li key={index} className={styles.li}>
<NavLink
to={link.link}
className={({ isActive }) =>
`${styles.a} ${isActive ? styles.active : ''}`
}
onClick={() => setOpen(false)}
>
{link.title}
</NavLink>
</li>
))}
</ul>
</div>
</header>
);
}

export default Navbar;
Binary file added frontend/src/assets/uno_csoc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion frontend/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
#root {
width: 100%;
}

a {
font-weight: 500;
Expand All @@ -29,7 +32,6 @@ a:hover {
body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}
Expand Down
18 changes: 17 additions & 1 deletion frontend/src/pages/AppLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
import { Outlet } from 'react-router-dom';
import Navbar from '../Navbar';
import uno_csoc from '../assets/uno_csoc.png';

function AppLayout() {
const logoSrc = uno_csoc; // give path of the logo you want
const navLinks = [
{ title: 'Home', link: '/' },
{ title: 'Play Options', link: '/play' },
{ title: 'Game', link: '/game' },
{ title: 'About', link: '/about' },
];
const bgColorFrom = '#999999';
const bgColorTo = '#333333'; // Example background colors

return (
<div>
<Navbar />
<Navbar
logoSrc={logoSrc}
navLinks={navLinks}
bgColorFrom={bgColorFrom}
bgColorTo={bgColorTo}
/>
<Outlet />
{/* todo: Add a footer component */}
</div>
Expand Down
Loading