From ddd0599d339327886eb8e569b65800d8912e98c9 Mon Sep 17 00:00:00 2001 From: Gang Li Date: Thu, 25 Jan 2024 16:56:38 +0800 Subject: [PATCH] Use anonymous call instead for all init calls --- .../src/app/components/content/common/PackageTypeSelect.jsx | 5 ++--- .../webui/src/app/components/content/group/GroupList.jsx | 5 ++--- .../webui/src/app/components/content/group/GroupView.jsx | 6 ++---- .../webui/src/app/components/content/hosted/HostedEdit.jsx | 6 ++---- .../webui/src/app/components/content/hosted/HostedList.jsx | 5 ++--- .../webui/src/app/components/content/hosted/HostedView.jsx | 6 ++---- .../webui/src/app/components/content/remote/RemoteEdit.jsx | 6 ++---- .../webui/src/app/components/content/remote/RemoteList.jsx | 5 ++--- .../webui/src/app/components/content/remote/RemoteView.jsx | 6 ++---- src/main/webui/src/app/components/nav/NavFooter.jsx | 6 ++---- src/main/webui/src/app/components/nav/NavHeader.jsx | 6 ++---- src/main/webui/src/content-browse/DirectoryListing.jsx | 5 ++--- 12 files changed, 24 insertions(+), 43 deletions(-) diff --git a/src/main/webui/src/app/components/content/common/PackageTypeSelect.jsx b/src/main/webui/src/app/components/content/common/PackageTypeSelect.jsx index 9469f6a..21f023c 100644 --- a/src/main/webui/src/app/components/content/common/PackageTypeSelect.jsx +++ b/src/main/webui/src/app/components/content/common/PackageTypeSelect.jsx @@ -28,7 +28,7 @@ export const PackageTypeSelect = ({register, formErrors}) =>{ const [selected, setSelected] = useState(); useEffect(()=>{ - const fetchPkgTypes = async () =>{ + (async () =>{ const res = await statsRes.getAllPkgTypes(); if (res.success){ const pkgTypes = res.result; @@ -36,8 +36,7 @@ export const PackageTypeSelect = ({register, formErrors}) =>{ }else{ Utils.logMessage(res); } - }; - fetchPkgTypes(); + })(); }, []); let registered = {}; diff --git a/src/main/webui/src/app/components/content/group/GroupList.jsx b/src/main/webui/src/app/components/content/group/GroupList.jsx index 98e0fae..ba47765 100644 --- a/src/main/webui/src/app/components/content/group/GroupList.jsx +++ b/src/main/webui/src/app/components/content/group/GroupList.jsx @@ -59,7 +59,7 @@ export default function GroupList() { useEffect(() => { setLoading(true); - const fetchdData = async () => { + (async () => { const res = await storeRes.getStores(packageType, "group"); if (res.success) { const timeoutRes = await disableRes.getAllStoreTimeout(); @@ -85,8 +85,7 @@ export default function GroupList() { }); } setLoading(false); - }; - fetchdData(); + })(); }, [packageType]); if (loading) { diff --git a/src/main/webui/src/app/components/content/group/GroupView.jsx b/src/main/webui/src/app/components/content/group/GroupView.jsx index e9c6804..92d65a1 100644 --- a/src/main/webui/src/app/components/content/group/GroupView.jsx +++ b/src/main/webui/src/app/components/content/group/GroupView.jsx @@ -37,7 +37,7 @@ export default function GroupView() { useEffect(()=>{ setLoading(true); - const fetchStore = async () => { + (async () => { const res = await storeRes.get(packageType, "group", name); if (res.success){ const raw = res.result; @@ -59,9 +59,7 @@ export default function GroupView() { Utils.logMessage(`Failed to get store data. Error reason: ${res.error.status}->${res.error.message}`); } setLoading(false); - }; - - fetchStore(); + })(); }, [packageType, name]); if (loading) { diff --git a/src/main/webui/src/app/components/content/hosted/HostedEdit.jsx b/src/main/webui/src/app/components/content/hosted/HostedEdit.jsx index e0d5c27..b0f692b 100644 --- a/src/main/webui/src/app/components/content/hosted/HostedEdit.jsx +++ b/src/main/webui/src/app/components/content/hosted/HostedEdit.jsx @@ -51,7 +51,7 @@ export default function HostedEdit() { let store = {"packageType": "maven", "type": "hosted"}; useEffect(()=>{ if(mode === 'edit'){ - const fetchStore = async () =>{ + (async () =>{ // get Store data const res = await storeRes.get(packageType, "hosted", name); if (res.success){ @@ -77,9 +77,7 @@ export default function HostedEdit() { // TODO: find another way to do error handling Utils.logMessage(`Failed to get store data. Error reason: ${res.error.status}->${res.error.message}`); } - }; - - fetchStore(); + })(); } }, [packageType, name, mode, reset]); diff --git a/src/main/webui/src/app/components/content/hosted/HostedList.jsx b/src/main/webui/src/app/components/content/hosted/HostedList.jsx index c928a34..13aee56 100644 --- a/src/main/webui/src/app/components/content/hosted/HostedList.jsx +++ b/src/main/webui/src/app/components/content/hosted/HostedList.jsx @@ -59,7 +59,7 @@ export default function HostedList() { useEffect(() => { setLoading(true); - const fetchdData = async () => { + (async () => { const res = await storeRes.getStores(packageType, "hosted"); if (res.success) { const timeoutRes = await disableRes.getAllStoreTimeout(); @@ -85,8 +85,7 @@ export default function HostedList() { }); } setLoading(false); - }; - fetchdData(); + })(); }, [packageType]); if (loading) { diff --git a/src/main/webui/src/app/components/content/hosted/HostedView.jsx b/src/main/webui/src/app/components/content/hosted/HostedView.jsx index 7f85e7e..6d01103 100644 --- a/src/main/webui/src/app/components/content/hosted/HostedView.jsx +++ b/src/main/webui/src/app/components/content/hosted/HostedView.jsx @@ -38,7 +38,7 @@ export default function HostedView() { useEffect(()=>{ setLoading(true); - const fetchStore = async () => { + (async () => { const res = await storeRes.get(packageType, "hosted", name); if (res.success){ const raw = res.result; @@ -60,9 +60,7 @@ export default function HostedView() { Utils.logMessage(`Failed to get store data. Error reason: ${res.error.status}->${res.error.message}`); } setLoading(false); - }; - - fetchStore(); + })(); }, [packageType, name]); if (loading) { diff --git a/src/main/webui/src/app/components/content/remote/RemoteEdit.jsx b/src/main/webui/src/app/components/content/remote/RemoteEdit.jsx index 3e800f8..631cc46 100644 --- a/src/main/webui/src/app/components/content/remote/RemoteEdit.jsx +++ b/src/main/webui/src/app/components/content/remote/RemoteEdit.jsx @@ -53,7 +53,7 @@ export default function RemoteEdit() { let store = {"packageType": "maven", "type": "remote"}; useEffect(()=>{ if(mode === 'edit'){ - const fetchStore = async () =>{ + (async () =>{ // get Store data const res = await storeRes.get(packageType, "remote", name); if (res.success){ @@ -86,9 +86,7 @@ export default function RemoteEdit() { // TODO: find another way to do error handling Utils.logMessage(`Failed to get store data. Error reason: ${res.error.status}->${res.error.message}`); } - }; - - fetchStore(); + })(); } }, [packageType, name, mode, reset]); diff --git a/src/main/webui/src/app/components/content/remote/RemoteList.jsx b/src/main/webui/src/app/components/content/remote/RemoteList.jsx index e05697f..914a7e9 100644 --- a/src/main/webui/src/app/components/content/remote/RemoteList.jsx +++ b/src/main/webui/src/app/components/content/remote/RemoteList.jsx @@ -59,7 +59,7 @@ export default function RemoteList() { useEffect(()=>{ setLoading(true); - const fetchdData = async ()=>{ + (async ()=>{ const res = await storeRes.getStores(packageType, "remote"); if (res.success){ const timeoutRes = await disableRes.getAllStoreTimeout(); @@ -85,8 +85,7 @@ export default function RemoteList() { }); } setLoading(false); - }; - fetchdData(); + })(); }, [packageType]); if (loading) { diff --git a/src/main/webui/src/app/components/content/remote/RemoteView.jsx b/src/main/webui/src/app/components/content/remote/RemoteView.jsx index 9445650..d7f03c6 100644 --- a/src/main/webui/src/app/components/content/remote/RemoteView.jsx +++ b/src/main/webui/src/app/components/content/remote/RemoteView.jsx @@ -162,7 +162,7 @@ export default function RemoteView() { useEffect(()=>{ setLoading(true); - const fetchStore = async () => { + (async () => { const res = await storeRes.get(packageType, "remote", name); if (res.success){ const raw = res.result; @@ -188,9 +188,7 @@ export default function RemoteView() { Utils.logMessage(`Failed to get store data. Error reason: ${res.error.status}->${res.error.message}`); } setLoading(false); - }; - - fetchStore(); + })(); }, [packageType, name]); if (loading) { diff --git a/src/main/webui/src/app/components/nav/NavFooter.jsx b/src/main/webui/src/app/components/nav/NavFooter.jsx index b0dbcde..4cd03e7 100644 --- a/src/main/webui/src/app/components/nav/NavFooter.jsx +++ b/src/main/webui/src/app/components/nav/NavFooter.jsx @@ -27,7 +27,7 @@ export default function NavFooter() { const [state, setState] = useState({stats: {}}); useEffect(()=>{ - const fetchVersion = async () => { + (async () => { const res = await statsRes.getVersion(); if (res.success){ setState({ @@ -38,9 +38,7 @@ export default function NavFooter() { Utils.logMessage(`Failed to version info. Error reason: ${res.status}->${data}`); }); } - }; - - fetchVersion(); + })(); }, []); const stats = state.stats; diff --git a/src/main/webui/src/app/components/nav/NavHeader.jsx b/src/main/webui/src/app/components/nav/NavHeader.jsx index 0af9645..5bf989f 100644 --- a/src/main/webui/src/app/components/nav/NavHeader.jsx +++ b/src/main/webui/src/app/components/nav/NavHeader.jsx @@ -34,7 +34,7 @@ export default function NavHeader(){ }); useEffect(()=>{ - const fetchUserInfo = async () => { + (async () => { const res = await authRes.getUserInfo(); if (res.success){ setState({ @@ -46,9 +46,7 @@ export default function NavHeader(){ Utils.logMessage(`Failed to get user info. Error reason: ${res.status}->${data}`); }); } - }; - - fetchUserInfo(); + })(); }, []); return ( diff --git a/src/main/webui/src/content-browse/DirectoryListing.jsx b/src/main/webui/src/content-browse/DirectoryListing.jsx index e470b79..b5ed28b 100644 --- a/src/main/webui/src/content-browse/DirectoryListing.jsx +++ b/src/main/webui/src/content-browse/DirectoryListing.jsx @@ -112,7 +112,7 @@ export default function DirectoryListing () { }); useEffect(()=>{ - const fetchData = async () => { + (async () => { const res = await contentRes.browse(document.location.pathname); if(res.success){ const data = res.result; @@ -126,8 +126,7 @@ export default function DirectoryListing () { error: res.error.message }); } - }; - fetchData(); + })(); }, []); const {error, isLoaded, data} = state;