Skip to content
Snippets Groups Projects
Unverified Commit 977e0c90 authored by Jed Fox's avatar Jed Fox Committed by GitHub
Browse files

Updates to the server button at the top right (#1141)

It now always shows a menu, so the user doesn’t unexpectedly perform an
action.
parent 497a3104
No related branches found
No related tags found
No related merge requests found
...@@ -75,6 +75,7 @@ test.describe('Onboarding', () => { ...@@ -75,6 +75,7 @@ test.describe('Onboarding', () => {
await configurationPage.startFresh(); await configurationPage.startFresh();
await navigation.clickOnNoServer(); await navigation.clickOnNoServer();
await page.getByRole('button', { name: 'Start using a server' }).click();
await expect(configurationPage.heading).toHaveText('Where’s the server?'); await expect(configurationPage.heading).toHaveText('Where’s the server?');
}); });
......
...@@ -2,6 +2,8 @@ import React, { useState, useEffect } from 'react'; ...@@ -2,6 +2,8 @@ import React, { useState, useEffect } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { withRouter } from 'react-router'; import { withRouter } from 'react-router';
import { css } from 'glamor';
import * as actions from 'loot-core/src/client/actions'; import * as actions from 'loot-core/src/client/actions';
import { colors } from '../style'; import { colors } from '../style';
...@@ -9,14 +11,16 @@ import { colors } from '../style'; ...@@ -9,14 +11,16 @@ import { colors } from '../style';
import { View, Text, Button, Tooltip, Menu } from './common'; import { View, Text, Button, Tooltip, Menu } from './common';
import { useServerURL } from './ServerContext'; import { useServerURL } from './ServerContext';
let fade = css.keyframes({
'0%': { opacity: 0 },
'100%': { opacity: 1 },
});
function LoggedInUser({ function LoggedInUser({
files, hideIfNoServer,
budgetId,
userData, userData,
getUserData, getUserData,
setAppState,
signOut, signOut,
pushModal,
closeBudget, closeBudget,
style, style,
color, color,
...@@ -34,80 +38,98 @@ function LoggedInUser({ ...@@ -34,80 +38,98 @@ function LoggedInUser({
window.__history.push('/change-password'); window.__history.push('/change-password');
} }
function onMenuSelect(type) { async function onMenuSelect(type) {
setMenuOpen(false); setMenuOpen(false);
switch (type) { switch (type) {
case 'change-password': case 'change-password':
onChangePassword(); onChangePassword();
break; break;
case 'sign-in':
await closeBudget();
window.__history.push('/login');
break;
case 'sign-out': case 'sign-out':
signOut(); signOut();
break; break;
case 'config-server':
await closeBudget();
window.__history.push('/config-server');
break;
default: default:
} }
} }
async function onClick() { function serverMessage() {
if (!serverUrl) { if (!serverUrl) {
await closeBudget(); return 'No server';
window.__history.push('/config-server');
} else if (userData) {
setMenuOpen(true);
} else {
await closeBudget();
window.__history.push('/login');
} }
if (userData?.offline) {
return 'Server offline';
}
return 'Server online';
}
if (hideIfNoServer && !serverUrl) {
return null;
} }
if (loading) { if (loading && serverUrl) {
return ( return (
<Text style={[{ color: colors.n5, fontStyle: 'italic' }, style]}> <Text
Loading account... style={[
{
color: colors.n5,
fontStyle: 'italic',
animationName: fade,
animationDuration: '0.2s',
animationFillMode: 'both',
animationDelay: '0.5s',
},
style,
]}
>
Connecting...
</Text> </Text>
); );
} else if (userData) { }
if (userData.offline) {
return <View style={[{ color }, style]}>Offline</View>;
}
return ( return (
<View style={[{ flexDirection: 'row', alignItems: 'center' }, style]}> <View style={[{ flexDirection: 'row', alignItems: 'center' }, style]}>
<Button bare onClick={onClick} style={{ color }}> <Button bare onClick={() => setMenuOpen(true)} style={{ color }}>
{serverUrl ? 'Server' : 'No server'} {serverMessage()}
</Button>
{menuOpen && (
<Tooltip
position="bottom-right"
style={{ padding: 0 }}
onClose={() => setMenuOpen(false)}
>
<Menu
onMenuSelect={onMenuSelect}
items={[
{ name: 'change-password', text: 'Change password' },
{ name: 'sign-out', text: 'Sign out' },
]}
/>
</Tooltip>
)}
</View>
);
} else {
return (
<Button bare onClick={onClick} style={[{ color }, style]}>
Not logged in
</Button> </Button>
);
} {menuOpen && (
<Tooltip
position="bottom-right"
style={{ padding: 0 }}
onClose={() => setMenuOpen(false)}
>
<Menu
onMenuSelect={onMenuSelect}
items={[
serverUrl &&
!userData?.offline && {
name: 'change-password',
text: 'Change password',
},
serverUrl && { name: 'sign-out', text: 'Sign out' },
{
name: 'config-server',
text: serverUrl ? 'Change server URL' : 'Start using a server',
},
]}
/>
</Tooltip>
)}
</View>
);
} }
export default connect( export default connect(
state => ({ state => ({ userData: state.user.data }),
userData: state.user.data,
files: state.budgets.allFiles,
budgetId: state.prefs.local && state.prefs.local.id,
}),
actions, actions,
)(withRouter(LoggedInUser)); )(withRouter(LoggedInUser));
...@@ -182,7 +182,10 @@ function ManagementApp({ ...@@ -182,7 +182,10 @@ function ManagementApp({
<Switch> <Switch>
<Route exact path="/config-server" children={null} /> <Route exact path="/config-server" children={null} />
<Route exact path="/"> <Route exact path="/">
<LoggedInUser style={{ padding: '4px 7px' }} /> <LoggedInUser
hideIfNoServer
style={{ padding: '4px 7px' }}
/>
</Route> </Route>
</Switch> </Switch>
</View> </View>
......
---
category: Enhancements
authors: [j-f1]
---
Make the behavior of the “Server” button in the top-right corner more consistent
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