Conversation
…eact query flags . renaming flags in the correct graph name addint is as prefix
…into refactor--add--dashbord--context
| export const DashboardCtx = createContext<DashboardContextType>({} as DashboardContextType) | ||
| export const DashboardContext: FC<PropsWithChildren> = ({ children }) => { | ||
| // loading | ||
| const [allLinesChartsIsLoading, setAllLinesChartsIsLoading] = useState(false) |
There was a problem hiding this comment.
maybe we can simplify state?
const [allLinesChartsIsLoading, setAllLinesChartsIsLoading] = useState({
loading: false,
empty: false,
})or
type ErrorItem = false | 'loading' | 'error'
const [worstLineIsLoading, setWorstLineIsLoading] = useState<ErrorItem>(false)or
type ErrorItem = { name: string; state: false | 'loading' | 'error' }
const [errorList, setErrorList] = useState<ErrorItem[]>([])There was a problem hiding this comment.
First - I'd like to emphasise that I think the code is great as is - you've done a great job.
following @AvivAbachi's suggestions, here's some ideas that I have. It's up to you - you're the owner :)
First, if we'll use useQuery, it can make our life easier using the useIsFetching:
https://tanstack.com/query/latest/docs/framework/react/reference/useIsFetching
Second idea - you can use one variable for the state. I disagree with Aviv regarding the idea to use array - I believe arrays should be used when ordering matters, and I don't feel like that's the case. Here's my suggestion draft -
const [statuses, setStatuses] = useState<
'worstLiteChart' | 'otherChart' | 'theThirdChart' | ..., // so on
'loading' | 'loaded-empty' | 'loaded' | 'error'
>({})Third option - having different state variables - it's also great and valid - just like you've implemented.
It's up to you, anyway that's a great change 👑
| const [isDataEmpty, setIsDataEmpty] = useState(false) | ||
| const [isDataLoading, setIsDataLoading] = useState(false) | ||
|
|
||
| useEffect(() => { |
There was a problem hiding this comment.
you can useMemo() is same computed() in vue
const isDataEmpty = useMemo(() => {
return allLineChartsIsEmpty && worstLineIsEmpty && dayTimeChartIsEmpty
}, [allLineChartsIsEmpty, worstLineIsEmpty, dayTimeChartIsEmpty])| isDataLoading, | ||
| isDataEmpty, |
There was a problem hiding this comment.
When someone consumes this context, I don't want them to make guesses on whether there's an "and" (&&) or "or" (||) condition between the different statuses. I suggest that we could try a naming convention that corresponds with the Array.prototype.every() and Array.prototype.some()
| isDataLoading, | |
| isDataEmpty, | |
| isSomeDataLoading, | |
| isAllDataEmpty, |
| export const DashboardCtx = createContext<DashboardContextType>({} as DashboardContextType) | ||
| export const DashboardContext: FC<PropsWithChildren> = ({ children }) => { | ||
| // loading | ||
| const [allLinesChartsIsLoading, setAllLinesChartsIsLoading] = useState(false) |
There was a problem hiding this comment.
First - I'd like to emphasise that I think the code is great as is - you've done a great job.
following @AvivAbachi's suggestions, here's some ideas that I have. It's up to you - you're the owner :)
First, if we'll use useQuery, it can make our life easier using the useIsFetching:
https://tanstack.com/query/latest/docs/framework/react/reference/useIsFetching
Second idea - you can use one variable for the state. I disagree with Aviv regarding the idea to use array - I believe arrays should be used when ordering matters, and I don't feel like that's the case. Here's my suggestion draft -
const [statuses, setStatuses] = useState<
'worstLiteChart' | 'otherChart' | 'theThirdChart' | ..., // so on
'loading' | 'loaded-empty' | 'loaded' | 'error'
>({})Third option - having different state variables - it's also great and valid - just like you've implemented.
It's up to you, anyway that's a great change 👑
Description
screenshots