diff --git a/packages/desktop-client/src/components/Settings.js b/packages/desktop-client/src/components/Settings.js index 0f5053b..29ad397 100644 --- a/packages/desktop-client/src/components/Settings.js +++ b/packages/desktop-client/src/components/Settings.js @@ -24,6 +24,8 @@ import ExpandArrow from 'loot-design/src/svg/ExpandArrow'; import ExclamationSolid from 'loot-design/src/svg/v1/ExclamationSolid'; import Platform from 'loot-core/src/client/platform'; +import useServerVersion from '../hooks/useServerVersion'; + let dateFormats = [ { value: 'MM/dd/yyyy', label: 'MM/DD/YYYY' }, { value: 'dd/MM/yyyy', label: 'DD/MM/YYYY' }, @@ -474,19 +476,7 @@ function SettingsLink({ to, name, style, first, last }) { } function Version() { - let [version, setVersion] = useState(''); - - useEffect(() => { - (async () => { - const { error, version } = await send('get-server-version'); - - if (error) { - setVersion(''); - } else { - setVersion(version); - } - })(); - }, []); + const version = useServerVersion(); return ( - {`App: v${window.Actual.ACTUAL_VERSION}` + - ` | Server: ${version ? `v${version}` : 'N/A'}`} + {`App: v${window.Actual.ACTUAL_VERSION} | Server: ${version}`} ); } diff --git a/packages/desktop-client/src/hooks/useServerVersion.js b/packages/desktop-client/src/hooks/useServerVersion.js new file mode 100644 index 0000000..96f93d1 --- /dev/null +++ b/packages/desktop-client/src/hooks/useServerVersion.js @@ -0,0 +1,22 @@ +import React, { useState, useEffect } from 'react'; +import { send } from 'loot-core/src/platform/client/fetch'; + +function useServerVersion() { + let [version, setVersion] = useState(''); + + useEffect(() => { + (async () => { + const { error, version } = await send('get-server-version'); + + if (error) { + setVersion(''); + } else { + setVersion(version); + } + })(); + }, []); + + return version ? `v${version}` : 'N/A'; +} + +export default useServerVersion;