Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Collapsable historical picker #6911

Draft
wants to merge 28 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a121b6f
WIP: Collapsable historical picker
VIKTORVAV99 Jun 28, 2024
fee034e
pnpm dedupe
VIKTORVAV99 Jun 28, 2024
aff5477
add accordion
VIKTORVAV99 Jun 28, 2024
838d6c4
Merge remote-tracking branch 'origin/master' into vik/avo-357-collaps…
VIKTORVAV99 Jun 29, 2024
67b91a0
simplify and optimize code
VIKTORVAV99 Jun 29, 2024
bac1f54
add transparent background
VIKTORVAV99 Jun 29, 2024
c71f041
change selector style
VIKTORVAV99 Jun 29, 2024
bd66746
ensure no CLS
VIKTORVAV99 Jun 29, 2024
af0d7b4
change style of ticks
VIKTORVAV99 Jun 29, 2024
8c5371b
remove accidental file duplication
VIKTORVAV99 Jul 1, 2024
3d30590
Show 'Latest' instead of 'LIVE'
VIKTORVAV99 Jul 1, 2024
5525589
merge master
VIKTORVAV99 Jul 1, 2024
a37297f
add success state to badge
VIKTORVAV99 Jul 1, 2024
85e2021
add colors to tailwind config
VIKTORVAV99 Jul 1, 2024
be2a06e
use the same color for latest
VIKTORVAV99 Jul 1, 2024
2d7e725
Merge remote-tracking branch 'origin/master' into vik/avo-357-collaps…
VIKTORVAV99 Jul 1, 2024
40eaf88
add atoms to persist state
VIKTORVAV99 Jul 2, 2024
98a4268
update atom types
VIKTORVAV99 Jul 2, 2024
cda8488
set default based on isMobile
VIKTORVAV99 Jul 2, 2024
5004bdc
Merge branch 'master' into vik/avo-357-collapsable-historical-picker
VIKTORVAV99 Jul 2, 2024
6bd9ed3
fix E2E test
VIKTORVAV99 Jul 2, 2024
ce8f864
style tweaks
VIKTORVAV99 Jul 2, 2024
9763bfe
use fa icons and adjust tests
VIKTORVAV99 Jul 2, 2024
6c7c41b
clean up types
VIKTORVAV99 Jul 2, 2024
7fe3fa5
fix some more styles
VIKTORVAV99 Jul 2, 2024
a7f149a
use rounded-2xl to match cards
VIKTORVAV99 Jul 2, 2024
25cb917
Code cleanup and Story additions
VIKTORVAV99 Jul 3, 2024
6effa26
Merge remote-tracking branch 'origin/master' into vik/avo-357-collaps…
VIKTORVAV99 Jul 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Code cleanup and Story additions
  • Loading branch information
VIKTORVAV99 committed Jul 3, 2024
commit 25cb917baaa2fd6296b69060e296037b1b734df4
4 changes: 2 additions & 2 deletions web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const MapOverlays = lazy(() => import('components/MapOverlays'));
const FAQModal = lazy(() => import('features/modals/FAQModal'));
const InfoModal = lazy(() => import('features/modals/InfoModal'));
const SettingsModal = lazy(() => import('features/modals/SettingsModal'));
const TimeControllerWrapper = lazy(() => import('features/time/TimeControllerWrapper'));
const TimeController = lazy(() => import('features/time/TimeController'));
const AnnouncementModal = lazy(() => import('features/modals/AnnouncementModal'));

