diff --git a/src/components/common/customtogglebutton.tsx b/src/components/common/customtogglebutton.tsx new file mode 100644 index 0000000..6c217cf --- /dev/null +++ b/src/components/common/customtogglebutton.tsx @@ -0,0 +1,67 @@ +import { + alpha, + ToggleButton, + Tooltip, + type ToggleButtonProps, +} from "@mui/material"; +import type { SxProps, Theme } from "@mui/material/styles"; +import { Square, SquareCheckBig } from "lucide-react"; +import type { ReactNode } from "react"; + +type CustomToggleButtonProps = ToggleButtonProps & { + activeColor?: string; + showIcon?: boolean; + tooltip?: ReactNode; +}; + +const customToggleButtonSx = + (activeColor?: string): SxProps => + (theme) => ({ + height: 40, + px: 2, + textTransform: "none", + gap: 0.5, + whiteSpace: "nowrap", + backgroundColor: "transparent", + "& [data-toggle-icon='checked']": { + display: "none", + }, + "&.Mui-selected [data-toggle-icon='checked']": { + display: "inline-flex", + }, + "&.Mui-selected [data-toggle-icon='unchecked']": { + display: "none", + }, + "&&.Mui-selected": { + backgroundColor: alpha(activeColor ?? theme.palette.primary.main, 0.5), + }, + }); + +const CustomToggleButton = ({ + children, + activeColor, + showIcon = true, + sx, + tooltip, + ...props +}: CustomToggleButtonProps) => { + const button = ( + + {showIcon && ( + <> + + + + )} + {children} + + ); + + return tooltip ? {button} : button; +}; + +export default CustomToggleButton; diff --git a/src/components/common/customtogglegroup.tsx b/src/components/common/customtogglegroup.tsx new file mode 100644 index 0000000..eff42a7 --- /dev/null +++ b/src/components/common/customtogglegroup.tsx @@ -0,0 +1,25 @@ +import { + alpha, + ToggleButtonGroup, + type ToggleButtonGroupProps, +} from "@mui/material"; +import type { SxProps, Theme } from "@mui/material/styles"; + +const customToggleGroupSx: SxProps = (theme) => ({ + height: 40, + borderRadius: "12px", + "& .MuiToggleButtonGroup-grouped": { + px: 2, + textTransform: "none", + }, +}); + +const CustomToggleGroup = ({ + size = "small", + sx, + ...props +}: ToggleButtonGroupProps) => ( + +); + +export default CustomToggleGroup; diff --git a/src/cosm/vendors/components/locationfilter.tsx b/src/cosm/vendors/components/locationfilter.tsx index fa8c6f6..207ca93 100644 --- a/src/cosm/vendors/components/locationfilter.tsx +++ b/src/cosm/vendors/components/locationfilter.tsx @@ -1,14 +1,16 @@ -import React, { useEffect, useMemo, useState } from "react"; +import React, { useMemo, useState } from "react"; import { alpha, Autocomplete, Box, + createFilterOptions, TextField, Typography, useTheme, type SxProps, type Theme, } from "@mui/material"; +import { RotateCcw } from "lucide-react"; import { formatLocation as formatLocationName, useLocationFormatVersion, @@ -35,6 +37,9 @@ const formatLocation = (option: LocationOption) => option.id === NOT_HORTUS_LOCATION ? option.name || option.id : formatLocationName(option.name, option.id); +const filterOptions = createFilterOptions({ + stringify: formatLocation, +}); const LocationFilter = ({ locations, @@ -51,68 +56,81 @@ const LocationFilter = ({ }) => { const theme = useTheme(); const locationFormatVersion = useLocationFormatVersion(); - const [inputValue, setInputValue] = useState(""); + const [inputValue, setInputValue] = useState(null); + const [open, setOpen] = useState(false); const options = useMemo(() => { - const sortedLocations = [...locations].sort((a, b) => { - if (a.id === HORTUS_LOCATION_CODE) return -1; - if (b.id === HORTUS_LOCATION_CODE) return 1; - return formatLocation(a).localeCompare(formatLocation(b)); - }); - const hortus = sortedLocations.find( + const hortus = locations.find( (location) => location.id === HORTUS_LOCATION_CODE, ); + const otherLocations = locations + .filter((location) => location.id !== HORTUS_LOCATION_CODE) + .sort((a, b) => formatLocation(a).localeCompare(formatLocation(b))); return hortus - ? [ - ALL_LOCATIONS, - hortus, - NOT_HORTUS, - ...sortedLocations.filter((location) => location !== hortus), - ] - : [ALL_LOCATIONS, ...sortedLocations]; + ? [hortus, NOT_HORTUS, ALL_LOCATIONS, ...otherLocations] + : [ALL_LOCATIONS, ...otherLocations]; }, [locationFormatVersion, locations]); - - useEffect(() => { - setInputValue( - value - ? formatLocation( - options.find((option) => option.id === value) || { id: value }, - ) - : "", - ); - }, [options, value]); + const selectedOption = + value === null + ? ALL_LOCATIONS + : options.find((option) => option.id === value) || null; + const selectedLabel = selectedOption + ? formatLocation(selectedOption) + : value || ""; + const canClear = value !== HORTUS_LOCATION_CODE; return ( size="small" + clearIcon={} options={options} - value={ - value ? options.find((option) => option.id === value) || null : null + open={open} + onOpen={() => setOpen(true)} + onClose={() => setOpen(false)} + filterOptions={(locations, state) => + state.inputValue === selectedLabel + ? locations + : filterOptions(locations, state) } - onChange={(_event, option) => { + value={selectedOption} + onChange={(event, option) => { + // MUI also reports erased text as a clear change; only the button resets. + if (!option && event.type !== "click") return; + if (!option) setOpen(false); const nextValue = - option?.id === ALL_LOCATIONS.id ? null : option?.id || null; - setInputValue(nextValue ? formatLocation(option!) : ""); + option?.id === ALL_LOCATIONS.id + ? null + : option?.id || HORTUS_LOCATION_CODE; + setInputValue(null); onChange(nextValue); }} - inputValue={inputValue} + inputValue={inputValue ?? selectedLabel} onInputChange={(_event, nextInputValue, reason) => { - if (reason === "input") setInputValue(nextInputValue); + if (reason !== "input") return; + setInputValue(nextInputValue); }} + onBlur={() => setInputValue(null)} getOptionLabel={formatLocation} isOptionEqualToValue={(option, selected) => option.id === selected.id} - renderOption={(props, option) => ( - - {formatLocation(option)} - - )} + renderOption={(props, option) => { + const { key, ...optionProps } = props; + return ( + + {formatLocation(option)} + + ); + }} slotProps={{ paper: { sx: { @@ -125,8 +143,8 @@ const LocationFilter = ({ sx={[ { "& .MuiAutocomplete-clearIndicator": { - visibility: value ? "visible" : "hidden", - opacity: value ? 1 : 0, + visibility: canClear ? "visible" : "hidden", + opacity: canClear ? 1 : 0, }, "& .MuiOutlinedInput-root": { height: 40, @@ -146,7 +164,7 @@ const LocationFilter = ({ ...(Array.isArray(sx) ? sx : sx ? [sx] : []), ]} renderInput={(params) => ( - + )} /> ); diff --git a/src/cosm/vendors/components/locationicon.tsx b/src/cosm/vendors/components/locationicon.tsx new file mode 100644 index 0000000..d86e9bb --- /dev/null +++ b/src/cosm/vendors/components/locationicon.tsx @@ -0,0 +1,14 @@ +import { useTheme } from "@mui/material"; +import { Globe, Warehouse } from "lucide-react"; + +const LocationIcon = ({ locationCode }: { locationCode?: string }) => { + const theme = useTheme(); + + return locationCode === "HRT" ? ( + + ) : ( + + ); +}; + +export default LocationIcon; diff --git a/src/cosm/vendors/shoppinglistmodal.tsx b/src/cosm/vendors/shoppinglistmodal.tsx index 2d0ac7a..da747bc 100644 --- a/src/cosm/vendors/shoppinglistmodal.tsx +++ b/src/cosm/vendors/shoppinglistmodal.tsx @@ -35,8 +35,6 @@ import { ArrowUp, ArrowDown, Store, - Warehouse, - Globe, FileUp, } from "lucide-react"; import { ContentCopy } from "@mui/icons-material"; @@ -58,6 +56,7 @@ import LocationFilter, { import InlineConfirmButton from "../components/inlineconfirmbutton"; import { Modal } from "./modal"; import VendorLastActiveIndicator from "./components/vendorlastactiveindicator"; +import LocationIcon from "./components/locationicon"; import { useGlobalData } from "../../context/globaldatacontext"; import { formatLocation as formatLocationLabel, @@ -388,17 +387,7 @@ const VendorPrioritySelector: React.FC<{ {location ? ( <> - {location.location_code === "HRT" ? ( - - ) : ( - - )}{" "} + {" "} {formatLocationLabel( location.location_name || location.location_code || @@ -730,17 +719,9 @@ const CompactListItem: React.FC<{ key={location.label} sx={{ whiteSpace: "nowrap" }} > - {location.isHortus ? ( - - ) : ( - - )}{" "} + {" "} {location.label} , " ", @@ -1059,17 +1040,7 @@ const OrderSummaryPanel: React.FC<{ mb: 0.75, }} > - {location?.location_code === "HRT" ? ( - - ) : ( - - )} + {formatLocationLabel(locationName, locationCode)} diff --git a/src/cosm/vendors/vendorlist.tsx b/src/cosm/vendors/vendorlist.tsx index 952dc81..b63244c 100644 --- a/src/cosm/vendors/vendorlist.tsx +++ b/src/cosm/vendors/vendorlist.tsx @@ -6,6 +6,8 @@ import React, { useCallback, } from "react"; import { API_BASE_URL } from "../../config/api"; +import CustomToggleGroup from "../../components/common/customtogglegroup"; +import CustomToggleButton from "../../components/common/customtogglebutton"; import { Masonry } from "@mui/lab"; import { DataGrid, type GridColDef } from "@mui/x-data-grid"; import { @@ -14,8 +16,6 @@ import { Chip, TextField, InputAdornment, - ToggleButton, - ToggleButtonGroup, Card, CardContent, Divider, @@ -26,17 +26,7 @@ import { Button, alpha, } from "@mui/material"; -import { - Search, - MapPin, - Warehouse, - Globe, - Minus, - Square, - SquareCheck, - Target, - X, -} from "lucide-react"; +import { Search, MapPin, Minus, Target, X } from "lucide-react"; import CenterFocusStrongIcon from "@mui/icons-material/CenterFocusStrong"; import VendorCreationModal from "./createvendorstoremodal"; import EditVendorStoreModal from "./editvendorstoremodal"; @@ -52,6 +42,7 @@ import { } from "./utils/formatlocation"; import { pickPrice } from "./utils/pickprice"; import VendorLastActiveIndicator from "./components/vendorlastactiveindicator"; +import LocationIcon from "./components/locationicon"; import LocationFilter, { ALL_LOCATIONS_ID, HORTUS_LOCATION_CODE, @@ -279,15 +270,15 @@ const PriceComparisonBadge = ({ const ChipSmall = ({ text, - colour, + color, tooltip, }: { text: string; - colour?: string; + color?: string; tooltip?: React.ReactNode; }) => { const theme = useTheme(); - const badgeColour = colour ?? theme.palette.primary.light; + const badgeColor = color ?? theme.palette.primary.light; const badge = ( { return ( ); @@ -346,7 +337,7 @@ const ChipBid = () => { return ( ); @@ -529,6 +520,12 @@ const VendorCard = React.memo( className={isUnavailable ? "unavailable-order" : undefined} sx={{ p: 0, + backgroundColor: alpha( + isBuying + ? theme.palette.info.light + : theme.palette.warning.light, + 0.06, + ), borderBottom: index === sortedList.length - 1 ? "none" @@ -538,10 +535,6 @@ const VendorCard = React.memo( display: "flex", flexDirection: "column", gap: 0.5, - cursor: "default", - "&:hover": { - backgroundColor: alpha(theme.palette.primary.main, 0.2), - }, }} > {/* Main Row: Ticker, Price */} @@ -634,17 +627,9 @@ const VendorCard = React.memo( gap: 0.5, }} > - {l.location_code === "HRT" ? ( - - ) : ( - - )} + ( - {row.locCode === "HRT" ? ( - - ) : ( - - )} + {row.locCode === HORTUS_LOCATION_CODE @@ -1398,18 +1373,23 @@ const VendorsList = ({ disableRowSelectionOnClick localeText={{ noRowsLabel: "No results" }} getRowClassName={({ row }) => - row.quantity === 0 ? "unavailable-order" : "" + `${row.orderType === "sell" ? "ask-order" : "bid-order"}${ + row.quantity === 0 ? " unavailable-order" : "" + }` } sx={{ border: "none", "& .MuiDataGrid-row": { borderBottom: `1px solid ${alpha(theme.palette.divider, 0.05)}`, - "&:hover": { - backgroundColor: alpha(theme.palette.primary.main, 0.2), - }, display: "flex", alignItems: "center", }, + "& .MuiDataGrid-row.ask-order": { + backgroundColor: alpha(theme.palette.warning.light, 0.05), + }, + "& .MuiDataGrid-row.bid-order": { + backgroundColor: alpha(theme.palette.info.light, 0.05), + }, "& .MuiDataGrid-cell": { borderBottom: "none", display: "flex", @@ -1562,7 +1542,7 @@ const VendorsList = ({ display: "flex", }} > - { @@ -1570,52 +1550,26 @@ const VendorsList = ({ handleViewModeChange(newValue); } }} - size="small" aria-label="Vendor view mode" - sx={{ - height: 40, - borderRadius: "12px", - "& .MuiToggleButtonGroup-grouped": { - "&:hover": { - background: alpha(theme.palette.primary.main, 0.5), - }, - "&.Mui-selected": { - background: alpha( - theme.palette.background.default, - 0.8, - ), - color: theme.palette.primary.light, - pointerEvents: "none", - "&:hover": { - background: alpha( - theme.palette.background.default, - 0.9, - ), - }, - }, - }, - }} > - - Grid - - Table - - + + + Grid + + - { if (newValue) setOrderTypeFilter(newValue); }} - size="small" aria-label="Order type filter" - sx={{ - height: 40, - borderRadius: "12px", - "& .MuiToggleButtonGroup-grouped": { - "&:hover": { - background: alpha(theme.palette.primary.main, 0.5), - }, - "&.Mui-selected": { - background: alpha( - theme.palette.background.default, - 0.8, - ), - color: theme.palette.primary.light, - "&:hover": { - background: alpha( - theme.palette.background.default, - 1, - ), - }, - }, - }, - }} > - - - All - - - - - Ask - - - - - Bid - - - + + Ask + + + Bid + + + All + + - - setHideUnavailable((prev) => !prev)} - aria-label="Hide Unavailable" - sx={{ - height: 40, - px: 1.5, - textTransform: "none", - gap: 0.5, - whiteSpace: "nowrap", - "&.Mui-selected": { - color: theme.palette.primary.light, - backgroundColor: "transparent", - "&:hover": { backgroundColor: "transparent" }, - }, - }} - > - {hideUnavailable ? ( - - ) : ( - - )} - Hide Unavailable - - + setHideUnavailable((prev) => !prev)} + tooltip="Hide materials if vendor has/wants 0" + aria-label="Hide Unavailable" + > + Hide Unavailable + diff --git a/src/dashboard/corporation/corporationoverview.tsx b/src/dashboard/corporation/corporationoverview.tsx index 92fb2d2..08568fc 100644 --- a/src/dashboard/corporation/corporationoverview.tsx +++ b/src/dashboard/corporation/corporationoverview.tsx @@ -318,8 +318,7 @@ export const CorporationOverview: React.FC = () => { fuelConfigs.forEach((cfg) => { const activeFuelConsumers: ProducerConsumerItem[] = fuelData - .consumers! - .filter((c) => cfg.getMemberTotal(c) > 0) + .consumers!.filter((c) => cfg.getMemberTotal(c) > 0) .map((c) => ({ player: c.player_name, loc: "Fleet", @@ -368,8 +367,7 @@ export const CorporationOverview: React.FC = () => { 0, ); item.consumptionTotal = nonFleetCons + fleetCons; - item.consumptionAccurate = - (item.consumptionAccurate || 0) + fleetCons; + item.consumptionAccurate = (item.consumptionAccurate || 0) + fleetCons; item.consumption = item.consumptionTotal; item.net = (item.productionTotal || 0) - item.consumptionTotal; });