Skip to content
Snippets Groups Projects
Unverified Commit f8dfa5a6 authored by Matiss Janis Aboltins's avatar Matiss Janis Aboltins Committed by GitHub
Browse files

:bug: disable 'all payees' checkbox while schedules are loading (#1136)

Closes #1125

Disables (hides) the "all payees" checkbox when schedules are loading.

Reproduction:
1. open `/schedule/discover`
2. while the data is still loading - click on the checkbox in the table
header
3. after loading finishes - the page crashes with an error
parent 9aea091f
No related branches found
No related tags found
No related merge requests found
import React, { useState, useEffect } from 'react'; import React, { useState } from 'react';
import { useHistory } from 'react-router-dom'; import { useHistory } from 'react-router-dom';
import q, { runQuery } from 'loot-core/src/client/query-helpers'; import q, { runQuery } from 'loot-core/src/client/query-helpers';
...@@ -10,6 +10,7 @@ import useSelected, { ...@@ -10,6 +10,7 @@ import useSelected, {
useSelectedItems, useSelectedItems,
SelectedProvider, SelectedProvider,
} from '../../hooks/useSelected'; } from '../../hooks/useSelected';
import useSendPlatformRequest from '../../hooks/useSendPlatformRequest';
import { colors } from '../../style'; import { colors } from '../../style';
import { View, Stack, ButtonWithLoading, P } from '../common'; import { View, Stack, ButtonWithLoading, P } from '../common';
import { Page, usePageType } from '../Page'; import { Page, usePageType } from '../Page';
...@@ -73,7 +74,7 @@ function DiscoverSchedulesTable({ schedules, loading }) { ...@@ -73,7 +74,7 @@ function DiscoverSchedulesTable({ schedules, loading }) {
<View style={{ flex: 1 }}> <View style={{ flex: 1 }}>
<TableHeader height={ROW_HEIGHT} inset={15} version="v2"> <TableHeader height={ROW_HEIGHT} inset={15} version="v2">
<SelectCell <SelectCell
exposed={true} exposed={!loading}
focused={false} focused={false}
selected={selectedItems.size > 0} selected={selectedItems.size > 0}
onSelect={e => dispatchSelected({ type: 'select-all', event: e })} onSelect={e => dispatchSelected({ type: 'select-all', event: e })}
...@@ -109,18 +110,12 @@ function DiscoverSchedulesTable({ schedules, loading }) { ...@@ -109,18 +110,12 @@ function DiscoverSchedulesTable({ schedules, loading }) {
export default function DiscoverSchedules() { export default function DiscoverSchedules() {
let pageType = usePageType(); let pageType = usePageType();
let history = useHistory(); let history = useHistory();
let [schedules, setSchedules] = useState(); let { data: schedules = [], isLoading } =
useSendPlatformRequest('schedule/discover');
let [creating, setCreating] = useState(false); let [creating, setCreating] = useState(false);
let selectedInst = useSelected('discover-schedules', schedules, []); let selectedInst = useSelected('discover-schedules', schedules, []);
useEffect(() => {
async function run() {
setSchedules(await send('schedule/discover'));
}
run();
}, []);
async function onCreate() { async function onCreate() {
let selected = schedules.filter(s => selectedInst.items.has(s.id)); let selected = schedules.filter(s => selectedInst.items.has(s.id));
setCreating(true); setCreating(true);
...@@ -165,10 +160,7 @@ export default function DiscoverSchedules() { ...@@ -165,10 +160,7 @@ export default function DiscoverSchedules() {
</P> </P>
<SelectedProvider instance={selectedInst}> <SelectedProvider instance={selectedInst}>
<DiscoverSchedulesTable <DiscoverSchedulesTable loading={isLoading} schedules={schedules} />
loading={schedules == null}
schedules={schedules}
/>
</SelectedProvider> </SelectedProvider>
<Stack <Stack
......
import { useEffect, useState } from 'react';
import { send } from 'loot-core/src/platform/client/fetch';
import type { Handlers } from 'loot-core/src/types/handlers';
export default function useSendPlatformRequest<K extends keyof Handlers>(
name: K,
args?: Parameters<Handlers[K]>[0],
options?: { catchErrors?: boolean },
) {
const [data, setData] = useState<unknown>(null);
const [isLoading, setIsLoading] = useState<boolean | null>(null);
useEffect(() => {
async function run() {
setIsLoading(true);
setData(await send(name, args, options));
setIsLoading(false);
}
run();
}, [name, args, options]);
return {
data,
isLoading,
};
}
---
category: Bugfix
authors: [MatissJanis]
---
Fix "find schedules" page crashing if interction is made before loading data finishes
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment