Skip to content

Commit

Permalink
fix: bugs caused by missing defaults on home page form upload
Browse files Browse the repository at this point in the history
  • Loading branch information
aalemayhu committed May 26, 2024
1 parent 8cd8f43 commit 1bf1dc9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/components/modals/SettingsModal/SettingsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { getSettingsCardOptions } from '../../../lib/backend/getSettingsCardOpti
import { getLocalStorageBooleanValue } from '../../../lib/data_layer/getLocalStorageBooleanValue';
import CardOption from '../../../lib/data_layer/model/CardOption';
import { getVisibleText } from '../../../lib/text/getVisibleText';
import { useSettingsCardsOptions } from './useSettingsCardsOptions';

interface Props {
pageTitle?: string;
Expand All @@ -36,13 +37,7 @@ function SettingsModal({
onClickClose,
setError
}: Props) {
const { isLoading, isError, data: options, error: loadingDefaultsError } = useQuery(
`cardOptions-${pageId ?? 'default'}`, // pageId will invalidate the cache
getSettingsCardOptions,
{
staleTime: FIFTEEN_MINUTES
}
);
const { isLoading, isError, options, loadingDefaultsError } = useSettingsCardsOptions(pageId);
const [settings, setSettings] = useState<SettingsPayload>({});
const [loading, setLoading] = useState(!!pageId);
const deckNameKey = 'deckName';
Expand Down
15 changes: 15 additions & 0 deletions src/components/modals/SettingsModal/useSettingsCardsOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useQuery } from 'react-query';
import { getSettingsCardOptions } from '../../../lib/backend/getSettingsCardOptions';
import { FIFTEEN_MINUTES } from './constants';

export const useSettingsCardsOptions = (pageId: string | null) => {
const { isLoading, isError, data: options, error: loadingDefaultsError } = useQuery(
`cardOptions-${pageId ?? 'default'}`, // pageId will invalidate the cache
getSettingsCardOptions,
{
staleTime: FIFTEEN_MINUTES
}
);

return { isLoading, isError, options, loadingDefaultsError };
};
4 changes: 4 additions & 0 deletions src/pages/HomePage/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ import UploadForm from '../UploadPage/components/UploadForm/UploadForm';
import { ErrorHandlerType } from '../../components/errors/helpers/getErrorMessage';
import { FormSection } from './components/Sections/hero/styled';
import TierSection from './components/Sections/tier/TierSection';
import { useSettingsCardsOptions } from '../../components/modals/SettingsModal/useSettingsCardsOptions';

interface HomePageProps {
setErrorMessage: ErrorHandlerType;
}

export function HomePage({ setErrorMessage }: Readonly<HomePageProps>) {
// Load the default settings cards options for backend compatibility
useSettingsCardsOptions(null);

return (
<HomeContainer>
<HeroSection />
Expand Down

0 comments on commit 1bf1dc9

Please sign in to comment.