Virtualize source list
This commit is contained in:
@@ -58,7 +58,7 @@ export function Browse() {
|
|||||||
<Tab value={Tabs.MIGRATE} sx={{ textTransform: 'none' }} label={t('migrate.title')} />
|
<Tab value={Tabs.MIGRATE} sx={{ textTransform: 'none' }} label={t('migrate.title')} />
|
||||||
</TabsMenu>
|
</TabsMenu>
|
||||||
<TabPanel index={Tabs.SOURCE} currentIndex={tabName}>
|
<TabPanel index={Tabs.SOURCE} currentIndex={tabName}>
|
||||||
<Sources />
|
<Sources tabsMenuHeight={tabsMenuHeight} />
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
<TabPanel index={Tabs.EXTENSIONS} currentIndex={tabName}>
|
<TabPanel index={Tabs.EXTENSIONS} currentIndex={tabName}>
|
||||||
<Extensions tabsMenuHeight={tabsMenuHeight} />
|
<Extensions tabsMenuHeight={tabsMenuHeight} />
|
||||||
|
|||||||
@@ -59,12 +59,7 @@ export const SourceCard: React.FC<IProps> = (props: IProps) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card
|
<Card>
|
||||||
sx={{
|
|
||||||
margin: 1,
|
|
||||||
marginTop: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<CardActionArea
|
<CardActionArea
|
||||||
component={Link}
|
component={Link}
|
||||||
to={AppRoutes.sources.childRoutes.browse.path(id)}
|
to={AppRoutes.sources.childRoutes.browse.path(id)}
|
||||||
|
|||||||
@@ -6,12 +6,12 @@
|
|||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Fragment, useMemo } from 'react';
|
import { useCallback, useMemo } from 'react';
|
||||||
import IconButton from '@mui/material/IconButton';
|
import IconButton from '@mui/material/IconButton';
|
||||||
import Typography from '@mui/material/Typography';
|
|
||||||
import TravelExploreIcon from '@mui/icons-material/TravelExplore';
|
import TravelExploreIcon from '@mui/icons-material/TravelExplore';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import Typography from '@mui/material/Typography';
|
||||||
import { CustomTooltip } from '@/modules/core/components/CustomTooltip.tsx';
|
import { CustomTooltip } from '@/modules/core/components/CustomTooltip.tsx';
|
||||||
import { requestManager } from '@/lib/requests/RequestManager.ts';
|
import { requestManager } from '@/lib/requests/RequestManager.ts';
|
||||||
import { useLocalStorage } from '@/modules/core/hooks/useStorage.tsx';
|
import { useLocalStorage } from '@/modules/core/hooks/useStorage.tsx';
|
||||||
@@ -27,8 +27,12 @@ import { getErrorMessage } from '@/lib/HelperFunctions.ts';
|
|||||||
import { Sources as SourceService } from '@/modules/source/services/Sources.ts';
|
import { Sources as SourceService } from '@/modules/source/services/Sources.ts';
|
||||||
import { useMetadataServerSettings } from '@/modules/settings/services/ServerSettingsMetadata.ts';
|
import { useMetadataServerSettings } from '@/modules/settings/services/ServerSettingsMetadata.ts';
|
||||||
import { useAppAction } from '@/modules/navigation-bar/hooks/useAppAction.ts';
|
import { useAppAction } from '@/modules/navigation-bar/hooks/useAppAction.ts';
|
||||||
|
import { StyledGroupedVirtuoso } from '@/modules/core/components/virtuoso/StyledGroupedVirtuoso.tsx';
|
||||||
|
import { VirtuosoUtil } from '@/lib/virtuoso/Virtuoso.util.tsx';
|
||||||
|
import { StyledGroupHeader } from '@/modules/core/components/virtuoso/StyledGroupHeader.tsx';
|
||||||
|
import { StyledGroupItemWrapper } from '@/modules/core/components/virtuoso/StyledGroupItemWrapper.tsx';
|
||||||
|
|
||||||
export function Sources() {
|
export function Sources({ tabsMenuHeight }: { tabsMenuHeight: number }) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const [shownLangs, setShownLangs] = useLocalStorage<string[]>('shownSourceLangs', getDefaultLanguages());
|
const [shownLangs, setShownLangs] = useLocalStorage<string[]>('shownSourceLangs', getDefaultLanguages());
|
||||||
@@ -66,6 +70,23 @@ export function Sources() {
|
|||||||
() => SourceService.areFromMultipleRepos(filteredSources),
|
() => SourceService.areFromMultipleRepos(filteredSources),
|
||||||
[filteredSources],
|
[filteredSources],
|
||||||
);
|
);
|
||||||
|
const visibleSources = useMemo(
|
||||||
|
() => sourcesByLanguage.map(([, sourcesOfLanguage]) => sourcesOfLanguage).flat(1),
|
||||||
|
[sourcesByLanguage],
|
||||||
|
);
|
||||||
|
|
||||||
|
const groupCounts = useMemo(
|
||||||
|
() => sourcesByLanguage.map((sourceGroup) => sourceGroup[1].length),
|
||||||
|
[sourcesByLanguage],
|
||||||
|
);
|
||||||
|
const computeItemKey = VirtuosoUtil.useCreateGroupedComputeItemKey(
|
||||||
|
groupCounts,
|
||||||
|
useCallback((index) => sourcesByLanguage[index][0], [sourcesByLanguage]),
|
||||||
|
useCallback(
|
||||||
|
(index, groupIndex) => `${sourcesByLanguage[groupIndex][0]}_${visibleSources[index].id}`,
|
||||||
|
[visibleSources],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
@@ -102,27 +123,32 @@ export function Sources() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<StyledGroupedVirtuoso
|
||||||
{sourcesByLanguage.map(([language, sourcesOfLanguage]) => (
|
persistKey="sources"
|
||||||
<Fragment key={language}>
|
heightToSubtract={tabsMenuHeight}
|
||||||
<Typography
|
overscan={window.innerHeight * 0.5}
|
||||||
key={language}
|
groupCounts={groupCounts}
|
||||||
variant="h5"
|
computeItemKey={computeItemKey}
|
||||||
component="h2"
|
groupContent={(index) => {
|
||||||
sx={{
|
const [language] = sourcesByLanguage[index];
|
||||||
paddingLeft: 3,
|
|
||||||
paddingTop: 1,
|
return (
|
||||||
paddingBottom: 2,
|
<StyledGroupHeader isFirstItem={!index}>
|
||||||
fontWeight: 'bold',
|
<Typography variant="h5" component="h2">
|
||||||
}}
|
{translateExtensionLanguage(language)}
|
||||||
>
|
</Typography>
|
||||||
{translateExtensionLanguage(language)}
|
</StyledGroupHeader>
|
||||||
</Typography>
|
);
|
||||||
{sourcesOfLanguage.map((source) => (
|
}}
|
||||||
<SourceCard key={source.id} source={source} showSourceRepo={areSourcesFromDifferentRepos} />
|
itemContent={(index) => {
|
||||||
))}
|
const source = visibleSources[index];
|
||||||
</Fragment>
|
|
||||||
))}
|
return (
|
||||||
</>
|
<StyledGroupItemWrapper>
|
||||||
|
<SourceCard source={source} showSourceRepo={areSourcesFromDifferentRepos} />
|
||||||
|
</StyledGroupItemWrapper>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user