import { useEffect, useMemo, useRef, useState } from 'react';
import {
AppCircle,
AppCircleContainer,
AppCircleLabel,
AppLibrarySubTitle,
AppsContainer,
AppsDesktopLibraryBody,
AppsDesktopLibraryHeader,
AppsLibraryContainer,
AppsSearchContainer,
AppsSearchLeft,
AppsSearchRight,
AppsWidthLimiter,
PublishQAppCTAButton,
PublishQAppCTALeft,
PublishQAppCTAParent,
PublishQAppCTARight,
PublishQAppDotsBG,
} from './Apps-styles';
import {
Avatar,
Box,
ButtonBase,
InputBase,
Typography,
styled,
useTheme,
} from '@mui/material';
import { getBaseApiReact } from '../../App';
import LogoSelected from '../../assets/svgs/LogoSelected.svg';
import SearchIcon from '@mui/icons-material/Search';
import IconClearInput from '../../assets/svgs/ClearInput.svg';
import { QappDevelopText } from '../../assets/Icons/QappDevelopText.tsx';
import { QappLibraryText } from '../../assets/Icons/QappLibraryText.tsx';
import RefreshIcon from '@mui/icons-material/Refresh';
import AppsIcon from '@mui/icons-material/Apps';
import { Spacer } from '../../common/Spacer';
import { AppInfoSnippet } from './AppInfoSnippet';
import { Virtuoso } from 'react-virtuoso';
import { executeEvent } from '../../utils/events';
import { ComposeP, ShowMessageReturnButton } from '../Group/Forum/Mail-styles';
import { ReturnIcon } from '../../assets/Icons/ReturnIcon.tsx';
import { useTranslation } from 'react-i18next';
const officialAppList = [
'q-tube',
'q-blog',
'q-share',
'q-support',
'q-mail',
'q-fund',
'q-shop',
'q-trade',
'q-support',
'q-manager',
'q-mintership',
'q-wallets',
'q-search',
'q-nodecontrol',
];
const ScrollerStyled = styled('div')({
// Hide scrollbar for WebKit browsers (Chrome, Safari)
'::-webkit-scrollbar': {
width: '0px',
height: '0px',
},
// Hide scrollbar for Firefox
scrollbarWidth: 'none',
// Hide scrollbar for IE and older Edge
msOverflowStyle: 'none',
});
const StyledVirtuosoContainer = styled('div')({
position: 'relative',
width: '100%',
display: 'flex',
flexDirection: 'column',
// Hide scrollbar for WebKit browsers (Chrome, Safari)
'::-webkit-scrollbar': {
width: '0px',
height: '0px',
},
// Hide scrollbar for Firefox
scrollbarWidth: 'none',
// Hide scrollbar for IE and older Edge
msOverflowStyle: 'none',
});
export const AppsLibraryDesktop = ({
availableQapps,
setMode,
myName,
hasPublishApp,
isShow,
categories,
getQapps,
}) => {
const [searchValue, setSearchValue] = useState('');
const virtuosoRef = useRef(null);
const theme = useTheme();
const { t } = useTranslation(['auth', 'core', 'group']);
const officialApps = useMemo(() => {
return availableQapps.filter(
(app) =>
app.service === 'APP' &&
officialAppList.includes(app?.name?.toLowerCase())
);
}, [availableQapps]);
const [debouncedValue, setDebouncedValue] = useState(''); // Debounced value
// Debounce logic
useEffect(() => {
const handler = setTimeout(() => {
setDebouncedValue(searchValue);
}, 350);
setTimeout(() => {
if (virtuosoRef.current) {
virtuosoRef.current.scrollToIndex({ index: 0 });
}
}, 500);
// Cleanup timeout if searchValue changes before the timeout completes
return () => {
clearTimeout(handler);
};
}, [searchValue]); // Runs effect when searchValue changes
// Example: Perform search or other actions based on debouncedValue
const searchedList = useMemo(() => {
if (!debouncedValue) return [];
return availableQapps.filter(
(app) =>
app.name.toLowerCase().includes(debouncedValue.toLowerCase()) ||
(app?.metadata?.title &&
app?.metadata?.title
?.toLowerCase()
.includes(debouncedValue.toLowerCase()))
);
}, [debouncedValue]);
const rowRenderer = (index) => {
let app = searchedList[index];
return (
);
};
return (
setSearchValue(e.target.value)}
sx={{
background: theme.palette.background.paper,
borderRadius: '6px',
flex: 1,
ml: 1,
paddingLeft: '12px',
}}
placeholder={t('core:action.search_apps', {
postProcess: 'capitalizeFirst',
})}
inputProps={{
'aria-label': t('core:action.search_apps', {
postProcess: 'capitalizeFirst',
}),
fontSize: '16px',
fontWeight: 400,
}}
/>
{searchValue && (
{
setSearchValue('');
}}
>
)}
{
getQapps();
}}
>
{
executeEvent('navigateBack', {});
}}
>
{t('core:action.return_apps_dashboard', {
postProcess: 'capitalizeFirst',
})}
{searchedList?.length > 0 ? (
) : searchedList?.length === 0 && debouncedValue ? (
{t('core:message.generic.no_results', {
postProcess: 'capitalizeFirst',
})}
) : (
<>
{t('core:apps_official', { postProcess: 'capitalizeFirst' })}
{officialApps?.map((qapp) => {
return (
{
executeEvent('selectedAppInfo', {
data: qapp,
});
}}
>
{qapp?.metadata?.title || qapp?.name}
);
})}
{hasPublishApp
? t('core:action.update_app', {
postProcess: 'capitalizeFirst',
})
: t('core:action.publish_app', {
postProcess: 'capitalizeFirst',
})}
{
setMode('publish');
}}
>
{hasPublishApp
? t('core:action.update', {
postProcess: 'capitalizeFirst',
})
: t('core:action.publish', {
postProcess: 'capitalizeFirst',
})}
{t('core:category_other', {
postProcess: 'capitalizeFirst',
})}
{
executeEvent('selectedCategory', {
data: {
id: 'all',
name: 'All',
},
});
}}
>
{t('core:all', { postProcess: 'capitalizeFirst' })}
{categories?.map((category) => {
return (
{
executeEvent('selectedCategory', {
data: category,
});
}}
>
{category?.name}
);
})}
>
)}
);
};