import React from 'react'; import { AppCircle, AppCircleContainer, AppDownloadButton, AppDownloadButtonText, AppInfoAppName, AppInfoSnippetContainer, AppInfoSnippetLeft, AppInfoSnippetMiddle, AppInfoSnippetRight, AppInfoUserName, } from './Apps-styles'; import { Avatar, ButtonBase, useTheme } from '@mui/material'; import { getBaseApiReact } from '../../App'; import LogoSelected from '../../assets/svgs/LogoSelected.svg'; import { Spacer } from '../../common/Spacer'; import { executeEvent } from '../../utils/events'; import { AppRating } from './AppRating'; import { settingsLocalLastUpdatedAtom, sortablePinnedAppsAtom, } from '../../atoms/global'; import { saveToLocalStorage } from './AppsNavBarDesktop'; import { useAtom, useSetAtom } from 'jotai'; import { useTranslation } from 'react-i18next'; export const AppInfoSnippet = ({ app, myName, isFromCategory, parentStyles = {}, }) => { const isInstalled = app?.status?.status === 'READY'; const [sortablePinnedApps, setSortablePinnedApps] = useAtom( sortablePinnedAppsAtom ); const setSettingsLocalLastUpdated = useSetAtom(settingsLocalLastUpdatedAtom); const isSelectedAppPinned = !!sortablePinnedApps?.find( (item) => item?.name === app?.name && item?.service === app?.service ); const theme = useTheme(); const { t } = useTranslation(['auth', 'core', 'group']); return ( { if (isFromCategory) { executeEvent('selectedAppInfoCategory', { data: app, }); return; } executeEvent('selectedAppInfo', { data: app, }); }} > center-icon { if (isFromCategory) { executeEvent('selectedAppInfoCategory', { data: app, }); return; } executeEvent('selectedAppInfo', { data: app, }); }} > {app?.metadata?.title || app?.name} {app?.name} { setSortablePinnedApps((prev) => { let updatedApps; if (isSelectedAppPinned) { // Remove the selected app if it is pinned updatedApps = prev.filter( (item) => !( item?.name === app?.name && item?.service === app?.service ) ); } else { // Add the selected app if it is not pinned updatedApps = [ ...prev, { name: app?.name, service: app?.service, }, ]; } saveToLocalStorage( 'ext_saved_settings', 'sortablePinnedApps', updatedApps ); return updatedApps; }); setSettingsLocalLastUpdated(Date.now()); }} sx={{ backgroundColor: theme.palette.background.paper, opacity: isSelectedAppPinned ? 0.6 : 1, }} > {isSelectedAppPinned ? t('core:action.unpin', { postProcess: 'capitalizeFirstChar', }) : t('core:action.pin', { postProcess: 'capitalizeFirstChar', })} { executeEvent('addTab', { data: app, }); }} sx={{ backgroundColor: isInstalled ? theme.palette.primary.main : theme.palette.background.paper, }} > {isInstalled ? t('core:action.open', { postProcess: 'capitalizeFirstChar', }) : t('core:action.download', { postProcess: 'capitalizeFirstChar', })} ); };