-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: create useInvoke hook to reduce repetition (#45)
- Loading branch information
1 parent
e0a5c71
commit 011f865
Showing
7 changed files
with
59 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { invoke } from "@tauri-apps/api"; | ||
|
||
import { useCurrentNamespace } from "../namespaces/namespaces"; | ||
|
||
type Commands = | ||
| "get_cron_jobs" | ||
| "get_deployments" | ||
| "get_jobs" | ||
| "get_pods" | ||
| "get_replica_sets" | ||
| "get_stateful_sets"; | ||
|
||
export function useGetResourceList<T>(command: Commands) { | ||
const { namespace } = useCurrentNamespace(); | ||
const result = useQuery( | ||
[command, namespace], | ||
() => { | ||
return invoke<{ items: T[] }>(command, { namespace }); | ||
}, | ||
// TODO: maybe make this configurable? | ||
{ refetchInterval: 2000 } | ||
); | ||
|
||
return { ...result, data: result.data ?? { items: [] } }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters