📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
Refactor: Remove duplicated code
Blue Mouse3e442eb934e6
diff --git a/web/app/pages/Project/tabs/Profiles/Profiles.tsx b/web/app/pages/Project/tabs/Profiles/Profiles.tsxindex 96db0f453..06e7f6b73 100644--- a/web/app/pages/Project/tabs/Profiles/Profiles.tsx+++ b/web/app/pages/Project/tabs/Profiles/Profiles.tsx@@ -8,18 +8,13 @@ import {CursorClickIcon,UserListIcon,CaretRightIcon,- GlobeIcon,} from '@phosphor-icons/react'import React, { useMemo } from 'react'import { useTranslation } from 'react-i18next'import { Link, useLocation } from 'react-router'import { ClientOnly } from 'remix-utils/client-only'-import {- BROWSER_LOGO_MAP,- OS_LOGO_MAP,- OS_LOGO_MAP_DARK,-} from '~/lib/constants'+import { BrowserIcon, OSIcon } from '../SharedIcons'import { Profile as ProfileType } from '~/lib/models/Project'import { useTheme } from '~/providers/ThemeProvider'import { Badge } from '~/ui/Badge'@@ -63,61 +58,6 @@ interface ProfileRowProps {timeFormat: '12-hour' | '24-hour'}-const BrowserIcon = ({- browser,- className,-}: {- browser: string | null- className?: string-}) => {- if (!browser)- return (- <GlobeIcon- className={className || 'size-3.5 text-gray-400 dark:text-gray-500'}- weight='duotone'- />- )- const logoUrl = BROWSER_LOGO_MAP[browser as keyof typeof BROWSER_LOGO_MAP]- if (!logoUrl)- return (- <GlobeIcon- className={className || 'size-3.5 text-gray-400 dark:text-gray-500'}- weight='duotone'- />- )- return <img src={logoUrl} className={className || 'size-3.5'} alt={browser} />-}--const OSIcon = ({- os,- theme,- className,-}: {- os: string | null- theme: string- className?: string-}) => {- if (!os)- return (- <GlobeIcon- className={className || 'size-3.5 text-gray-400 dark:text-gray-500'}- weight='duotone'- />- )- const logoUrlLight = OS_LOGO_MAP[os as keyof typeof OS_LOGO_MAP]- const logoUrlDark = OS_LOGO_MAP_DARK[os as keyof typeof OS_LOGO_MAP_DARK]- let logoUrl = theme === 'dark' ? logoUrlDark : logoUrlLight- logoUrl ||= logoUrlLight- if (!logoUrl)- return (- <GlobeIcon- className={className || 'size-3.5 text-gray-400 dark:text-gray-500'}- weight='duotone'- />- )- return <img src={logoUrl} className={className || 'size-3.5'} alt={os} />-}-const ProfileRow = ({ profile, timeFormat }: ProfileRowProps) => {const {t,diff --git a/web/app/pages/Project/tabs/Sessions/Sessions.tsx b/web/app/pages/Project/tabs/Sessions/Sessions.tsxindex 24fbb687b..03d3b1476 100644--- a/web/app/pages/Project/tabs/Sessions/Sessions.tsx+++ b/web/app/pages/Project/tabs/Sessions/Sessions.tsx@@ -8,18 +8,13 @@ import {WarningIcon,CursorClickIcon,CaretRightIcon,- GlobeIcon,} from '@phosphor-icons/react'import React, { useMemo } from 'react'import { useTranslation } from 'react-i18next'import { Link, useLocation } from 'react-router'import { ClientOnly } from 'remix-utils/client-only'-import {- BROWSER_LOGO_MAP,- OS_LOGO_MAP,- OS_LOGO_MAP_DARK,-} from '~/lib/constants'+import { BrowserIcon, OSIcon } from '../SharedIcons'import { Session as SessionType } from '~/lib/models/Project'import { useTheme } from '~/providers/ThemeProvider'import { Badge } from '~/ui/Badge'@@ -83,61 +78,6 @@ interface SessionProps {currency?: string}-const BrowserIcon = ({- browser,- className,-}: {- browser: string | null- className?: string-}) => {- if (!browser)- return (- <GlobeIcon- className={className || 'size-3.5 text-gray-400'}- weight='duotone'- />- )- const logoUrl = BROWSER_LOGO_MAP[browser as keyof typeof BROWSER_LOGO_MAP]- if (!logoUrl)- return (- <GlobeIcon- className={className || 'size-3.5 text-gray-400'}- weight='duotone'- />- )- return <img src={logoUrl} className={className || 'size-3.5'} alt={browser} />-}--const OSIcon = ({- os,- theme,- className,-}: {- os: string | null- theme: string- className?: string-}) => {- if (!os)- return (- <GlobeIcon- className={className || 'size-3.5 text-gray-400'}- weight='duotone'- />- )- const logoUrlLight = OS_LOGO_MAP[os as keyof typeof OS_LOGO_MAP]- const logoUrlDark = OS_LOGO_MAP_DARK[os as keyof typeof OS_LOGO_MAP_DARK]- let logoUrl = theme === 'dark' ? logoUrlDark : logoUrlLight- logoUrl ||= logoUrlLight- if (!logoUrl)- return (- <GlobeIcon- className={className || 'size-3.5 text-gray-400'}- weight='duotone'- />- )- return <img src={logoUrl} className={className || 'size-3.5'} alt={os} />-}-export const Session = ({session,timeFormat,@@ -214,7 +154,7 @@ export const Session = ({</span>)}, [- session,+ session.isLive,language,timeFormat,sessionDurationString,diff --git a/web/app/pages/Project/tabs/SharedIcons.tsx b/web/app/pages/Project/tabs/SharedIcons.tsxnew file mode 100644index 000000000..ee77102f4--- /dev/null+++ b/web/app/pages/Project/tabs/SharedIcons.tsx@@ -0,0 +1,64 @@+import { GlobeIcon } from '@phosphor-icons/react'++import {+ BROWSER_LOGO_MAP,+ OS_LOGO_MAP,+ OS_LOGO_MAP_DARK,+} from '~/lib/constants'++const FALLBACK_ICON_CLASS = 'size-3.5 text-gray-400 dark:text-gray-500'++export const BrowserIcon = ({+ browser,+ className,+}: {+ browser: string | null+ className?: string+}) => {+ if (!browser)+ return (+ <GlobeIcon+ className={className || FALLBACK_ICON_CLASS}+ weight='duotone'+ />+ )+ const logoUrl = BROWSER_LOGO_MAP[browser as keyof typeof BROWSER_LOGO_MAP]+ if (!logoUrl)+ return (+ <GlobeIcon+ className={className || FALLBACK_ICON_CLASS}+ weight='duotone'+ />+ )+ return <img src={logoUrl} className={className || 'size-3.5'} alt={browser} />+}++export const OSIcon = ({+ os,+ theme,+ className,+}: {+ os: string | null+ theme: string+ className?: string+}) => {+ if (!os)+ return (+ <GlobeIcon+ className={className || FALLBACK_ICON_CLASS}+ weight='duotone'+ />+ )+ const logoUrlLight = OS_LOGO_MAP[os as keyof typeof OS_LOGO_MAP]+ const logoUrlDark = OS_LOGO_MAP_DARK[os as keyof typeof OS_LOGO_MAP_DARK]+ let logoUrl = theme === 'dark' ? logoUrlDark : logoUrlLight+ logoUrl ||= logoUrlLight+ if (!logoUrl)+ return (+ <GlobeIcon+ className={className || FALLBACK_ICON_CLASS}+ weight='duotone'+ />+ )+ return <img src={logoUrl} className={className || 'size-3.5'} alt={os} />+}