Skip to content

Commit

Permalink
style: clean up imports
Browse files Browse the repository at this point in the history
  • Loading branch information
ayuhito committed Jul 9, 2024
1 parent 79c37bd commit 45560e0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
37 changes: 14 additions & 23 deletions dashboard/app/components/DropdownSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ interface DropdownSelectBase {
defaultValue: string;
defaultLabel: string;
selectAriaLabel: string;

records: Record<string, string>;
groupEndValues?: string[];

leftSection?: React.ReactNode;
}

Expand Down Expand Up @@ -42,28 +40,23 @@ export const DropdownSelect = (props: DropdownSelectProps) => {
leftSection,
} = props;

const combobox = useCombobox({
onDropdownClose: () => {
combobox.resetSelectedOption();
},
onDropdownOpen: (eventSource) => {
if (eventSource === 'keyboard') {
combobox.selectActiveOption();
} else {
combobox.updateSelectedOptionIndex('active');
}
},
});

const [searchParams, setSearchParams] = useSearchParams();
const navigate = useNavigate();

const [option, setOption] = useState<string>(
isSearchParams(props)
? searchParams.get(props.searchParamKey) || defaultValue
? searchParams.get(props.searchParamKey) ?? defaultValue
: defaultValue,
);

const combobox = useCombobox({
onDropdownClose: () => combobox.resetSelectedOption(),
onDropdownOpen: (eventSource) => {
eventSource === 'keyboard'
? combobox.selectActiveOption()
: combobox.updateSelectedOptionIndex('active');
},
});

useDidUpdate(() => {
if (isSearchParams(props)) {
setSearchParams((prevParams) => {
Expand All @@ -72,18 +65,16 @@ export const DropdownSelect = (props: DropdownSelectProps) => {
return newParams;
});
} else {
navigate(`/${option}`, {
relative: 'route',
});
navigate(`/${option}`, { relative: 'route' });
}
}, [option]);
}, [option, props, navigate, setSearchParams]);

const handleOptionSubmit = useCallback(
(value: string) => {
setOption(value);
combobox.toggleDropdown();
},
[combobox.toggleDropdown],
[combobox],
);

const options = useMemo(
Expand Down Expand Up @@ -124,7 +115,7 @@ export const DropdownSelect = (props: DropdownSelectProps) => {
leftSection={leftSection}
data-left={Boolean(leftSection)}
>
{records[option] || defaultLabel}
{records[option] ?? defaultLabel}
</InputBase>
</Combobox.Target>
<Combobox.Dropdown>
Expand Down
2 changes: 1 addition & 1 deletion dashboard/app/components/stats/StatsHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Tooltip,
UnstyledButton,
} from '@mantine/core';
import { useMediaQuery } from '@mantine/hooks';
import { useState } from 'react';
import { ScrollContainer } from 'react-indiana-drag-scroll';

Expand All @@ -19,7 +20,6 @@ import { HeaderDataBox } from './HeaderDataBox';
import type { ChartType, StatHeaderData } from './types';

import classes from './StatsHeader.module.css';
import { useMediaQuery } from '@mantine/hooks';

interface StatsHeaderProps {
stats: StatHeaderData[];
Expand Down

0 comments on commit 45560e0

Please sign in to comment.