From c0089cf10e138d063dab70a1f5c273920a88c0fd Mon Sep 17 00:00:00 2001 From: Marius Vollmer Date: Fri, 19 May 2023 12:50:53 +0300 Subject: [PATCH] storage: Optional spinners in StorageButtons --- pkg/storaged/storage-controls.jsx | 42 +++++++++++++++++++------------ 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/pkg/storaged/storage-controls.jsx b/pkg/storaged/storage-controls.jsx index e2a04a366e1f..ce6b565d49d9 100644 --- a/pkg/storaged/storage-controls.jsx +++ b/pkg/storaged/storage-controls.jsx @@ -68,7 +68,7 @@ class StorageControl extends React.Component { } } -function checked(callback) { +function checked(callback, setSpinning) { return function (event) { if (!event) return; @@ -82,31 +82,41 @@ function checked(callback) { return; const promise = client.run(callback); - if (promise) + if (promise) { + if (setSpinning) + setSpinning(true); + promise.finally(() => { + if (setSpinning) + setSpinning(false); + }); promise.catch(function (error) { dialog_open({ Title: _("Error"), Body: error.toString() }); }); + } event.stopPropagation(); }; } -export const StorageButton = ({ id, kind, excuse, onClick, children, ariaLabel, onlyWide }) => ( - ( - - )} /> -); +export const StorageButton = ({ id, kind, excuse, onClick, children, ariaLabel, onlyWide, spinner }) => { + const [spinning, setSpinning] = useState(false); + + return ( + + )} />; +}; export const StorageLink = ({ id, excuse, onClick, children }) => (