Skip to content

Commit

Permalink
Fix regression
Browse files Browse the repository at this point in the history
PleatherStarfish committed Dec 12, 2024
1 parent ed9c972 commit e784b4e
Showing 13 changed files with 322 additions and 171 deletions.
2 changes: 1 addition & 1 deletion backend/static/css/styles.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion backend/static/js/main.bundle.js

Large diffs are not rendered by default.

54 changes: 41 additions & 13 deletions backend/static/js/toggle_dropdown.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,58 @@
// ===============================================
// Generic Dropdown Toggle Functionality
// Dropdown Toggle Functionality
// ===============================================

// Select all menu buttons
const $buttons = $(".menu-button");
// Select profile dropdown button
const $profileButton = $(".menu-button-click"); // For click-based dropdowns
const $hoverButton = $(".menu-button-hover"); // For hover-based dropdowns

// Toggle the visibility of dropdown menus when a button is clicked
$buttons.on("click", function(event) {
// Toggle visibility for click-based dropdown menus
$profileButton.on("click", function (event) {
event.stopPropagation(); // Prevent click event from bubbling up
const $menu = cash(this.nextElementSibling); // Get the menu element next to the button
const $menu = cash(this.nextElementSibling); // Get the dropdown menu
$menu.toggleClass("hidden block"); // Toggle visibility classes

// Update the aria-expanded attribute for accessibility
// Update aria-expanded for accessibility
const expanded = $menu.hasClass("block");
this.setAttribute("aria-expanded", expanded);
});

// Close dropdown menus when clicking outside of them
$(document).on("click", function() {
$buttons.each(function(index, button) {
// Keep dropdown open when interacting with it
$(".dropdown-menu").on("click", function (event) {
event.stopPropagation(); // Prevent click event from bubbling up
});

// Close click-based dropdowns when clicking outside
$(document).on("click", function () {
$profileButton.each(function (index, button) {
const $menu = cash(button.nextElementSibling);

// Hide the menu and reset aria-expanded if it's visible
// Hide the menu and reset aria-expanded if visible
if (!$menu.hasClass("hidden")) {
$menu.addClass("hidden");
$menu.addClass("hidden").removeClass("block");
button.setAttribute("aria-expanded", false);
}
});
});
});

// Hover functionality for hover-based dropdowns
$hoverButton.on("mouseenter", function () {
const $menu = cash(this.nextElementSibling); // Get the dropdown menu
$menu.removeClass("hidden").addClass("block"); // Show the menu
this.setAttribute("aria-expanded", true);
});

// Keep hover-based dropdown open when mouse enters the menu
$(".hover-dropdown-menu").on("mouseenter", function () {
const $button = cash(this.previousElementSibling); // Get the hover button
$button.attr("aria-expanded", true);
$(this).removeClass("hidden").addClass("block"); // Keep it visible
});

// Close hover-based dropdown when the mouse leaves both the button and menu
$hoverButton.add(".hover-dropdown-menu").on("mouseleave", function () {
const $menu = cash(this.nextElementSibling || this); // Get the dropdown menu
$menu.addClass("hidden").removeClass("block"); // Hide the menu
const $button = cash($menu.prev()); // Update aria-expanded on the button
$button.attr("aria-expanded", false);
});
11 changes: 5 additions & 6 deletions backend/templates/components/dropdown_menu.html
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
/>
</a>
</div>
<div class="relative pr-2 border-r border-gray-100">
<div class="relative pr-2">
<select
id="currency-selector"
class="px-3 py-2 text-white bg-[#212529] transition-all border-0 w-[75px] outline-none"
@@ -24,25 +24,24 @@
</span>
</div>
<button
class="block pl-2 ml-4 text-white menu-button text-decoration-none focus:outline-none"
class="block pl-2 ml-4 text-white menu-button-click text-decoration-none focus:outline-none"
aria-label="User menu"
aria-haspopup="true"
aria-expanded="false"
>
{{ button_text }}
</button>
<div
class="absolute right-0 z-30 hidden w-48 py-2 mt-2 rounded-md shadow-md top-full bg-gray-50"
class="absolute right-0 z-30 hidden w-52 py-2 mt-2 rounded-md shadow-md top-full bg-[#212529]"
>
<ul class="text-sm text-gray-700">
<ul class="text-white">
{% for item in dropdown_items %}
<li>
<a class="block px-4 py-2 hover:bg-gray-100" href="{{ item.url }}"
<a class="block px-4 py-2 hover:hover:bg-[#2c3237]" href="{{ item.url }}"
>{{ item.name }}</a
>
</li>
{% if not forloop.last %}
<hr class="dropdown-divider" />
{% endif %} {% endfor %}
</ul>
</div>
128 changes: 105 additions & 23 deletions backend/templates/nav.html
Original file line number Diff line number Diff line change
@@ -39,46 +39,128 @@
<div
class="flex items-center justify-center flex-1 sm:items-stretch sm:justify-start"
>
<div class="hidden md:block">
<div class="hidden h-16 md:block">
{% with request.path|slice:":5" as path %}
{% if path == '/user' %}
<ul class="flex space-x-3 text-white hover:text-gray-200 ml-[60px]">
<ul class="flex space-x-3 text-white hover:text-gray-200 ml-[60px] h-16">
<li>
<a href="{% url 'home' %}" class="px-2 nav-link text-secondary"
><i class="bi bi-house"></i></a
<button
onclick="window.location.href='{% url 'home' %}'"
class="flex flex-col justify-center h-full px-2 nav-link text-secondary"
type="button"
>
<i class="bi bi-house"></i>
</button>
</li>
<li>
<a href="{% url 'about' %}" class="px-2 nav-link">About</a>
</li>
<li>
<a href="/projects/" class="px-2 nav-link">Projects</a>
<button
onclick="window.location.href='/projects/'"
class="flex flex-col justify-center h-full px-2 nav-link text-secondary"
type="button"
>
<span>Projects</span>
</button>
</li>
<li>
<a href="/components/" class="px-2 nav-link">Components</a>
<button
onclick="window.location.href='/components/'"
class="flex flex-col justify-center h-full px-2 nav-link text-secondary"
type="button"
>
<span>Components</span>
</button>
</li>
<li>
<a href="/community/" class="px-2 nav-link">Community</a>

<!-- Resources Dropdown -->
<li class="relative group">
<button
class="h-full px-2 text-white menu-button-hover nav-link"
aria-expanded="false"
type="button"
>
Resources
</button>
<div class="absolute left-0 hidden mt-0 text-white bg-[#212529] rounded-b shadow-lg hover-dropdown-menu">
<ul
class="mt-2"
>
<li>
<a href="{% url 'about' %}" class="block py-3 px-9 hover:bg-[#2c3237]">
About
</a>
</li>
<li>
<a href="/community/" class="block py-3 px-9 hover:bg-[#2c3237]">
Community
</a>
</li>
<li>
<a href="/tools/" class="block py-3 px-9 hover:bg-[#2c3237]">
Tools
</a>
</li>
</ul>
</div>
</li>
</ul>
{% else %}
<ul class="flex space-x-3 text-white hover:text-gray-200 ml-[200px]">
<ul class="flex space-x-3 text-white hover:text-gray-200 ml-[200px] h-16">
<li>
<a href="{% url 'home' %}" class="px-2 nav-link text-secondary"
><i class="bi bi-house"></i></a
<button
onclick="window.location.href='{% url 'home' %}'"
class="flex flex-col justify-center h-full px-2 nav-link text-secondary"
type="button"
>
<i class="bi bi-house"></i>
</button>
</li>
<li>
<a href="{% url 'about' %}" class="px-2 nav-link">About</a>
</li>
<li>
<a href="/projects/" class="px-2 nav-link">Projects</a>
<button
onclick="window.location.href='/projects/'"
class="flex flex-col justify-center h-full px-2 nav-link text-secondary"
type="button"
>
<span>Projects</span>
</button>
</li>
<li>
<a href="/components/" class="px-2 nav-link">Components</a>
<button
onclick="window.location.href='/components/'"
class="flex flex-col justify-center h-full px-2 nav-link text-secondary"
type="button"
>
<span>Components</span>
</button>
</li>
<li>
<a href="/community/" class="px-2 nav-link">Community</a>

<!-- Resources Dropdown -->
<li class="relative group">
<button
class="h-full px-2 text-white menu-button-hover nav-link"
aria-expanded="false"
type="button"
>
Resources
</button>
<div class="absolute left-0 hidden mt-0 text-white bg-[#212529] rounded-b shadow-lg hover-dropdown-menu">
<ul>
<li>
<a href="{% url 'about' %}" class="block py-3 px-9 hover:bg-[#2c3237]">
About
</a>
</li>
<li>
<a href="/community/" class="block py-3 px-9 hover:bg-[#2c3237]">
Community
</a>
</li>
<li>
<a href="/tools/" class="block py-3 px-9 hover:bg-[#2c3237]">
Tools
</a>
</li>
</ul>
</div>
</li>
</ul>
{% endif %}
@@ -95,7 +177,7 @@
{% dropdown_items user as dropdown_items %}
{% include "components/dropdown_menu.html" with button_text=user.email dropdown_items=dropdown_items %}
</div>
{% else %}
{% else %}
<div class="flex items-center space-x-2">
<div class="flex items-center pr-4 space-x-4 border-r border-gray-100">
<a href="https://ko-fi.com/bomsquad">
@@ -131,7 +213,7 @@
>Sign up</a
>
</div>
{% endif %}
{% endif %}
</div>
</div>
{% include "components/mobile_hamburger_menu.html" %}
1 change: 1 addition & 0 deletions frontend/src/components/bom_list/nestedTable.tsx
Original file line number Diff line number Diff line change
@@ -79,6 +79,7 @@ const NestedTable: React.FC<NestedTableProps> = ({ data }) => {
const { componentsData, componentsAreLoading, componentsAreError } =
useGetComponentsByIds(components_options);
const { data: currencyData } = useGetUserCurrency();
console.log(componentsData)

// Ah yes, another bizarre useEffect hack to get around the quirks of react-data-table-component...
useEffect(() => {
9 changes: 3 additions & 6 deletions frontend/src/components/shopping_list/Quantity.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import React from "react";
import { get } from "lodash";

interface Component {
quantity: number;
}
import { AggregatedComponent } from "../../types/shoppingList"

interface QuantityProps {
componentId: string;
componentsInModule?: Record<string, Component[]>;
pencilComponent?: React.ReactNode;
componentsInModule?: Record<string, AggregatedComponent[]> | undefined;
hideInteraction?: boolean;
pencilComponent?: React.ReactNode;
}

const Quantity: React.FC<QuantityProps> = ({
14 changes: 9 additions & 5 deletions frontend/src/components/shopping_list/TotalPriceForComponent.tsx
Original file line number Diff line number Diff line change
@@ -5,23 +5,27 @@ import useUserShoppingListComponentTotalPrice from "../../services/useGetUserSho

interface TotalPriceForComponentProps {
componentId: string;
currency: string;
}

const TotalPriceForComponent: React.FC<TotalPriceForComponentProps> = ({ componentId }) => {
const { totalPriceData, totalPriceIsLoading, totalPriceIsError } =
useUserShoppingListComponentTotalPrice(componentId);
const { data: currencyData, isLoading: currencyIsLoading } = useGetUserCurrency();

if (totalPriceIsError || !currencyData) {
return <div>Error fetching data</div>;
}
const { data: currencyData, isLoading: currencyIsLoading, isError: currencyIsError } =
useGetUserCurrency();

// If data is still loading, show a loading indicator
if (totalPriceIsLoading || currencyIsLoading) {
return (
<div className="text-center text-gray-500 animate-pulse">Loading...</div>
);
}

// If both calls failed, show a fallback message or value
if (totalPriceIsError && currencyIsError) {
return <span className="text-xs font-bold">N/A</span>;
}

const totalMinPrice = convertUnitPrice(totalPriceData?.total_min_price || 0, currencyData);
const totalMaxPrice = convertUnitPrice(totalPriceData?.total_max_price || 0, currencyData);

8 changes: 5 additions & 3 deletions frontend/src/components/shopping_list/index.tsx
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ import Notification from "../../ui/Notification";
import useAddComponentToInventory from "../../services/useAddComponentToInventory";
import useArchiveShoppingListMutation from "../../services/useArchiveUserSavedShoppingList";
import useGetUserShoppingList from "../../services/useGetUserShoppingList";
import { GroupedByModule } from "../../types/shoppingList";
import { UserShoppingList } from "../../types/shoppingList";

const ShoppingList: React.FC = () => {
const textareaRef = React.useRef<HTMLTextAreaElement | null>(null);
@@ -134,13 +134,15 @@ const ShoppingList: React.FC = () => {
].map((value, index) => {
const moduleSlug = Object.values(value.data)?.[0]?.[0]?.module?.slug;
const moduleId = Object.values(value.data)?.[0]?.[0]?.module?.id;
const componentsInModule = Array.isArray(value.data) ? {} : (value.data as Record<string, UserShoppingList[]>);
return (
<ListSlice
aggregatedComponents={
userShoppingListData.aggregatedComponents
userShoppingListData?.aggregatedComponents
}
allModulesData={userShoppingListData.groupedByModule as GroupedByModule[]}
allModulesData={userShoppingListData.groupedByModule}
componentsAreLoading={userShoppingListIsLoading}
componentsInModule={componentsInModule}
index={index}
key={value.name}
moduleId={moduleId}
Loading

0 comments on commit e784b4e

Please sign in to comment.