Skip to content

Commit

Permalink
fix: use hostname param for default state
Browse files Browse the repository at this point in the history
  • Loading branch information
ayuhito committed Jul 9, 2024
1 parent 45560e0 commit 91a9e94
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions dashboard/app/components/DropdownSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ export const DropdownSelect = (props: DropdownSelectProps) => {
} else {
navigate(`/${option}`, { relative: 'route' });
}
}, [option, props, navigate, setSearchParams]);
}, [option]);

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

const options = useMemo(
Expand Down
4 changes: 3 additions & 1 deletion dashboard/app/components/stats/StatsHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
UnstyledButton,
} from '@mantine/core';
import { useMediaQuery } from '@mantine/hooks';
import { useParams } from '@remix-run/react';
import { useState } from 'react';
import { ScrollContainer } from 'react-indiana-drag-scroll';

Expand Down Expand Up @@ -105,6 +106,7 @@ const SegmentedChartControl = () => {
};

const StatsHeader = ({ stats, chart, websites }: StatsHeaderProps) => {
const { hostname } = useParams();
const hideWebsiteSelector = useMediaQuery('(36em < width < 62em)');
// Convert websites array to object with same key-val for DropdownSelect
const websitesRecord = Object.fromEntries(
Expand All @@ -119,7 +121,7 @@ const StatsHeader = ({ stats, chart, websites }: StatsHeaderProps) => {
{!hideWebsiteSelector && (
<DropdownSelect
records={websitesRecord}
defaultValue={websites[0] ?? ''}
defaultValue={hostname ?? ''}
defaultLabel="Unknown"
selectAriaLabel="Select website"
type="link"
Expand Down

0 comments on commit 91a9e94

Please sign in to comment.