import type { FC } from 'react'; import { useEffect } from 'react'; import { Link, useNavigate } from 'react-router-dom'; import { Card, CardBody, CardHeader, Row } from 'reactstrap'; import type { ShlinkShortUrlsListParams } from '../../api/types'; import type { SelectedServer } from '../../servers/data'; import { getServerId } from '../../servers/data'; import { HighlightCard } from '../../servers/helpers/HighlightCard'; import { VisitsHighlightCard } from '../../servers/helpers/VisitsHighlightCard'; import type { Settings } from '../../settings/reducers/settings'; import { prettify } from '../../utils/helpers/numbers'; import { boundToMercureHub } from '../mercure/helpers/boundToMercureHub'; import { Topics } from '../mercure/helpers/Topics'; import type { CreateShortUrlProps } from '../short-urls/CreateShortUrl'; import type { ShortUrlsList as ShortUrlsListState } from '../short-urls/reducers/shortUrlsList'; import { ITEMS_IN_OVERVIEW_PAGE } from '../short-urls/reducers/shortUrlsList'; import type { ShortUrlsTableType } from '../short-urls/ShortUrlsTable'; import type { TagsList } from '../tags/reducers/tagsList'; import { useFeature } from '../utils/features'; import type { VisitsOverview } from '../visits/reducers/visitsOverview'; interface OverviewConnectProps { shortUrlsList: ShortUrlsListState; listShortUrls: (params: ShlinkShortUrlsListParams) => void; listTags: Function; tagsList: TagsList; selectedServer: SelectedServer; visitsOverview: VisitsOverview; loadVisitsOverview: Function; settings: Settings; } export const Overview = ( ShortUrlsTable: ShortUrlsTableType, CreateShortUrl: FC, ) => boundToMercureHub(({ shortUrlsList, listShortUrls, listTags, tagsList, selectedServer, loadVisitsOverview, visitsOverview, settings: { visits }, }: OverviewConnectProps) => { const { loading, shortUrls } = shortUrlsList; const { loading: loadingTags } = tagsList; const { loading: loadingVisits, nonOrphanVisits, orphanVisits } = visitsOverview; const serverId = getServerId(selectedServer); const linkToNonOrphanVisits = useFeature('nonOrphanVisits'); const navigate = useNavigate(); useEffect(() => { listShortUrls({ itemsPerPage: ITEMS_IN_OVERVIEW_PAGE, orderBy: { field: 'dateCreated', dir: 'DESC' } }); listTags(); loadVisitsOverview(); }, []); return ( <>
{loading ? 'Loading...' : prettify(shortUrls?.pagination.totalItems ?? 0)}
{loadingTags ? 'Loading...' : prettify(tagsList.tags.length)}
Create a short URL
Create a short URL
Advanced options »
Recently created URLs
Recently created URLs
See all »
navigate(`/server/${serverId}/list-short-urls/1?tags=${encodeURIComponent(tag)}`)} />
); }, () => [Topics.visits, Topics.orphanVisits]);