dispatch/client/js/modules/documentTitle.js
2020-06-15 10:58:51 +02:00

28 lines
727 B
JavaScript

import capitalize from 'lodash/capitalize';
import { getRouter } from 'state';
import { getCurrentNetworkName } from 'state/networks';
import { observe } from 'utils/observe';
export default function documentTitle({ store }) {
observe(store, [getRouter, getCurrentNetworkName], (router, networkName) => {
let title;
if (router.route === 'chat') {
const { network, name } = router.params;
if (name) {
title = `${name} @ ${networkName || network}`;
} else {
title = networkName || network;
}
} else {
title = capitalize(router.route);
}
if (title) {
document.title = `${title} | Dispatch`;
} else {
document.title = 'Dispatch';
}
});
}