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

:recycle: (reports) improve useReports data fetching hook to return loading state (#3198)

parent d2bbe6a9
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,7 @@ export function ReportAutocomplete({ ...@@ -14,7 +14,7 @@ export function ReportAutocomplete({
embedded, embedded,
...props ...props
}: ReportAutocompleteProps) { }: ReportAutocompleteProps) {
const reports = useReports() || []; const { data: reports } = useReports();
return ( return (
<Autocomplete <Autocomplete
......
...@@ -21,7 +21,7 @@ import { NetWorthCard } from './reports/NetWorthCard'; ...@@ -21,7 +21,7 @@ import { NetWorthCard } from './reports/NetWorthCard';
import { SpendingCard } from './reports/SpendingCard'; import { SpendingCard } from './reports/SpendingCard';
export function Overview() { export function Overview() {
const customReports = useReports(); const { data: customReports } = useReports();
const { isNarrowWidth } = useResponsive(); const { isNarrowWidth } = useResponsive();
const location = useLocation(); const location = useLocation();
......
...@@ -34,7 +34,7 @@ export function SaveReport({ ...@@ -34,7 +34,7 @@ export function SaveReport({
savedStatus, savedStatus,
onReportChange, onReportChange,
}: SaveReportProps) { }: SaveReportProps) {
const listReports = useReports(); const { data: listReports } = useReports();
const triggerRef = useRef(null); const triggerRef = useRef(null);
const [deleteMenuOpen, setDeleteMenuOpen] = useState(false); const [deleteMenuOpen, setDeleteMenuOpen] = useState(false);
const [nameMenuOpen, setNameMenuOpen] = useState(false); const [nameMenuOpen, setNameMenuOpen] = useState(false);
......
...@@ -34,7 +34,7 @@ export function GenericInput({ ...@@ -34,7 +34,7 @@ export function GenericInput({
onChange, onChange,
}) { }) {
const { grouped: categoryGroups } = useCategories(); const { grouped: categoryGroups } = useCategories();
const savedReports = useReports(); const { data: savedReports } = useReports();
const saved = useSelector(state => state.queries.saved); const saved = useSelector(state => state.queries.saved);
const dateFormat = useDateFormat() || 'MM/dd/yyyy'; const dateFormat = useDateFormat() || 'MM/dd/yyyy';
......
...@@ -35,9 +35,10 @@ function toJS(rows: CustomReportData[]) { ...@@ -35,9 +35,10 @@ function toJS(rows: CustomReportData[]) {
return reports; return reports;
} }
export function useReports(): CustomReportEntity[] { export function useReports() {
const reports: CustomReportEntity[] = toJS( const queryData = useLiveQuery<CustomReportData[]>(
useLiveQuery(() => q('custom_reports').select('*'), []) || [], () => q('custom_reports').select('*'),
[],
); );
// Sort reports by alphabetical order // Sort reports by alphabetical order
...@@ -51,5 +52,11 @@ export function useReports(): CustomReportEntity[] { ...@@ -51,5 +52,11 @@ export function useReports(): CustomReportEntity[] {
); );
} }
return useMemo(() => sort(reports), [reports]); return useMemo(
() => ({
isLoading: queryData === null,
data: sort(toJS(queryData || [])),
}),
[queryData],
);
} }
---
category: Maintenance
authors: [MatissJanis]
---
Reports: improve `useReports` data fetching hook to return the loading state.
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