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

feat: add functionality to specify whether a filter that should be initially checked. #240

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
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
14 changes: 13 additions & 1 deletion src/page-modules/assistant/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ import { PageText, useTranslation } from '@atb/translations';
import { FocusScope } from '@react-aria/focus';
import { AnimatePresence, motion } from 'framer-motion';
import { useRouter } from 'next/router';
import { FormEventHandler, PropsWithChildren, useState } from 'react';
import {
FormEventHandler,
PropsWithChildren,
useEffect,
useState,
} from 'react';
import style from './assistant.module.css';
import { FromToTripQuery } from './types';
import { createTripQuery } from './utils';
Expand Down Expand Up @@ -54,6 +59,13 @@ function AssistantLayout({ children, tripQuery }: AssistantLayoutProps) {
getTransportModeFilter,
);

useEffect(() => {
tripQuery.transportModeFilter =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe setValuesWithLoading() should be used here as well? Like we looked at some time ago with some other changes. Or maybe not? I guess if the setValuesWithLoading is used we get an (possibly) unwanted route change.

And it's important to check whether transportModeFilter is set already, then the isUncheckedByDefault should not be taken into account and the filter should remain as is, since there's a chance the user has set the filters themselves. Haven't tested this code, but that might be how this works with the optional chaining and nullish coalescing.

transportModeFilter
?.filter((filter: any) => !filter.isUncheckedByDefault)
.map((filter: any) => filter.id) ?? null;
}, [transportModeFilter]);

const setValuesWithLoading = async (
override: Partial<FromToTripQuery>,
replace = false,
Expand Down
Loading