Skip to content

Commit

Permalink
Added a dropdown menu that will be home to operations for selected as…
Browse files Browse the repository at this point in the history
…sets.
  • Loading branch information
ashleydavis committed Jul 7, 2024
1 parent 6fa989e commit 1c52303
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 33 deletions.
1 change: 0 additions & 1 deletion electron/frontend/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ i {
height: 52px;
background-color: white;
border-bottom: 1px solid rgb(218, 220, 224);
overflow: hidden;
}

#navbar.search {
Expand Down
28 changes: 25 additions & 3 deletions frontend/src/styles.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
body {
overflow: hidden;
font-family: 'Roboto', Arial, sans-serif;
color: rgb(60,64,67);
color: rgb(60, 64, 67);
font-size: 1.125rem;
line-height: 1.5rem;
letter-spacing: 0;
Expand Down Expand Up @@ -106,7 +106,6 @@ i {
height: 52px;
background-color: white;
border-bottom: 1px solid rgb(218, 220, 224);
overflow: hidden;
}

#navbar.search {
Expand All @@ -133,6 +132,7 @@ i {
from {
opacity: 0;
}

to {
opacity: 1;
}
Expand Down Expand Up @@ -282,8 +282,30 @@ i {
.info.open>.info-header {
left: 50%;
}
}
}

.info-content {
margin-top: 50px;
}

/* Drop down */

.dropdown {
position: relative;
display: inline-block;
}

.dropdown-toggle {
cursor: pointer;
height: 39px;
padding: 8px;
}

.dropdown-menu li {
padding: 10px;
cursor: pointer;
}

.dropdown-menu li:hover {
background-color: #f0f0f0;
}
1 change: 0 additions & 1 deletion mobile/frontend/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ i {
height: 52px;
background-color: white;
border-bottom: 1px solid rgb(218, 220, 224);
overflow: hidden;
}

#navbar.search {
Expand Down
97 changes: 97 additions & 0 deletions packages/user-interface/src/components/dropdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import React, { useEffect, useRef, useState } from 'react';
import { useAuth } from '../context/auth-context';
import { useIndexeddb } from '../context/indexeddb-context';

export function Dropdown() {
const [isOpen, setIsOpen] = useState(false);
const dropdownRef = useRef<HTMLDivElement>(null);

const {
logout,
} = useAuth();

const {
deleteDatabase
} = useIndexeddb();

function onToggleDropdown() {
setIsOpen(!isOpen);
};

function onClick() {
setIsOpen(false);
};

function onClickOutside(event: MouseEvent) {
if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) {
setIsOpen(false);
}
};

useEffect(() => {
if (isOpen) {
document.addEventListener('mousedown', onClickOutside);
} else {
document.removeEventListener('mousedown', onClickOutside);
}
return () => {
document.removeEventListener('mousedown', onClickOutside);
};
}, [isOpen]);

async function onLogOut() {
setIsOpen(false);

await logout();

await deleteDatabase();
}

return (
<div
className="dropdown"
ref={dropdownRef}
>
<button
className="dropdown-toggle mr-2"
onClick={onToggleDropdown}
>
<i className="fa-solid fa-ellipsis-vertical"></i>
</button>
{isOpen && (
<ul
className="dropdown-menu"
style={{
position: "absolute",
top: "calc(100% + 4px)",
right: "4px",
background: "white",
border: "1px solid #ccc",
width: "150px",
zIndex: "5000",
}}
>

<li onClick={onClick}>
Item 1
</li>

<li onClick={onClick}>
Item 2
</li>

<li onClick={onClick}>
Item 3
</li>

<li
onClick={onLogOut}
>
<i className="w-5 fa-solid fa-right-from-bracket"></i>
<span className="hidden sm:inline ml-1">Log out</span>
</li>
</ul>
)}
</div>
);
};
30 changes: 2 additions & 28 deletions packages/user-interface/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { useGallery } from "./context/gallery-context";
import classNames from "classnames";
import { useApp } from "./context/app-context";
import { useIndexeddb } from "./context/indexeddb-context";
import { Dropdown } from "./components/dropdown";
const FPSStats = require("react-fps-stats").default;


export interface IMainProps {
//
// The "computer page" which is only displayed in the Electron or mobile version.
Expand Down Expand Up @@ -177,12 +177,6 @@ export function Main({ computerPage }: IMainProps) {
}
}

async function onLogOut() {
await logout();

await deleteDatabase();
}

return (
<>
<div id="navbar" className={(openSearch ? "search": "")} >
Expand Down Expand Up @@ -278,27 +272,7 @@ export function Main({ computerPage }: IMainProps) {

</div>

{!isAuthenticated && (
<div className="ml-1 mr-2 sm:mr-4">
<button
onClick={login}
>
<i className="w-5 fa-solid fa-right-to-bracket"></i>
<span className="hidden sm:inline ml-2">Log in</span>
</button>
</div>
)}

{isAuthenticated && (
<div className="ml-1 mr-2 sm:mr-4">
<button
onClick={onLogOut}
>
<i className="w-5 fa-solid fa-right-from-bracket"></i>
<span className="hidden sm:inline ml-1">Log out</span>
</button>
</div>
)}
<Dropdown />
</div>

{openSearch
Expand Down

0 comments on commit 1c52303

Please sign in to comment.