diff --git a/src/components/setting/mods/network-interface-viewer.tsx b/src/components/setting/mods/network-interface-viewer.tsx index 588ce472c..087733437 100644 --- a/src/components/setting/mods/network-interface-viewer.tsx +++ b/src/components/setting/mods/network-interface-viewer.tsx @@ -1,11 +1,11 @@ import { ContentCopyRounded } from '@mui/icons-material' -import { alpha, Box, Button, IconButton } from '@mui/material' +import { alpha, Box, Button, CircularProgress, IconButton } from '@mui/material' import { writeText } from '@tauri-apps/plugin-clipboard-manager' import type { Ref } from 'react' import { useImperativeHandle, useState } from 'react' import { useTranslation } from 'react-i18next' -import { BaseDialog, DialogRef } from '@/components/base' +import { BaseDialog, BaseEmpty, DialogRef } from '@/components/base' import { useNetworkInterfaces } from '@/hooks/use-network' import { showNotice } from '@/services/notice-service' @@ -21,7 +21,10 @@ export function NetworkInterfaceViewer({ ref }: { ref?: Ref }) { close: () => setOpen(false), })) - const { networkInterfaces } = useNetworkInterfaces() + const { networkInterfaces, loading } = useNetworkInterfaces() + const isEmpty = networkInterfaces.length === 0 + const getAddressIp = (address: IAddress) => + isV4 ? address.V4?.ip : address.V6?.ip return ( }) { onClose={() => setOpen(false)} onCancel={() => setOpen(false)} > - {networkInterfaces.map((item) => ( - -

{item.name}

- - {isV4 && ( - <> - {item.addr.map( - (address) => - address.V4 && ( - - ), - )} - - - )} - {!isV4 && ( - <> - {item.addr.map( - (address) => - address.V6 && ( - - ), - )} - - - )} - + {loading && isEmpty ? ( + + - ))} + ) : isEmpty ? ( + + + + ) : ( + networkInterfaces.map((item) => ( + +

{item.name}

+ + {item.addr.map((address) => { + const ip = getAddressIp(address) + return ( + ip && ( + + ) + ) + })} + + +
+ )) + )}
) } diff --git a/src/hooks/use-network.ts b/src/hooks/use-network.ts index 105c7807c..47235f490 100644 --- a/src/hooks/use-network.ts +++ b/src/hooks/use-network.ts @@ -6,6 +6,7 @@ export const useNetworkInterfaces = () => { const { data, error, + isFetching, isLoading, refetch: mutate, } = useQuery({ @@ -13,12 +14,12 @@ export const useNetworkInterfaces = () => { queryFn: getNetworkInterfacesInfo, refetchOnWindowFocus: false, refetchOnReconnect: false, - initialData: [], + placeholderData: [], }) return { networkInterfaces: data || [], - loading: isLoading, + loading: isLoading || isFetching, error, mutate, }