Table length checking if data is already set

This commit is contained in:
Nick Sandstrom 2025-12-19 19:19:04 -08:00
parent 63daa3ddf2
commit 1029eb5b5c

View file

@ -1,4 +1,10 @@
import React, { useEffect, useMemo, useState, useCallback } from 'react'; import React, {
useEffect,
useMemo,
useState,
useCallback,
useRef,
} from 'react';
import useChannelsStore from '../../store/channels'; import useChannelsStore from '../../store/channels';
import useLogosStore from '../../store/logos'; import useLogosStore from '../../store/logos';
import { notifications } from '@mantine/notifications'; import { notifications } from '@mantine/notifications';
@ -289,7 +295,6 @@ const ChannelsTable = ({}) => {
const [selectedProfile, setSelectedProfile] = useState( const [selectedProfile, setSelectedProfile] = useState(
profiles[selectedProfileId] profiles[selectedProfileId]
); );
const [hasFetchedData, setHasFetchedData] = useState(false);
const [showDisabled, setShowDisabled] = useState(true); const [showDisabled, setShowDisabled] = useState(true);
const [showOnlyStreamlessChannels, setShowOnlyStreamlessChannels] = const [showOnlyStreamlessChannels, setShowOnlyStreamlessChannels] =
useState(false); useState(false);
@ -311,6 +316,8 @@ const ChannelsTable = ({}) => {
const [isBulkDelete, setIsBulkDelete] = useState(false); const [isBulkDelete, setIsBulkDelete] = useState(false);
const [channelToDelete, setChannelToDelete] = useState(null); const [channelToDelete, setChannelToDelete] = useState(null);
const hasFetchedData = useRef(false);
// Column sizing state for resizable columns // Column sizing state for resizable columns
// Store in localStorage but with empty object as default // Store in localStorage but with empty object as default
const [columnSizing, setColumnSizing] = useLocalStorage( const [columnSizing, setColumnSizing] = useLocalStorage(
@ -365,7 +372,8 @@ const ChannelsTable = ({}) => {
}); });
}); });
const channelsTableLength = hasFetchedData ? Object.keys(data).length : undefined; const channelsTableLength = (Object.keys(data).length > 0 || hasFetchedData.current) ?
Object.keys(data).length : undefined;
/** /**
* Functions * Functions
@ -406,7 +414,7 @@ const ChannelsTable = ({}) => {
]); ]);
setIsLoading(false); setIsLoading(false);
setHasFetchedData(true); hasFetchedData.current = true;
setTablePrefs({ setTablePrefs({
pageSize: pagination.pageSize, pageSize: pagination.pageSize,