Skip to content
Snippets Groups Projects
Commit eed864ac authored by Arthur E. Jones's avatar Arthur E. Jones Committed by James Long
Browse files

refactor: extract useServerVersion hook

parent b95a5708
No related branches found
No related tags found
No related merge requests found
...@@ -24,6 +24,8 @@ import ExpandArrow from 'loot-design/src/svg/ExpandArrow'; ...@@ -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 }) { ...@@ -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() { ...@@ -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>
); );
} }
......
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;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment