import { toPlural } from '@vizality/util/string';
import { useRouteMatch } from 'react-router';
import React, { memo } from 'react';

import AddonsList from './AddonsList';

export default memo(() => {
  const { path } = useRouteMatch();
  const type = (/(\/plugins\/)/).test(path) ? 'plugin' : (/(\/themes\/)/).test(path) ? 'theme' : 'plugin';
  const source = [ ...vizality.manager.community[toPlural(type)].values() ];

  return (
    <AddonsList
      source={source}
      section='browse'
      type={type}
      community={true}
    />
  );
});
