Files
iD/modules/ui/account.js
Quincy Morgan a1af118f0e Ensure locales and presets are loaded before the UI loads (close #7406)
Consolidate localization behavior and init to a coreLocalizer function and singleton
Explicitly support `en-US` locale
Rename coreData to coreFileFetcher and export a singleton rather than using a property of coreContext
Add `apiConnections` property of coreContext to simplify adding a source switcher
Replace some init functions with re-callable, promise-supporting `ensureLoaded` functions
Make coreContext itself load the UI if a container has been specified at init time
Fix code tests
2020-03-31 12:23:31 -07:00

79 lines
2.1 KiB
JavaScript

import { event as d3_event } from 'd3-selection';
import { t } from '../core/localizer';
import { svgIcon } from '../svg/icon';
export function uiAccount(context) {
var osm = context.connection();
function update(selection) {
if (!osm) return;
if (!osm.authenticated()) {
selection.selectAll('.userLink, .logoutLink')
.classed('hide', true);
return;
}
osm.userDetails(function(err, details) {
var userLink = selection.select('.userLink'),
logoutLink = selection.select('.logoutLink');
userLink.html('');
logoutLink.html('');
if (err || !details) return;
selection.selectAll('.userLink, .logoutLink')
.classed('hide', false);
// Link
userLink.append('a')
.attr('href', osm.userURL(details.display_name))
.attr('target', '_blank');
// Add thumbnail or dont
if (details.image_url) {
userLink.append('img')
.attr('class', 'icon pre-text user-icon')
.attr('src', details.image_url);
} else {
userLink
.call(svgIcon('#iD-icon-avatar', 'pre-text light'));
}
// Add user name
userLink.append('span')
.attr('class', 'label')
.text(details.display_name);
logoutLink.append('a')
.attr('class', 'logout')
.attr('href', '#')
.text(t('logout'))
.on('click.logout', function() {
d3_event.preventDefault();
osm.logout();
});
});
}
return function(selection) {
selection.append('li')
.attr('class', 'logoutLink')
.classed('hide', true);
selection.append('li')
.attr('class', 'userLink')
.classed('hide', true);
if (osm) {
osm.on('change.account', function() { update(selection); });
update(selection);
}
};
}