const isProduction = import.meta.env.PROD;
Expand Down Expand Up @@ -89,7 +89,7 @@ export default function App(): ReactElement {
<MapWrapper />
</Suspense>
<Suspense>
<TimeControllerWrapper />
<TimeController />
</Suspense>
<Suspense>
<MapOverlays />
Expand Down
53 changes: 53 additions & 0 deletions web/src/components/Badge.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import type { Meta, StoryObj } from '@storybook/react';

import Badge from './Badge';

const meta: Meta<typeof Badge> = {
title: 'Basics/Badge',
component: Badge,
decorators: [
(Story) => (
<div className="flex">
<Story />
</div>
),
],
argTypes: {
type: {
control: {
type: 'select',
options: ['default', 'success', 'warning'],
labels: {
default: 'Default',
success: 'Success',
warning: 'Warning',
},
},
},
},
args: {
pillText: 'Badge',
type: 'default',
},
};

export default meta;
type Story = StoryObj<typeof Badge>;

export const Default: Story = {
name: 'Default Badge',
};

export const Success: Story = {
name: 'Success Badge',
args: {
type: 'success',
},
};

export const Warning: Story = {
name: 'Warning Badge',
args: {
type: 'warning',
},
};
40 changes: 40 additions & 0 deletions web/src/components/TimeAverageToggle.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import type { Meta, StoryObj } from '@storybook/react';
import { TimeAverages } from 'utils/constants';

import TimeAverageToggle from './TimeAverageToggle';

const meta = {
component: TimeAverageToggle,
title: 'Toggles/TimeAverageToggle',
args: {
onToggleGroupClick: () => {},
},
} satisfies Meta<typeof TimeAverageToggle>;

export default meta;

type Story = StoryObj<typeof meta>;

export const Hourly: Story = {
args: {
timeAverage: TimeAverages.HOURLY,
},
};

export const Daily: Story = {
args: {
timeAverage: TimeAverages.DAILY,
},
};

export const Monthly: Story = {
args: {
timeAverage: TimeAverages.MONTHLY,
},
};

export const Yearly: Story = {
args: {
timeAverage: TimeAverages.YEARLY,
},
};
6 changes: 3 additions & 3 deletions web/src/features/time/TimeBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import { useTranslation } from 'react-i18next';
import { formatDate } from 'utils/formatting';
import { selectedDatetimeIndexAtom, timeAverageAtom } from 'utils/state/atoms';

export default function TimeHeader() {
export default function TimeBadge() {
const { i18n } = useTranslation();
const [timeAverage] = useAtom(timeAverageAtom);
const [selectedDatetime] = useAtom(selectedDatetimeIndexAtom);
const { isLoading } = useGetState();

const date = formatDate(
const formattedDate = formatDate(
new Date(selectedDatetime.datetimeString),
i18n.language,
timeAverage
);

return !isLoading && <Badge pillText={date} type="success" />;
return !isLoading && <Badge pillText={formattedDate} type="success" />;
}
29 changes: 25 additions & 4 deletions web/src/features/time/TimeController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import trackEvent from 'utils/analytics';
import { TimeAverages } from 'utils/constants';
import { dateToDatetimeString } from 'utils/helpers';
import { selectedDatetimeIndexAtom, timeAverageAtom } from 'utils/state/atoms';
import { useIsMobile } from 'utils/styling';
import { useIsBiggerThanMobile, useIsMobile } from 'utils/styling';

import TimeAxis from './TimeAxis';
import TimeHeader from './TimeBadge';
import TimeBadge from './TimeBadge';

const timeControllerCollapsedAtom = atomWithStorage<boolean | null>(
'timeControllerCollapsed',
null
);

export default function TimeController({ className }: { className?: string }) {
function InternalTimeController({ className }: { className?: string }) {
const { t } = useTranslation();
const isMobile = useIsMobile();
const [timeControllerCollapsed, setTimeControllerCollapsed] = useAtom(
Expand Down Expand Up @@ -85,7 +85,7 @@ export default function TimeController({ className }: { className?: string }) {
<div className={className}>
<Accordion
title={t('time-controller.title')}
badge={<TimeHeader />}
badge={<TimeBadge />}
isOnTop
isCollapsedAtom={timeControllerCollapsedAtom}
>
Expand All @@ -110,3 +110,24 @@ export default function TimeController({ className }: { className?: string }) {
</div>
);
}

function FloatingTimeController() {
return (
<div className="fixed bottom-3 left-3 z-20 w-[calc(14vw_+_16rem)] rounded-2xl bg-white/80 px-4 py-3 shadow-xl drop-shadow-2xl backdrop-blur min-[780px]:w-[calc((14vw_+_16rem)_-_30px)] xl:px-5 dark:bg-gray-800/80">
<InternalTimeController />
</div>
);
}

function FixedTimeController() {
return (
<div className="fixed bottom-0 left-0 right-0 z-20 w-full border-t border-neutral-200 bg-white/80 px-4 py-3 backdrop-blur dark:border-gray-700 dark:bg-gray-800/80">
<InternalTimeController />
</div>
);
}

export default function TimeController() {
const isBiggerThanMobile = useIsBiggerThanMobile();
return isBiggerThanMobile ? <FloatingTimeController /> : <FixedTimeController />;
}
24 changes: 0 additions & 24 deletions web/src/features/time/TimeControllerWrapper.tsx

This file was deleted.

Loading