mirror of
https://github.com/actualbudget/actual.git
synced 2026-04-28 10:33:02 -05:00
Add a useServerURL hook
This commit is contained in:
@@ -11,25 +11,19 @@ import { colors } from 'loot-design/src/style';
|
||||
import { signOut, loggedIn } from 'loot-core/src/client/actions/user';
|
||||
import { send } from 'loot-core/src/platform/client/fetch';
|
||||
import { Title, Input } from './subscribe/common';
|
||||
import useServerURL from '../../hooks/useServerURL';
|
||||
|
||||
export default function ConfigServer() {
|
||||
let dispatch = useDispatch();
|
||||
let history = useHistory();
|
||||
let [url, setUrl] = useState('');
|
||||
let currentUrl = useServerURL();
|
||||
useEffect(() => {
|
||||
setUrl(currentUrl);
|
||||
}, [currentUrl]);
|
||||
let [loading, setLoading] = useState(false);
|
||||
let [error, setError] = useState(null);
|
||||
|
||||
let [currentUrl, setCurrentUrl] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
async function run() {
|
||||
let url = await send('get-server-url');
|
||||
setUrl(!url || url.indexOf('not-configured') ? '' : url);
|
||||
setCurrentUrl(url);
|
||||
}
|
||||
run();
|
||||
}, []);
|
||||
|
||||
function getErrorMessage(error) {
|
||||
switch (error) {
|
||||
case 'network-failure':
|
||||
|
||||
@@ -1,17 +1,9 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import React from 'react';
|
||||
import { View, Text, AnchorLink } from 'loot-design/src/components/common';
|
||||
import { send } from 'loot-core/src/platform/client/fetch';
|
||||
import useServerURL from '../../hooks/useServerURL';
|
||||
|
||||
export default function ServerURL() {
|
||||
let [url, setUrl] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
async function run() {
|
||||
let url = await send('get-server-url');
|
||||
setUrl(url);
|
||||
}
|
||||
run();
|
||||
}, []);
|
||||
const url = useServerURL();
|
||||
|
||||
return (
|
||||
<View
|
||||
|
||||
19
packages/desktop-client/src/hooks/useServerURL.js
Normal file
19
packages/desktop-client/src/hooks/useServerURL.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { send } from 'loot-core/src/platform/client/fetch';
|
||||
|
||||
function useServerURL() {
|
||||
let [url, setUrl] = useState('');
|
||||
useEffect(() => {
|
||||
async function run() {
|
||||
let url = await send('get-server-url');
|
||||
if (url === 'https://not-configured/') {
|
||||
url = '';
|
||||
}
|
||||
setUrl(url);
|
||||
}
|
||||
run();
|
||||
}, []);
|
||||
return url;
|
||||
}
|
||||
|
||||
export default useServerURL;
|
||||
Reference in New Issue
Block a user