refactor: extract useServerVersion hook
This commit is contained in:
parent
b95a57080b
commit
eed864aca1
2 changed files with 26 additions and 15 deletions
|
@ -24,6 +24,8 @@ import ExpandArrow from 'loot-design/src/svg/ExpandArrow';
|
||||||
import ExclamationSolid from 'loot-design/src/svg/v1/ExclamationSolid';
|
import ExclamationSolid from 'loot-design/src/svg/v1/ExclamationSolid';
|
||||||
import Platform from 'loot-core/src/client/platform';
|
import Platform from 'loot-core/src/client/platform';
|
||||||
|
|
||||||
|
import useServerVersion from '../hooks/useServerVersion';
|
||||||
|
|
||||||
let dateFormats = [
|
let dateFormats = [
|
||||||
{ value: 'MM/dd/yyyy', label: 'MM/DD/YYYY' },
|
{ value: 'MM/dd/yyyy', label: 'MM/DD/YYYY' },
|
||||||
{ value: 'dd/MM/yyyy', label: 'DD/MM/YYYY' },
|
{ value: 'dd/MM/yyyy', label: 'DD/MM/YYYY' },
|
||||||
|
@ -474,19 +476,7 @@ function SettingsLink({ to, name, style, first, last }) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function Version() {
|
function Version() {
|
||||||
let [version, setVersion] = useState('');
|
const version = useServerVersion();
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
(async () => {
|
|
||||||
const { error, version } = await send('get-server-version');
|
|
||||||
|
|
||||||
if (error) {
|
|
||||||
setVersion('');
|
|
||||||
} else {
|
|
||||||
setVersion(version);
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Text
|
<Text
|
||||||
|
@ -501,8 +491,7 @@ function Version() {
|
||||||
styles.smallText
|
styles.smallText
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
{`App: v${window.Actual.ACTUAL_VERSION}` +
|
{`App: v${window.Actual.ACTUAL_VERSION} | Server: ${version}`}
|
||||||
` | Server: ${version ? `v${version}` : 'N/A'}`}
|
|
||||||
</Text>
|
</Text>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
22
packages/desktop-client/src/hooks/useServerVersion.js
Normal file
22
packages/desktop-client/src/hooks/useServerVersion.js
Normal file
|
@ -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;
|
Loading…
Reference in a new issue