import { FC, useEffect } from 'react'; import { Card, CardBody, CardHeader, CardText, CardTitle, Row } from 'reactstrap'; import { Link, useHistory } from 'react-router-dom'; import { ITEMS_IN_OVERVIEW_PAGE, ShortUrlsList as ShortUrlsListState } from '../short-urls/reducers/shortUrlsList'; import { prettify } from '../utils/helpers/numbers'; import { TagsList } from '../tags/reducers/tagsList'; import { ShortUrlsTableProps } from '../short-urls/ShortUrlsTable'; import { boundToMercureHub } from '../mercure/helpers/boundToMercureHub'; import { CreateShortUrlProps } from '../short-urls/CreateShortUrl'; import { VisitsOverview } from '../visits/reducers/visitsOverview'; import { Versions } from '../utils/helpers/version'; import { Topics } from '../mercure/helpers/Topics'; import { ShlinkShortUrlsListParams } from '../api/types'; import { getServerId, SelectedServer } from './data'; import './Overview.scss'; interface OverviewConnectProps { shortUrlsList: ShortUrlsListState; listShortUrls: (params: ShlinkShortUrlsListParams) => void; listTags: Function; tagsList: TagsList; selectedServer: SelectedServer; visitsOverview: VisitsOverview; loadVisitsOverview: Function; } export const Overview = ( ShortUrlsTable: FC, CreateShortUrl: FC, ForServerVersion: FC, ) => boundToMercureHub(({ shortUrlsList, listShortUrls, listTags, tagsList, selectedServer, loadVisitsOverview, visitsOverview, }: OverviewConnectProps) => { const { loading, shortUrls } = shortUrlsList; const { loading: loadingTags } = tagsList; const { loading: loadingVisits, visitsCount, orphanVisitsCount } = visitsOverview; const serverId = getServerId(selectedServer); const history = useHistory(); useEffect(() => { listShortUrls({ itemsPerPage: ITEMS_IN_OVERVIEW_PAGE, orderBy: { field: 'dateCreated', dir: 'DESC' } }); listTags(); loadVisitsOverview(); }, []); return ( <>
Visits {loadingVisits ? 'Loading...' : prettify(visitsCount)}
Orphan visits {loadingVisits ? 'Loading...' : prettify(orphanVisitsCount ?? 0)} Shlink 2.6 is needed
Short URLs {loading ? 'Loading...' : prettify(shortUrls?.pagination.totalItems ?? 0)}
Tags {loadingTags ? 'Loading...' : prettify(tagsList.tags.length)}
Create a short URL
Create a short URL
Advanced options »
Recently created URLs
Recently created URLs
See all »
history.push(`/server/${serverId}/list-short-urls/1?tags=${encodeURIComponent(tag)}`)} />
); }, () => [ Topics.visits, Topics.orphanVisits ]);