select modules.Prefetched schema depends only on modules
This commit is contained in:
@@ -34,7 +34,6 @@ type MachineContextType =
|
||||
swrKey: string | false | Record<any, any>;
|
||||
}
|
||||
| {
|
||||
flakeName: string;
|
||||
isLoading: true;
|
||||
data: readonly [];
|
||||
};
|
||||
@@ -44,13 +43,10 @@ const initialState = {
|
||||
data: [],
|
||||
} as const;
|
||||
|
||||
export function CreateMachineContext(flakeName: string) {
|
||||
return useMemo(() => {
|
||||
return createContext<MachineContextType>({
|
||||
...initialState,
|
||||
flakeName,
|
||||
});
|
||||
}, [flakeName]);
|
||||
export function CreateMachineContext() {
|
||||
return createContext<MachineContextType>({
|
||||
...initialState,
|
||||
});
|
||||
}
|
||||
|
||||
interface MachineContextProviderProps {
|
||||
@@ -58,6 +54,8 @@ interface MachineContextProviderProps {
|
||||
flakeName: string;
|
||||
}
|
||||
|
||||
const MachineContext = CreateMachineContext();
|
||||
|
||||
export const MachineContextProvider = (props: MachineContextProviderProps) => {
|
||||
const { children, flakeName } = props;
|
||||
const {
|
||||
@@ -74,14 +72,12 @@ export const MachineContextProvider = (props: MachineContextProviderProps) => {
|
||||
if (!isLoading && !error && !isValidating && rawData) {
|
||||
const { machines } = rawData.data;
|
||||
return machines.filter((m) =>
|
||||
filters.every((f) => m[f.name] === f.value),
|
||||
filters.every((f) => m[f.name] === f.value)
|
||||
);
|
||||
}
|
||||
return [];
|
||||
}, [isLoading, error, isValidating, rawData, filters]);
|
||||
|
||||
const MachineContext = CreateMachineContext(flakeName);
|
||||
|
||||
return (
|
||||
<MachineContext.Provider
|
||||
value={{
|
||||
@@ -105,5 +101,4 @@ export const MachineContextProvider = (props: MachineContextProviderProps) => {
|
||||
);
|
||||
};
|
||||
|
||||
export const useMachines = (flakeName: string) =>
|
||||
React.useContext(CreateMachineContext(flakeName));
|
||||
export const useMachines = () => React.useContext(MachineContext);
|
||||
|
||||
Reference in New Issue
Block a user