Add favicon to websites

This commit is contained in:
Boris Kubiak 2020-10-21 15:44:43 +02:00
parent e55d03cbea
commit 90fa656d40
8 changed files with 44 additions and 7 deletions

View File

@ -0,0 +1,21 @@
import React from 'react';
import styles from './Favicon.module.css';
function getHostName(url) {
const match = url.match(/^(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:/\n?=]+)/im);
return match && match.length > 1 ? match[1] : null;
}
export default function Favicon({ domain, ...props }) {
const hostName = domain ? getHostName(domain) : null;
return hostName ? (
<img
className={styles.favicon}
src={`https://icons.duckduckgo.com/ip3/${hostName}.ico`}
height="16"
alt=""
{...props}
/>
) : null;
}

View File

@ -0,0 +1,3 @@
.favicon {
margin-right: 8px;
}

View File

@ -20,6 +20,7 @@ import { TOKEN_HEADER } from '../../lib/constants';
export default function WebsiteChart({ export default function WebsiteChart({
websiteId, websiteId,
title, title,
domain,
stickyHeader = false, stickyHeader = false,
showLink = false, showLink = false,
onDataLoad = () => {}, onDataLoad = () => {},
@ -66,7 +67,7 @@ export default function WebsiteChart({
return ( return (
<div className={styles.container}> <div className={styles.container}>
<WebsiteHeader websiteId={websiteId} title={title} showLink={showLink} /> <WebsiteHeader websiteId={websiteId} title={title} domain={domain} showLink={showLink} />
<div className={classNames(styles.header, 'row')}> <div className={classNames(styles.header, 'row')}>
<StickyHeader <StickyHeader
className={classNames(styles.metrics, 'col row')} className={classNames(styles.metrics, 'col row')}

View File

@ -4,14 +4,18 @@ import Link from 'components/common/Link';
import PageHeader from 'components/layout/PageHeader'; import PageHeader from 'components/layout/PageHeader';
import RefreshButton from 'components/common/RefreshButton'; import RefreshButton from 'components/common/RefreshButton';
import ButtonLayout from 'components/layout/ButtonLayout'; import ButtonLayout from 'components/layout/ButtonLayout';
import Favicon from 'components/common/Favicon';
import ActiveUsers from './ActiveUsers'; import ActiveUsers from './ActiveUsers';
import Arrow from 'assets/arrow-right.svg'; import Arrow from 'assets/arrow-right.svg';
import styles from './WebsiteHeader.module.css'; import styles from './WebsiteHeader.module.css';
export default function WebsiteHeader({ websiteId, title, showLink = false }) { export default function WebsiteHeader({ websiteId, title, domain, showLink = false }) {
return ( return (
<PageHeader> <PageHeader>
<div className={styles.title}>{title}</div> <div className={styles.title}>
<Favicon domain={domain} />
{title}
</div>
<ActiveUsers className={styles.active} websiteId={websiteId} /> <ActiveUsers className={styles.active} websiteId={websiteId} />
<ButtonLayout align="right"> <ButtonLayout align="right">
<RefreshButton websiteId={websiteId} /> <RefreshButton websiteId={websiteId} />

View File

@ -82,7 +82,12 @@ export default function TestConsole() {
</div> </div>
<div className="row"> <div className="row">
<div className="col-12"> <div className="col-12">
<WebsiteChart websiteId={website.website_id} title={website.name} showLink /> <WebsiteChart
websiteId={website.website_id}
title={website.name}
domain={website.domain}
showLink
/>
<PageHeader>Events</PageHeader> <PageHeader>Events</PageHeader>
<EventsChart websiteId={website.website_id} /> <EventsChart websiteId={website.website_id} />
</div> </div>

View File

@ -120,6 +120,7 @@ export default function WebsiteDetails({ websiteId }) {
<WebsiteChart <WebsiteChart
websiteId={websiteId} websiteId={websiteId}
title={data.name} title={data.name}
domain={data.domain}
onDataLoad={handleDataLoad} onDataLoad={handleDataLoad}
showLink={false} showLink={false}
stickyHeader stickyHeader

View File

@ -17,9 +17,9 @@ export default function WebsiteList({ userId }) {
return ( return (
<Page> <Page>
{data.map(({ website_id, name }) => ( {data.map(({ website_id, name, domain }) => (
<div key={website_id} className={styles.website}> <div key={website_id} className={styles.website}>
<WebsiteChart websiteId={website_id} title={name} showLink /> <WebsiteChart websiteId={website_id} title={name} domain={domain} showLink />
</div> </div>
))} ))}
{data.length === 0 && ( {data.length === 0 && (

View File

@ -13,6 +13,7 @@ import ShareUrlForm from 'components/forms/ShareUrlForm';
import EmptyPlaceholder from 'components/common/EmptyPlaceholder'; import EmptyPlaceholder from 'components/common/EmptyPlaceholder';
import ButtonLayout from 'components/layout/ButtonLayout'; import ButtonLayout from 'components/layout/ButtonLayout';
import Toast from 'components/common/Toast'; import Toast from 'components/common/Toast';
import Favicon from 'components/common/Favicon';
import Pen from 'assets/pen.svg'; import Pen from 'assets/pen.svg';
import Trash from 'assets/trash.svg'; import Trash from 'assets/trash.svg';
import Plus from 'assets/plus.svg'; import Plus from 'assets/plus.svg';
@ -60,8 +61,9 @@ export default function WebsiteSettings() {
</ButtonLayout> </ButtonLayout>
); );
const DetailsLink = ({ website_id, name }) => ( const DetailsLink = ({ website_id, name, domain }) => (
<Link href="/website/[...id]" as={`/website/${website_id}/${name}`}> <Link href="/website/[...id]" as={`/website/${website_id}/${name}`}>
<Favicon domain={domain} />
{name} {name}
</Link> </Link>
); );