dispatch/client/js/modules/documentTitle.js

28 lines
718 B
JavaScript
Raw Normal View History

2017-05-19 05:29:44 +00:00
import capitalize from 'lodash/capitalize';
import { getRouter } from 'state';
import { getCurrentServerName } from 'state/servers';
import { observe } from 'utils/observe';
2017-05-19 05:29:44 +00:00
export default function documentTitle({ store }) {
observe(store, [getRouter, getCurrentServerName], (router, serverName) => {
let title;
2017-05-19 05:29:44 +00:00
if (router.route === 'chat') {
2018-11-22 09:09:13 +00:00
const { server, name } = router.params;
if (name) {
2018-11-22 09:09:13 +00:00
title = `${name} @ ${serverName || server}`;
2017-05-19 05:29:44 +00:00
} else {
2018-11-22 09:09:13 +00:00
title = serverName || server;
2017-05-19 05:29:44 +00:00
}
} else {
title = capitalize(router.route);
2017-05-19 05:29:44 +00:00
}
2018-11-22 09:09:13 +00:00
if (title) {
document.title = `${title} | Dispatch`;
} else {
document.title = 'Dispatch';
}
});
2017-05-19 05:29:44 +00:00
}