Skip to content

Commit

Permalink
Do not crash if color is not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
thaapasa committed Mar 3, 2024
1 parent 79cb7e5 commit 16d21f4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/client/ui/Colors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { amber, grey, lime, teal } from '@mui/material/colors';
import { SimplePaletteColorOptions, styled } from '@mui/material/styles';
import { getLuminance, SimplePaletteColorOptions, styled } from '@mui/material/styles';

import { Money, MoneyLike } from 'shared/util';

Expand Down Expand Up @@ -119,3 +119,11 @@ export function classNameForMoney(m?: MoneyLike): 'positive' | 'negative' | 'uni
export const unused = styled('div')`
width: 100%;
`;

export function getLuminanceSafe(color: string): number {
try {
return getLuminance(color);
} catch (e) {
return 0;
}
}
5 changes: 3 additions & 2 deletions src/client/ui/grouping/GroupedExpenseIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import styled from '@emotion/styled';
import { colors, getLuminance } from '@mui/material';
import { colors } from '@mui/material';
import * as React from 'react';

import { ExpenseGroupingRef } from 'shared/types';

import { getLuminanceSafe } from '../Colors';
import { Bookmark } from '../icons/Bookmark';

type GroupedExpenseIconProps = {
Expand All @@ -20,7 +21,7 @@ export const GroupedExpenseIcon: React.FC<GroupedExpenseIconProps> = ({
className,
}) => {
const color = grouping.color ?? colors.blue[300];
const luminance = getLuminance(color);
const luminance = getLuminanceSafe(color);

return (
<IconContainer title={grouping.title} onClick={onClick} className={className}>
Expand Down

0 comments on commit 16d21f4

Please sign in to comment.