1
1
import { notify } from "@components/Notification" ;
2
+ import SkeletonPeerDetail from "@components/skeletons/SkeletonPeerDetail" ;
2
3
import { useApiCall } from "@utils/api" ;
3
4
import React , { useMemo } from "react" ;
4
5
import { useSWRConfig } from "swr" ;
@@ -27,12 +28,13 @@ const PeerContext = React.createContext(
27
28
) => Promise < Peer > ;
28
29
openSSHDialog : ( ) => Promise < boolean > ;
29
30
deletePeer : ( ) => void ;
31
+ isLoading : boolean ;
30
32
} ,
31
33
) ;
32
34
33
35
export default function PeerProvider ( { children, peer } : Props ) {
34
36
const user = usePeerUser ( peer ) ;
35
- const peerGroups = usePeerGroups ( peer ) ;
37
+ const { peerGroups, isLoading } = usePeerGroups ( peer ) ;
36
38
const peerRequest = useApiCall < Peer > ( "/peers" ) ;
37
39
const { confirm } = useDialog ( ) ;
38
40
const { mutate } = useSWRConfig ( ) ;
@@ -94,12 +96,22 @@ export default function PeerProvider({ children, peer }: Props) {
94
96
} ) ;
95
97
} ;
96
98
97
- return (
99
+ return ! isLoading ? (
98
100
< PeerContext . Provider
99
- value = { { peer, peerGroups, user, update, openSSHDialog, deletePeer } }
101
+ value = { {
102
+ peer,
103
+ peerGroups,
104
+ user,
105
+ update,
106
+ openSSHDialog,
107
+ deletePeer,
108
+ isLoading,
109
+ } }
100
110
>
101
111
{ children }
102
112
</ PeerContext . Provider >
113
+ ) : (
114
+ < SkeletonPeerDetail />
103
115
) ;
104
116
}
105
117
@@ -108,9 +120,9 @@ export default function PeerProvider({ children, peer }: Props) {
108
120
* @param peer
109
121
*/
110
122
export const usePeerGroups = ( peer ?: Peer ) => {
111
- const { groups } = useGroups ( ) ;
123
+ const { groups, isLoading } = useGroups ( ) ;
112
124
113
- return useMemo ( ( ) => {
125
+ const peerGroups = useMemo ( ( ) => {
114
126
if ( ! peer ) return [ ] ;
115
127
const peerGroups = groups ?. filter ( ( group ) => {
116
128
const foundGroup = group . peers ?. find ( ( p ) => {
@@ -121,6 +133,8 @@ export const usePeerGroups = (peer?: Peer) => {
121
133
} ) ;
122
134
return peerGroups || [ ] ;
123
135
} , [ groups , peer ] ) ;
136
+
137
+ return { peerGroups, isLoading } ;
124
138
} ;
125
139
126
140
/**
0 commit comments